简介
模型上下文协议 (MCP) 是一个开放标准,用于定义应用程序与大型语言模型 (LLM) 共享上下文的方式。 有关 MCP 的概述,请参阅“关于模型上下文协议 (MCP)”。
有关当前可用的 MCP 服务器的信息,请参阅 MCP 服务器存储库。
企业和组织可以选择启用或禁用对组织或企业成员使用 MCP。 请参阅“管理企业中 GitHub Copilot 的策略和功能”。 MCP 策略仅**** 适用于具有来自配置了该策略的组织或企业中的 Copilot Business 或 Copilot Enterprise 订阅的用户。 Copilot 免费版、Copilot 专业版 或 Copilot Pro+ 的 MCP 访问权限不受此策略约束。
先决条件
- 对 Copilot 的访问权限****。 请参阅“什么是 GitHub Copilot?”。
- Visual Studio Code 版本 1.99 或更高版本。 有关如何安装 Visual Studio Code 的信息,请参阅 Visual Studio Code 下载页面。
- If you are a member of an organization or enterprise with a Copilot Business or Copilot Enterprise plan, the "MCP servers in Copilot" policy must be enabled in order to use MCP with Copilot.
在 GitHub Copilot 中配置 MCP 服务器
可以在配置文件中或通过 GitHub MCP 注册表手动配置 MCP 服务器。 GitHub MCP 注册表提供了 MCP 服务器的特选列表,可轻松将其中所列服务器添加到 Visual Studio Code 实例。
使用 GitHub MCP 注册表
注意
GitHub MCP 注册表位于 公共预览版 中,并可能发生更改。
仅 GitHub MCP 注册表中列出的 MCP 服务器可通过注册表添加。 其他服务器可手动配置。 请参阅手动配置 MCP 服务器。
- 访问 GitHub MCP 注册表。
- 在搜索栏中,搜索要添加的 MCP 服务器,然后单击匹配列表中的 MCP 服务器。
- 在 MCP 服务器页上,阅读安装要求详细说明及其他重要使用信息。 这些信息可能因服务器而异。
- ******** 单击“Install server”,然后选择“Install in VS Code”。
- 随即服务器的“Marketplace”页面上将打开 Visual Studio Code。 **** 单击“Install”将 MCP 服务器添加到 Visual Studio Code 实例。
- 如果需要进一步配置,请按照 GitHub MCP 注册表中 MCP 服务器页面上的说明进行操作。
- **** 若要确认是否已添加 MCP 服务器,可在Copilot 对话助手 的代理模式下,单击工具图标。 随即会显示一个下拉列表,其中显示了 Visual Studio Code 实例中当前可用的所有 MCP 服务器和关联工具。
手动配置 MCP 服务器
要在 Visual Studio Code 中配置 MCP 服务器,需要设置一个配置脚本,指定要使用的 MCP 服务器的详细信息。 可以为以下任一资源配置 MCP 服务器:
-
特定仓库。 这使你能够将 MCP 服务器共享给任何在 Visual Studio Code 中打开该项目的人。 为此,请在仓库的根目录中,创建
.vscode/mcp.json
文件。 -
Visual Studio Code 的个人实例。 你将是唯一有权访问已配置的 MCP 服务器的人员。 为此,请将配置添加到 Visual Studio Code 中的
settings.json
文件。 以这种方式配置的 MCP 服务器将在所有工作区中可用。注意
We recommend you use only one location per server. Adding the same server to both locations may cause conflicts and unexpected behavior.
以下步骤演示如何在 .vscode/mcp.json
文件中配置 Fetch MCP 服务器。 Fetch MCP 服务器是一种简单的 MCP 服务器,提供 Web 内容提取功能。 有关 Fetch MCP 服务器的详细信息,请参阅 MCP 服务器仓库中的 Fetch 目录。
可以使用相同的步骤在个人版 Visual Studio Code 设置中配置 MCP 服务器。 有关如何配置其他 MCP 服务器的详细信息,请参阅 MCP 服务器仓库。
有关如何配置 GitHub MCP 服务器的信息,请参阅“使用 GitHub MCP 服务器”。
-
将以下配置密钥添加到
.vscode/mcp.json
文件。JSON { "inputs": [ // The "inputs" section defines the inputs required for the MCP server configuration. { "type": "promptString" } ], "servers": { // The "servers" section defines the MCP servers you want to use. "fetch": { "command": "uvx", "args": ["mcp-server-fetch"] } } }
{ "inputs": [ // The "inputs" section defines the inputs required for the MCP server configuration. { "type": "promptString" } ], "servers": { // The "servers" section defines the MCP servers you want to use. "fetch": { "command": "uvx", "args": ["mcp-server-fetch"] } } }
-
保存
.vscode/mcp.json
文件。 -
服务器列表顶部的“Start”按钮将显示在
.vscode/mcp.json
文件中。 现单击“Start”按钮以启动 MCP 服务器。 这将触发输入对话框并发现服务器工具,然后存储这些工具供以后会话使用。 -
单击 Visual Studio Code 标题栏中的 图标,打开 Copilot 对话助手。
-
在 Copilot 对话助手 框中,从弹出菜单选择“Agent”****。
-
要查看可用 MCP 服务器的列表,请单击聊天框左上角的工具图标。 这将打开 MCP 服务器列表,可在其中查看 Visual Studio Code 实例中当前可用的所有 MCP 服务器和关联工具。
- 也可选择定义工具集以及可在聊天中引用的相关工具组。 工具集可帮助你更轻松地将相关的 MCP 工具进行分组,并快速启用或停用它们。 有关如何定义和使用工具集的信息,请参阅 VS Code 文档。
有关在 Visual Studio Code 中配置 MCP 服务器的详细信息,请参阅 Visual Studio Code 文档中的在 Visual Studio Code 中使用 MCP 服务器。
在 Copilot 对话助手 中使用 MCP 服务器
配置 MCP 服务器后,可以在 Copilot 对话助手 中使用它们来访问各种工具和服务。 在下面的示例中,我们将使用 Fetch MCP 服务器获取有关网页的详细信息。
-
单击 Visual Studio Code 标题栏中的 图标,打开 Copilot 对话助手。
-
在 Copilot 对话助手 框中,从弹出菜单选择“Agent”****。
-
在具有 MCP 配置的文件中,检查 MCP 服务器是否正在运行。 如果未正在运行,请单击“Start”按钮以启动 MCP 服务器。
-
让 Copilot 对话助手 提取 URL 的详细信息。 例如:
Fetch https://github.com/github/docs.
-
如果 Copilot 让你确认是否继续,请单击“Continue”****。
-
Copilot 将提取 URL 的详细信息,并在聊天框中显示它们。
也可选择使用 VS Code 中的 MCP 提示和资源。
- MCP 服务器可以定义与工具交互的预配置提示。 你可以在聊天中通过斜杠命令(格式为
/mcp.servername.promptname
)访问这些提示。 - MCP 服务器提供资源,即服务器希望公开的各种类型的数据。 例如,GitHub 的 MCP 服务器将仓库内容作为一种资源提供。 要将 MCP 服务器的资源添加到聊天上下文中,请单击聊天框中的“Add Context...”,然后单击“MCP Resources”********。
有关在 Visual Studio Code 中使用 MCP 服务器的详细信息,请参阅 Visual Studio Code 文档中的在 Visual Studio Code 中使用 MCP 服务器。
使用现有的 MCP 配置
如果 Claude Desktop 中已有 MCP 配置,则可以在 Visual Studio Code 中使用该配置来访问相同的 MCP 服务器。 为此,请将以下配置添加到 Visual Studio Code 中的 settings.json
文件:
"chat.mcp.discovery.enabled": true
"chat.mcp.discovery.enabled": true
Visual Studio Code 将自动查找现有配置并在 Visual Studio Code 实例中使用。
先决条件
- 对 Copilot 的访问权限****。 请参阅“什么是 GitHub Copilot?”。
- Visual Studio 版本 17.14 或更高版本****. 有关安装 Visual Studio 的详细信息,请参阅“Visual Studio 下载页”。
- 从 Visual Studio 登录到 GitHub****。
- If you are a member of an organization or enterprise with a Copilot Business or Copilot Enterprise plan, the "MCP servers in Copilot" policy must be enabled in order to use MCP with Copilot.
在 Visual Studio 中配置 MCP 服务器
-
在 Visual Studio 菜单栏中,单击“View”,然后单击“GitHub Copilot Chat”********。
-
在聊天面板底部,从模式下拉列表中选择“Agent”****。
-
在 Copilot 对话助手 窗口中,单击工具图标,然后单击工具选取器窗口中的加号图标。
-
在“Configure MCP server”弹出窗口中,填写各字段,包括服务器 ID、类型以及特定 MCP 服务器配置所需的任何其他字段。
Visual Studio 同时支持远程服务器和本地服务器。 使用 URL 和凭据定义的远程服务器在外部托管,以便于设置和共享,而使用命令行调用定义的本地服务器在本地计算机上运行,并且可以访问本地资源。 请参阅下面的示例配置,以 GitHub MCP 服务器为例。
-
单击“ 保存”。
-
如果你使用具有 OAuth 身份验证的远程服务器,请在
mcp.json
文件中,单击服务器上方 CodeLens 中的“Auth”以向服务器进行身份验证****。 一个弹出窗口或新窗口随即显示,使你能够使用帐户进行身份验证。 该服务器只能访问你批准的范围以及组织策略允许的范围。 -
在 Copilot 对话助手 窗口中,单击工具图标。 现在,你应该可以从你配置的 MCP 服务器中看到其他工具。
使用 OAuth 的远程服务器配置示例
-
对于“Server ID”,键入
github
。 -
对于“Type”,从下拉列表中选择“HTTP/SSE”。
-
对于“URL”,键入
https://api.githubcopilot.com/mcp/
。 -
单击“Save”后,
mcp.json
文件中的配置应如下所示:****JSON { "servers": { "github": { "url": "https://api.githubcopilot.com/mcp/" } } }
{ "servers": { "github": { "url": "https://api.githubcopilot.com/mcp/" } } }
-
在
mcp.json
文件中,单击服务器上方 CodeLens 中的“Auth”以向服务器进行身份验证****。 一个弹出窗口随即出现,使你能够使用 GitHub 帐户进行身份验证。
本地服务器配置示例
-
对于“Server ID”,键入
github
。 -
对于“Type”,从下拉列表中选择“stdio”。
-
对于“Command (with optional arguments)”,键入
docker "run", "-i", "--rm", "-e", "GITHUB_PERSONAL_ACCESS_TOKEN", "ghcr.io/github/github-mcp-server"
-
将设置的环境变量“GITHUB_PERSONAL_ACCESS_TOKEN”添加到 personal access token。
-
单击“Save”后,
mcp.json
文件中的配置应如下所示:****JSON { "servers": { "github": { "type": "stdio", "command": "docker", "args": [ "run", "-i", "--rm", "-e", "GITHUB_PERSONAL_ACCESS_TOKEN", "ghcr.io/github/github-mcp-server" ], "env": { "GITHUB_PERSONAL_ACCESS_TOKEN": "YOUR_GITHUB_PAT" } } } }
{ "servers": { "github": { "type": "stdio", "command": "docker", "args": [ "run", "-i", "--rm", "-e", "GITHUB_PERSONAL_ACCESS_TOKEN", "ghcr.io/github/github-mcp-server" ], "env": { "GITHUB_PERSONAL_ACCESS_TOKEN": "YOUR_GITHUB_PAT" } } } }
有关在 Visual Studio 中配置 MCP 服务器的详细信息,请参阅 Visual Studio 文档中的在 Visual Studio 中使用 MCP 服务器(预览版)。
先决条件
-
对 Copilot 的访问权限****。 请参阅“什么是 GitHub Copilot?”。
-
兼容的 JetBrains IDE****。 GitHub Copilot 与以下 IDE 兼容:
- IntelliJ IDEA(旗舰版、社区版、教育版)
- Android Studio
- AppCode
- CLion
- Code With Me Guest
- DataGrip
- DataSpell
- GoLand
- JetBrains Client
- MPS
- PhpStorm
- PyCharm(专业版、社区版、教育版)
- Rider
- RubyMine
- RustRover
- WebStorm
- Writerside
请参阅 JetBrains IDE 工具查找器进行下载。
-
If you are a member of an organization or enterprise with a Copilot Business or Copilot Enterprise plan, the "MCP servers in Copilot" policy must be enabled in order to use MCP with Copilot.
在 JetBrains IDE 中配置 MCP 服务器
- In the lower right corner, click .
- From the menu, select "Open Chat", make sure you are in Agent mode, then click the tools icon (called "Configure your MCP server") at the bottom of the chat window.
- Click Add MCP Tools.
- 在
mcp.json
文件中,定义 MCP 服务器。 JetBrains IDE 同时支持远程服务器和本地服务器。 远程服务器在外部托管,以便于设置和共享,而本地服务器在本地计算机上运行,并且可以访问本地资源。
可以使用以下配置作为示例:
使用 PAT 的远程服务器配置示例
{ "servers": { "github": { "url": "https://api.githubcopilot.com/mcp/", "requestInit": { "headers": { "Authorization": "Bearer YOUR_PAT_HERE" } } } } }
{
"servers": {
"github": {
"url": "https://api.githubcopilot.com/mcp/",
"requestInit": {
"headers": {
"Authorization": "Bearer YOUR_PAT_HERE"
}
}
}
}
}
本地服务器配置示例
{ "servers": { "memory": { "command": "npx", "args": [ "-y", "@modelcontextprotocol/server-memory" ] } } }
{
"servers": {
"memory": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-memory"
]
}
}
}
先决条件
- 对 Copilot 的访问权限****。 请参阅“什么是 GitHub Copilot?”。
- 适用于 Xcode 的 GitHub Copilot 扩展****。 请参阅“在环境中安装 GitHub Copilot 扩展”。
- If you are a member of an organization or enterprise with a Copilot Business or Copilot Enterprise plan, the "MCP servers in Copilot" policy must be enabled in order to use MCP with Copilot.
在 Xcode 中配置 MCP 服务器
- Open the GitHub Copilot for Xcode extension and go to "Settings".
- Alternatively, in an active Xcode workspace, you can find the settings by clicking Editor in the menu bar, selecting GitHub Copilot, then clicking Open GitHub Copilot for Xcode Settings.
- Select the MCP tab, then click Edit Config.
- 定义 MCP 服务器,编辑
mcp.json
。 Xcode 同时支持远程服务器和本地服务器。 远程服务器在外部托管,以便于设置和共享,而本地服务器在本地计算机上运行,并且可以访问本地资源。
可以使用以下配置作为示例:
使用 PAT 的远程服务器配置示例
{ "servers": { "github": { "url": "https://api.githubcopilot.com/mcp/", "requestInit": { "headers": { "Authorization": "Bearer YOUR_PAT_HERE" } } } } }
{
"servers": {
"github": {
"url": "https://api.githubcopilot.com/mcp/",
"requestInit": {
"headers": {
"Authorization": "Bearer YOUR_PAT_HERE"
}
}
}
}
}
本地服务器配置示例
{ "servers": { "memory": { "command": "npx", "args": [ "-y", "@modelcontextprotocol/server-memory" ] } } }
{
"servers": {
"memory": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-memory"
]
}
}
}
先决条件
- 对 Copilot 的访问权限****。 请参阅“什么是 GitHub Copilot?”。
- 兼容的 Eclipse 版本****。 若要使用 GitHub Copilot 扩展,必须拥有 Eclipse 版本 2024-09 或更高版本。 请参阅 Eclipse 下载页。
在 Eclipse 中配置 MCP 服务器
- Click the Copilot icon () in the status bar at the bottom of Eclipse.
- From the menu, select Open Chat and, in the chat window, click the "Configure Tools..." icon.
- Alternatively, you can select Edit preferences, then in the left pane, expand GitHub Copilot and click MCP.
- 在“Server Configurations”下,定义你的 MCP 服务器。 Eclipse 同时支持远程服务器和本地服务器。 远程服务器在外部托管,以便于设置和共享,而本地服务器在本地计算机上运行,并且可以访问本地资源。
可以使用以下配置作为示例:
使用 PAT 的远程服务器配置示例
{ "servers": { "github": { "url": "https://api.githubcopilot.com/mcp/", "requestInit": { "headers": { "Authorization": "Bearer YOUR_PAT_HERE" } } } } }
{
"servers": {
"github": {
"url": "https://api.githubcopilot.com/mcp/",
"requestInit": {
"headers": {
"Authorization": "Bearer YOUR_PAT_HERE"
}
}
}
}
}
本地服务器配置示例
{ "servers": { "memory": { "command": "npx", "args": [ "-y", "@modelcontextprotocol/server-memory" ] } } }
{
"servers": {
"memory": {
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-memory"
]
}
}
}
创建新的 MCP 服务器
可以创建新的 MCP 服务器以满足你的特定需求,然后将其与 Copilot 对话助手 集成。 例如,可以创建连接到数据库或 Web 服务的 MCP 服务器,然后在 Copilot 对话助手 中使用该服务器对该数据库或 Web 服务执行任务。
有关创建和配置自己的 MCP 服务器的详细信息,请参阅官方 MCP 文档。