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 的具体工具,只需遵循统一协议即可完成集成。

相关推荐
ZGi.ai5 天前
ZGI Runtime:Agent 上线后要看哪些指标?
可观测性·aiagent·企业ai·zgi·运行指标
ZGi.ai5 天前
ZGI Runtime:切换模型后 Agent 为什么失效?
人工智能·aiagent·企业ai·模型切换·zgi·agentruntime
ZGi.ai6 天前
ZGI Agent:企业怎样治理工具调用?
工具调用·aiagent·权限治理·zgi·agentruntime·humanintheloop
ZGi.ai7 天前
ZGI Agent:修改配置时,怎样稳住线上版本?
版本管理·aiagent·zgi·agent发布·配置快照·agentruntime
梦想的颜色12 天前
2026 AI Agent 工程师完整技术图谱|从面试题「什么是本体 Ontology」切入,附精选面试题库
面试·知识图谱·langgraph·aiagent·大模型面试·本体·2026 面试真题
李燚14 天前
RAG 流水线设计:Eino 的 Loader → Transformer → Indexer → Retriever(第60篇-E46)
人工智能·深度学习·transformer·agent·rag·aiagent·eino
李燚15 天前
ReAct Agent 源码拆解:Eino 如何把 Graph 变成 Agent(第64篇-E50)
ai·agent·react·graph·multi-agent·aiagent·eino
IPHWT 零软网络24 天前
架构演进:基于零软IPHWT的中小企业轻量化通讯系统设计实践
saas·voip·系统集成·aiagent·呼叫中心·企业通讯·轻量化架构
李燚1 个月前
Eino devops 调试系统源码:GraphCompileCallback 怎么工作(第50篇-E36)
数据库·golang·agent·devops·graphql·aiagent·eino