使用说明
MCP网关(主MCP服务器)
多个子代MCP集中管理服务器并负责架构检索和工具执行的网关。
概要
children_config.(json|toml)启动在中定义的子服务器,并使用驻留会话+lock中描述的场景,使用以下步骤创建明细表,以便在概念设计中分析体量的体积。- 获取子服务器的架构(
get_schema)或任意工具调用(execute_child_tool),模板名称将采用不同的格式。 children_abstract.json将条目添加到文档注册表。
子服务器示例(附带的模板)
children_config.example.json/children_config.example.toml 那么注册了以下内容。children_abstract.example.json 请结合参考。
serena:基于代码的符号搜索/编辑、注释管理和有限的外壳执行(例如,tools:read_file,find_file,find_symbol,replace_content,execute_shell_command)context7:库名称-Context7兼容ID解析和文档检索(resolve-library-id,get-library-docs)codegraph:代码图表搜索、从属/调用搜索、文件读取、GraphRAG搜索、重新索引(query_codebase,read_file_content,reindex_repository等)
安装,安装
- 依赖性安装
uv sync - 创建配置文件(复制模板)
# JSONで使う場合 cp children_config.example.json children_config.json # codex CLIなどTOML形式を使う場合 cp children_config.example.toml children_config.toml cp children_abstract.example.json children_abstract.jsonchildren_config.json或children_config.toml中描述的场景,使用下列步骤创建明细表,以便在概念设计中分析体量的周长。
起动方法
本地运行(存储库clone已完成
uv run mcp-gateway \
--children-config /absolute/path/to/children_config.json \
--children-abstract /absolute/path/to/children_abstract.json
uvx経由(GitHub公开后)
uvx --from git+https://github.com/OWNER/MCPgateway \
mcp-gateway \
--children-config /absolute/path/to/children_config.json \
--children-abstract /absolute/path/to/children_abstract.json
※ OWNER/请将存储库名称替换为实际名称。
codex CLI等等TOML按设置传递时
uv run mcp-gateway \
--children-config /absolute/path/to/children_config.toml \
--children-abstract /absolute/path/to/children_abstract.json
从其他项目使用的例子(.mcp.json)
{
"mcpServers": {
"mcp-gateway": {
"command": "uvx",
"args": [
"--from",
"git+https://github.com/OWNER/MCPgateway",
"mcp-gateway",
"--children-config",
"/absolute/path/to/children_config.json",
"--children-abstract",
"/absolute/path/to/children_abstract.json"
],
"env": { "PYTHONUTF8": "1" }
}
}
}
--children-config 在 .json / .toml 对较大场景进行渲染期间已观察到该故障。
父服务器提供的主要工具
list_registered_children()已注册子服务器名称列表get_child_status()子服务器启动状态/错误信息get_schema(child_name)获取子服务器工具资源的模式(通过驻留会话)execute_child_tool(child_name, tool_name, tool_args, head_chars=None, tail_chars=None)运行子服务器工具(长句为head/tail),模板名称将采用不同的格式close_child_session(child_name)显式停止会话- 资源:
mcp://server_summary,mcp://children_servers(abstract提供时)
使用提示
- 架构确认:
get_schema("serena"),get_schema("codegraph")等获得工具列表。 - 工具运行:示例)
execute_child_tool("serena", "find_file", {"file_mask": "*.py", "relative_path": "."}) - codegraph如果需要重新索引
execute_child_tool("codegraph", "reindex_repository", {"incremental": true})中所述修改相应参数的值。
项目结构
MCPgateway/
├── mcp_gateway_server.py # 親MCPサーバー本体(FastMCPベース)
├── children_config.example.json # 子サーバー設定テンプレート
├── children_config.example.toml # 子サーバー設定テンプレート(TOML版)
├── children_abstract.example.json# 子サーバー概要テンプレート
├── children_config.json # 実運用用(ユーザー作成)
├── children_config.toml # 実運用用(TOMLで使う場合)
├── example.mcp.json # .mcp.json設定例
├── pyproject.toml # パッケージ定義・エントリポイント(mcp-gateway)
└── README.md
故障排除
- Python如果找不到环境:
uv sync中描述的场景,使用以下步骤创建明细表,以便在概念设计中分析体量的体积。 - 如果子服务器未启动:
children_config.json/children_config.toml检查命令/路径/环境变量- npx/uvx 等依存命令能否使用确认
- 安装子服务器端从属关系
- 子服务器的stderr查看项目中可用的所有族
DEBUG_MCP=1来定义自定义外观stderr中所述修改相应参数的值。