Code2Flow MCP 服务器
这是一个将 code2flow 命令行工具包装为 MCP (Model Context Protocol) 服务器的项目。它允许 AI 应用程序通过标准化的 MCP 协议生成和访问代码调用图。
功能特点
- 分析源代码并生成调用图
- 支持多种编程语言(Python、JavaScript、Ruby、PHP)
- 通过 MCP 协议提供服务,易于与 AI 应用集成
- 图像以 PNG 格式输出
- 提供版本检查和代码复杂度分析功能
安装要求
- Python 3.7+
- Windows 11 或其他支持的操作系统
- PowerShell 或其他命令行终端
- 已安装 code2flow 命令行工具
安装步骤
- 克隆此仓库
git clone https://github.com/kursk-ye/code2flow-mcp-server.git
cd code2flow-mcp-server
- 创建并激活虚拟环境(推荐)
python -m venv venv
.venvScriptsActivate.ps1 # 在 PowerShell 中
- 安装依赖项
pip install -r requirements.txt
- 安装 code2flow 命令行工具
pip install code2flow
使用方法
直接使用 Python 运行
- 启动 MCP 服务器
python server.py
使用 MCP 工具运行
- 使用 MCP Inspector 工具
mcp dev server.py
- 安装到 Claude Desktop
mcp install server.py
- 添加到 Cursor MCP 配置
"code2flow": {
"command": "cmd",
"args": [
"/c",
"python",
"path/to/server.py"
]
}
可用工具
服务器提供以下 MCP 工具:
generate_call_graph
- 生成代码调用图check_code2flow_version
- 检查 code2flow 版本analyze_code_complexity
- 分析代码复杂度
可用资源
服务器提供以下 MCP 资源:
help://code2flow
- 帮助文档languages://supported
- 支持的语言列表call-graph://图像ID
- 生成的调用图图像
示例(使用 Python MCP 客户端)
import asyncio
from mcp.client import MCPClient
async def main():
# 连接到服务器
client = MCPClient("http://localhost:8000")
# 创建新会话
session = await client.create_session()
# 调用工具生成调用图
result = await session.call_tool("generate_call_graph", {
"source_paths": ["path/to/your/code"],
"language": "python"
})
# 获取资源 ID
print(result)
# 检查code2flow版本
version_info = await session.call_tool("check_code2flow_version")
print(version_info)
# 分析代码复杂度
complexity = await session.call_tool("analyze_code_complexity", {
"source_path": "path/to/your/code",
"language": "python"
})
print(complexity)
if __name__ == "__main__":
asyncio.run(main())
配置选项
生成调用图时支持以下参数:
source_paths
:要分析的源代码文件或目录的路径列表output_path
:(可选)输出文件的路径language
:(可选)源代码语言(python、js、ruby、php)exclude
:(可选)要排除的文件模式列表include
:(可选)要包含的文件模式列表
文件结构
server.py
- 主服务器代码mcp_client_example.py
- 客户端示例代码test_server.py
- 测试代码requirements.txt
- 依赖文件
许可证
MIT
Code2Flow MCP Server
Project Details
- kursk-ye/code2flow-mcp-server
- Last Updated: 4/16/2025
Recomended MCP Servers
Minimal typescript template to build an mcp server
Deep Research MCP is an intelligent research assistant built on the Model Context Protocol (MCP) that performs comprehensive,...
flux-image-generator-mcp
Gladia MCP
Seamlessly integrate AI agents with Chargebee using AgentKit for smarter billing and subscription workflows.
A Model Context Protocol (MCP) for Jupyter Notebook
大家好!我是功能丰富的 MCP 服务,旨在打破设备与服务的隔阂,为用户带来便捷体验。 天气工具和气象平台联动,快速为用户推送全球实时天气,助力大家规划出行。控制浏览器工具模拟人工操作,自动搜索、浏览网页,大幅节省时间。摄像头工具调用本地摄像头拍照、录像,实现人脸识别,保障家庭安防。 为实现工具协同,我搭建了稳定框架,开发者可以基于现有服务进行拓展
Investidor10 MCP Server: A Model Context Protocol (MCP) server for interacting with the Status Invest API. Provides tools...
This MCP server provides tools for interacting with Aliyun (Alibaba Cloud) services.
An MCP Server for Bitcoin SV