本项目是一个结合了 LangGraph 和 Model Context Protocol(MCP)的协作编码机器人。该系统由三部分构成,分别是一个 gateway server、多个 MCP servers 以及三个协作的 Coding Agents,能有效提升编码协作效率。
# 安装代理包
pip install -e .
# 安装网关包
cd gateway
pip install -e .
cd ..
支持通过环境变量使用多个 LLM 提供商:
# LLM 配置 - 支持多个提供方:
LLM_MODEL=provider/model-name
# 支持的提供方和示例模型:
# - Anthropic: anthropic/claude-3-5-sonnet-20240620
# - OpenAI: openai/gpt-4
# - OpenRouter: openrouter/openai/gpt-4o-mini
# - Google: google/gemini-1.5-pro
# 不同提供方的 API Key
OPENAI_API_KEY=your_openai_api_key
ANTHROPIC_API_KEY=your_anthropic_api_key
OPENROUTER_API_KEY=your_openrouter_api_key
GOOGLE_API_KEY=your_google_api_key
# OpenRouter 配置(如果使用 OpenRouter)
OPENROUTER_BASE_URL=https://openrouter.ai/api/v1
网关服务器通过 gateway/config.json 进行配置。默认启动两个 MCP 服务器:
{
"mcp": {
"servers": {
"filesystem": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-filesystem",
"/path/to/directory"
]
},
"memory": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-memory"
]
}
}
}
}
可以在 官方 MCP 服务器仓库 中添加更多服务器。
cd gateway
python -m mcp_gateway.server
服务器将在默认端口 8808 上启动。
代理与网关的连接在 langgraph.json 中配置:
{
"dependencies": ["."],
"graphs": {
"agent": "./src/react_agent/graph.py:graph"
},
"env": ".env",
"mcp": {
"gateway_url": "http://localhost:8808"
}
}
在 LangGraph Studio 中打开文件夹!代理将自动:
在 LangGraph Studio 中打开项目文件夹,代理会自动连接网关、发现工具并开始协作编码。
见快速开始部分的安装依赖项、配置环境变量、配置 MCP 服务器、启动网关服务器、配置代理等步骤。
更多详细信息请参考:
本系统结合了 LangGraph 和 MCP,通过 MCP Gateway Server 管理多个 MCP servers,实现工具的统一访问和通信。Coding Agents 中的 Orchestrator、Planner 和 Coder 协作完成编码任务。通过环境变量配置支持多个 LLM 提供商,可灵活选择不同的大语言模型。同时,可通过配置文件添加新的 MCP 服务器和自定义代理行为,方便系统扩展和定制。
项目使用 MIT 许可证,详情见 LICENSE 文件。
在 config.json 中添加新的 MCP 服务器配置,然后重新启动网关。
可以通过修改 graph.py 和相关组件来自定义代理的行为。