Code2MCP: Transforming Code Repositories into MCP Services

Chaoqian Ouyang, Ling Yue, Shimin Di, Libin Zheng, Linan Yue, Shaowu Pan, Jian Yin, Min-Ling Zhang · DOI

Introduction

Large Language Models (LLMs) have demonstrated remarkable reasoning capabilities, yet they remain constrained by their training data cutoffs and a lack of access to real-time, specialized computational tools. While "tool-augmented reasoning" offers a path forward, it has historically suffered from an $N \times M$ integration problem: every new model ($N$) requires a custom connector for every new tool ($M$).

The Model Context Protocol (MCP) emerged as a universal standard to mitigate this, enabling a "plug-and-play" ecosystem for AI agents. However, a significant "supply-side" bottleneck persists. While millions of high-quality code repositories exist on GitHub, the vast majority are not MCP-compliant. Manually wrapping these libraries into standardized services is a labor-intensive and technically demanding process. Code2MCP addresses this by providing an automated multi-agent framework that transforms raw GitHub repositories into standardized, agent-ready MCP services.

The Code2MCP Framework

Code2MCP utilizes a collaborative multi-agent architecture to manage the end-to-end conversion of code repositories into functional tools. The process is orchestrated by seven specialized agents:

  1. Download & Environment Agents: These agents clone the target repository and attempt to replicate its runtime environment using Docker or Conda, ensuring the underlying code is executable.
  2. Analysis Agent: Leveraging a tool called DeepWiki, this agent performs semantic analysis of the codebase to identify "tool-worthy" functions based on documentation, comments, and structure.
  3. Generation Agent: This agent synthesizes the necessary MCP service code, adapters, and a comprehensive test suite.
  4. The "Run-Review-Fix" Loop: This iterative process is the framework's core innovation. A Run Agent executes the generated tests; if failures occur, a Review Agent analyzes error tracebacks to formulate a targeted modification plan. The Generation Agent then applies localized repairs, ensuring stability by avoiding unnecessary global rewrites.
  5. Finalize Agent: Once validated, the agent packages the service, generates documentation (README), and prepares a Pull Request for the original repository.
The Code2MCP multi-agent framework architecture, illustrating the collaborative workflow from repository download to final service packaging.

Evaluation and Datasets

The framework was rigorously evaluated using a curated dataset of 50 open-source repositories across 10 diverse scientific and engineering domains, including Biomedical Science (e.g., ESM), Symbolic Mathematics (e.g., SymPy), Fluid Dynamics, Astronomy, and Econometrics. This selection was designed to test the system against varied dependency structures, API styles, and execution environments.

Key Results and Failure Analysis

Code2MCP successfully converted 64% (32 out of 50) of the tested repositories into functional MCP services. In head-to-head comparisons, the system achieved task success rates comparable to human experts (graduate students) while significantly outperforming baseline GPT-4 template-based approaches. Furthermore, Code2MCP reduced the implementation time from hours (for humans) to tens of minutes.

Analysis of failure labels and the impact of the Run-Review-Fix (RRF) loop on repository success rates across different domains.

The evaluation highlighted that the primary hurdles are environmental and structural. "Environment failure"—the inability to reconstruct complex software dependencies—and "API inference errors" accounted for over half of all failures. However, the Run-Review-Fix (RRF) loop proved essential; as shown in the results, it significantly boosted success rates across all domains, with an average improvement of over 30% compared to a single-pass generation.

Discussion and Future Directions

Code2MCP shifts the focus from how agents consume tools to how those tools are created. By automating the supply chain of AI tools, it positions the MCP protocol as a catalyst for a more capable agent ecosystem.

Despite its success, limitations remain. Security is a paramount concern when executing third-party code, necessitating isolated worker environments. Additionally, some repositories remain "untoolable" due to heavy reliance on interactive GUIs or lack of stable library APIs. Future work will focus on improving the Analysis Agent's handling of obscure code patterns and expanding support for non-Python repositories.

Summary updated

BibTeX
@inproceedings{ouyang2025code,
  author = {Chaoqian Ouyang and Ling Yue and Shimin Di and Libin Zheng and Linan Yue and Shaowu Pan and Jian Yin and Min-Ling Zhang},
  title = {{Code2MCP: Transforming Code Repositories into MCP Services}},
  booktitle = {SEA @ NeurIPS},
  year = {2025},
  url = {https://openreview.net/forum?id=ghVs0H7DLA},
}
Figure