Github Copilot 是怎么识别到 MCP server 的

GitHub Copilot 本身不会自动扫描或发现 MCP(Model Context Protocol)Server 。它是通过 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 Server

Copilot 相当于执行:

复制代码
复制代码
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/list

Server 返回:

复制代码
复制代码
[
  {
    "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.json

Copilot 会自动调用:

复制代码
复制代码
tools/call

发送:

复制代码
复制代码
{
  "name": "read_file",
  "arguments": {
      "path":"config.json"
  }
}

Server 返回:

复制代码
复制代码
{
  "content":"......"
}

然后 Copilot 再把内容交给大模型生成回答。


Copilot 是怎么知道有哪些 Tool 的?

关键就在于 MCP 协议中的动态发现(Discovery)机制

Server 会实现:

复制代码
复制代码
tools/list
resources/list
prompts/list

Copilot 启动时会调用这些接口。

例如:

复制代码
复制代码
initialize
        ↓
tools/list
        ↓
resources/list
        ↓
prompts/list

所以 不需要在 Copilot 里手工注册每个 Tool,只要 Server 返回新的工具:

复制代码
复制代码
create_issue
git_commit
search_code
deploy

Copilot 就会立即识别。


Copilot 如何识别是哪个 MCP Server?

它并不是通过协议识别,而是根据配置文件中的服务器名称(键名)来区分。例如:

复制代码
复制代码
{
  "servers": {
    "filesystem": {...},
    "github": {...},
    "database": {...}
  }
}

Copilot 会分别启动三个进程:

复制代码
复制代码
filesystem
github
database

每个 Server 都会独立完成初始化和能力发现。


总结

GitHub Copilot 识别 MCP Server 的流程如下:

  1. 读取 MCP 配置 (例如 mcp.json),获取所有已配置的 Server。
  2. 启动每个 MCP Server (通过 commandargs,或连接到 HTTP/SSE 端点)。
  3. 执行 MCP 初始化握手initialize)。
  4. 动态发现能力 (调用 tools/listresources/listprompts/list)。
  5. 将发现的工具注册到 Copilot Chat ,在需要时自动调用 tools/call

因此,Copilot 并不是"扫描电脑上有哪些 MCP Server",而是依据配置文件建立连接,再通过 MCP 协议动态发现该 Server 提供的能力 。这也是 MCP 的核心设计之一:Client 无需预先了解 Server 的具体工具,只需遵循统一协议即可完成集成。

相关推荐
IPHWT 零软网络3 天前
架构演进:基于零软IPHWT的中小企业轻量化通讯系统设计实践
saas·voip·系统集成·aiagent·呼叫中心·企业通讯·轻量化架构
李燚8 天前
Eino devops 调试系统源码:GraphCompileCallback 怎么工作(第50篇-E36)
数据库·golang·agent·devops·graphql·aiagent·eino
Token观测者14 天前
Agent 上生产的最后一公里:权限、发布、回滚和版本治理
ai安全·大模型落地·aiagent·权限隔离
李燚15 天前
自定义 Workflow:Eino 之上的 Agent 编排
workflow·tool·multi-agent·aiagent·eino
avi91111 个月前
Unity团结引擎,但是AI Tuanjie Cowork
aigc·团结引擎·aiagent·tuanjie cowork
李燚1 个月前
流式管道:Pipe、StreamReader、背压控制
agent·stream·pipe·aiagent·streamreader
李燚1 个月前
Workflow 编排:字段映射、数据流分离
agent·chain·workflow·graph·aiagent·eino
Soari2 个月前
【功能演进】Claude Code v2.1.153:交互逻辑重大反转,后台 Agent 体验大修
aiagent·claudecode·model逻辑反转
Artech2 个月前
[MAF的Agent管道详解-01]塑智能体边界,从AIAgent抽象类开始
ai·agent·aiagent·maf·agent管道