Github Copilot 是怎么识别到 MCP server 的

发布时间:2026/7/20 22:19:43
Github Copilot 是怎么识别到 MCP server 的 GitHub Copilot 本身不会自动扫描或发现 MCPModel Context ProtocolServer。它是通过MCP Client例如 VS Code 中的 GitHub Copilot Chat 扩展读取配置文件然后建立连接的。整个过程可以分为四步┌──────────────────────┐ │ GitHub Copilot Chat │ │ (MCP Client) │ └──────────┬───────────┘ │ 读取配置 ▼ mcp.json / settings.json │ ▼ ┌──────────────────────┐ │ 启动 MCP Server │ │ stdio / SSE / HTTP │ └──────────┬───────────┘ │ ▼ MCP 协议握手 │ ▼ 获取 tools/resources/prompts │ ▼ Copilot Chat 中显示可用工具第一步Copilot 读取 MCP 配置VS Code 安装最新版 GitHub Copilot 后会读取 MCP 配置例如{ servers: { filesystem: { command: npx, args: [ -y, modelcontextprotocol/server-filesystem, D:\\workspace ] } } }这里告诉 Copilot有一个 MCP Server 叫 filesystem使用 npx 启动。如果没有这个配置Copilot 根本不知道 Server 存在。第二步启动 MCP ServerCopilot 相当于执行npx -y modelcontextprotocol/server-filesystem D:\workspace或者python server.py或者node server.js取决于配置。Server 启动以后stdin -------- Copilot stdout -------- Copilot如果是 stdio 模式就是通过标准输入输出通信。第三步MCP 握手连接以后Copilot 会发送 MCP 初始化请求。类似简化{ method: initialize }Server 返回{ capabilities: { tools: {}, resources: {}, prompts: {} } }随后 Copilot 会继续询问tools/listServer 返回[ { name: read_file, description: Read file }, { name: write_file, description: Write file } ]Copilot 就知道哦这个 Server 提供两个 Tool。第四步显示到 Chat于是聊天窗口里会看到Filesystem MCP ✓ read_file ✓ write_file ✓ list_directory当你问帮我读取 config.jsonCopilot 会自动调用tools/call发送{ name: read_file, arguments: { path:config.json } }Server 返回{ content:...... }然后 Copilot 再把内容交给大模型生成回答。Copilot 是怎么知道有哪些 Tool 的关键就在于MCP 协议中的动态发现Discovery机制。Server 会实现tools/list resources/list prompts/listCopilot 启动时会调用这些接口。例如initialize ↓ tools/list ↓ resources/list ↓ prompts/list所以不需要在 Copilot 里手工注册每个 Tool只要 Server 返回新的工具create_issue git_commit search_code deployCopilot 就会立即识别。Copilot 如何识别是哪个 MCP Server它并不是通过协议识别而是根据配置文件中的服务器名称键名来区分。例如{ servers: { filesystem: {...}, github: {...}, database: {...} } }Copilot 会分别启动三个进程filesystem github database每个 Server 都会独立完成初始化和能力发现。总结GitHub Copilot 识别 MCP Server 的流程如下读取 MCP 配置例如mcp.json获取所有已配置的 Server。启动每个 MCP Server通过command和args或连接到 HTTP/SSE 端点。执行 MCP 初始化握手initialize。动态发现能力调用tools/list、resources/list、prompts/list。将发现的工具注册到 Copilot Chat在需要时自动调用tools/call。因此Copilot 并不是“扫描电脑上有哪些 MCP Server”而是依据配置文件建立连接再通过 MCP 协议动态发现该 Server 提供的能力。这也是 MCP 的核心设计之一Client 无需预先了解 Server 的具体工具只需遵循统一协议即可完成集成。