The Model Context Protocol (MCP) aims to create a standard for how Large Language Models use tools. However, most current research focuses on selecting tools from an existing pool. A more fundamental, yet largely overlooked, problem is how to populate this pool by converting the vast number of existing software projects into MCP-compatible services. To bridge this gap, we introduce Code2MCP, an agent-based framework that automatically transforms a GitHub repository into a functional MCP service with minimal human intervention. Code2MCP employs a multi-agent workflow for code analysis, environment setup, tool function design, and service generation, enhanced by a self-correcting loop to ensure reliability. We demonstrate that Code2MCP successfully transforms open-source computing libraries in scientific fields such as bioinformatics, mathematics, and fluid dynamics that are not available in existing MCP servers. By providing a novel automated pathway to unlock GitHub, the world's largest code repository, for the MCP ecosystem, Code2MCP serves as a catalyst to significantly accelerate the protocol's adoption and practical application. The code is public at https://github.com/DEFENSE-SEU/Code2MCP.
翻译:模型上下文协议(Model Context Protocol, MCP)旨在为大型语言模型如何使用工具建立标准。然而,当前大多数研究集中于从现有工具池中选择工具。一个更为基础但很大程度上被忽视的问题是:如何通过将海量现有软件项目转化为MCP兼容的服务来填充这个工具池。为弥合这一差距,我们提出了Code2MCP,这是一个基于智能体的框架,能够以最少的人工干预,自动将GitHub仓库转化为功能完整的MCP服务。Code2MCP采用多智能体工作流进行代码分析、环境配置、工具函数设计和服务生成,并通过自校正循环增强以确保可靠性。我们证明,Code2MCP能够成功转化生物信息学、数学和流体动力学等科学领域中尚未在现有MCP服务器中提供的开源计算库。通过提供一条新颖的自动化路径,将全球最大的代码仓库GitHub解锁给MCP生态系统,Code2MCP作为一个催化剂,能够显著加速该协议的采纳与实际应用。代码已公开于 https://github.com/DEFENSE-SEU/Code2MCP。