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 的流程如下:
- 读取 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 的具体工具,只需遵循统一协议即可完成集成。