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 (通过 command 和 args,或连接到 HTTP/SSE 端点)。
  3. 执行 MCP 初始化握手 (initialize)。
  4. 动态发现能力 (调用 tools/list、resources/list、prompts/list)。
  5. 将发现的工具注册到 Copilot Chat ,在需要时自动调用 tools/call。

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

相关推荐
ZGi.ai12 小时前
Agent 一次要读多少资料?
知识检索·aiagent·上下文工程·zgi·agentruntime·项目简报
ZGi.ai2 天前
Agent 权限怎么配?先按动作拆开
工作流·工具调用·aiagent·zgi·agentruntime·权限配置
小易老师AI实战4 天前
AI Agent 完整实战:记忆机制 + 任务拆解 + 自动执行
llm·rag·大模型应用·aiagent·智能体工程化
晚风る5 天前
2026 AI Agent 工程化落地实战:从理论狂欢到产业规模化(AutoGen/LangGraph/CrewAI深度对比)
autogen·aiagent·大模型工程化·人工智能落地
ZGi.ai5 天前
Agent 重试会不会越帮越乱?
工作流·幂等性·aiagent·重试机制·zgi·agentruntime
deepseek2311 天前
Kolibri 拆解:计算像 3.5B、显存要 78GB 的德国主权模型,把合规做进六个架构决策
开源·大模型·moe·aiagent·ai架构
ZGi.ai15 天前
企业内网部署 Agent,先检查什么?
知识库·工作流·aiagent·人工确认·zgi·agentruntime·企业内网部署
Java的搬运工17 天前
2026 AI Agent 实战:五层架构、MCP 工具调用与十条避坑清单 合集 - AI行业观察
人工智能·架构·智能体·大模型应用·langgraph·aiagent·mcp
长谷深风11117 天前
Tool与Skill:AI能力设计的分水岭
java·人工智能·ai·大模型·aiagent
长谷深风11125 天前
根因定位:三步隔离法破解AIBadcase
人工智能·ai·大模型·retrieval·ai智能体·aiagent·aibadcase