|
| 1 | +--- |
| 2 | +title: Adding MCP servers for {% data variables.copilot.copilot_cli %} |
| 3 | +shortTitle: Add MCP servers |
| 4 | +allowTitleToDifferFromFilename: true |
| 5 | +intro: 'Extend {% data variables.product.prodname_copilot_short %}''s capabilities by connecting Model Context Protocol (MCP) servers to provide additional tools and context.' |
| 6 | +versions: |
| 7 | + feature: copilot |
| 8 | +topics: |
| 9 | + - Copilot |
| 10 | +contentType: how-tos |
| 11 | +category: |
| 12 | + - Configure Copilot CLI # Copilot CLI bespoke page |
| 13 | + - Author and optimize with Copilot # Copilot discovery page |
| 14 | +--- |
| 15 | + |
| 16 | +The Model Context Protocol (MCP) is an open standard that defines how applications share context with large language models (LLMs). You can connect MCP servers to {% data variables.copilot.copilot_cli %} to give {% data variables.product.prodname_copilot_short %} access to external tools, data sources, and services. For an overview of MCP, see [AUTOTITLE](/copilot/concepts/about-mcp). |
| 17 | + |
| 18 | +## Adding an MCP server |
| 19 | + |
| 20 | +> [!NOTE] |
| 21 | +> The {% data variables.product.github %} MCP server is built into {% data variables.copilot.copilot_cli_short %} and is already available without any additional configuration. The steps below are for adding other MCP servers. |
| 22 | +
|
| 23 | +You can add MCP servers using the interactive `/mcp add` command within the CLI, or by editing the configuration file directly. |
| 24 | + |
| 25 | +For installation instructions, available tools, and URLs for specific MCP servers, see the [{% data variables.product.github %} MCP Registry](https://github.com/mcp). |
| 26 | + |
| 27 | +### Using the `/mcp add` command |
| 28 | + |
| 29 | +1. In interactive mode, enter `/mcp add`. A configuration form is displayed. Use <kbd>Tab</kbd> to navigate between fields. |
| 30 | +1. Next to **Server Name**, enter a unique name for the MCP server. This is the name you will use to refer to the server. |
| 31 | +1. Next to **Server Type**, select a type by pressing the corresponding number. The following types are available: |
| 32 | + |
| 33 | + * **Local** or **STDIO**: starts a local process and communicates over standard input/output (`stdin`/`stdout`). Both options work the same way. **STDIO** is the standard MCP protocol type name, so choose this if you want your configuration to be compatible with {% data variables.product.prodname_vscode_shortname %}, the {% data variables.copilot.copilot_coding_agent %}, and other MCP clients. |
| 34 | + * **HTTP** or **SSE**: connects to a remote MCP server. **HTTP** uses the Streamable HTTP transport. **SSE** uses the legacy HTTP with Server-Sent Events transport, which is deprecated in the MCP specification but still supported for backwards compatibility. <!-- markdownlint-disable-line GHD046 --> |
| 35 | + |
| 36 | +1. The remaining fields depend on the server type you selected: |
| 37 | + |
| 38 | + * If you chose **Local** or **STDIO**: |
| 39 | + |
| 40 | + * Next to **Command**, enter the command to start the server, including any arguments. For example, `npx @playwright/mcp@latest`. This corresponds to both the `command` and `args` properties in the JSON configuration file. |
| 41 | + * Next to **Environment Variables**, optionally specify environment variables the server needs, such as API keys or tokens, as JSON key-value pairs. For example, `{"API_KEY": "YOUR-API-KEY"}`. The `PATH` variable is automatically inherited from your environment. All other environment variables must be configured here. |
| 42 | + |
| 43 | + * If you chose **HTTP** or **SSE**: |
| 44 | + |
| 45 | + * Next to **URL**, paste the remote server URL. For example, `https://mcp.context7.com/mcp`. |
| 46 | + * Next to **HTTP Headers**, optionally specify HTTP headers as JSON. For example, `{"CONTEXT7_API_KEY": "YOUR-API-KEY"}`. |
| 47 | + |
| 48 | +1. Next to **Tools**, specify which tools from the server should be available. Enter `*` to include all tools, or provide a comma-separated list of tool names (no quotes needed). The default is `*`. |
| 49 | +1. Press <kbd>Ctrl</kbd>+<kbd>S</kbd> to save the configuration. The MCP server is added and available immediately without restarting the CLI. |
| 50 | + |
| 51 | +### Editing the configuration file |
| 52 | + |
| 53 | +You can also add MCP servers by editing the configuration file at `~/.copilot/mcp-config.json`. This is useful if you want to share configurations or add multiple servers at once. |
| 54 | + |
| 55 | +The following example shows a configuration file with a local server and a remote HTTP server: |
| 56 | + |
| 57 | +```json copy |
| 58 | +{ |
| 59 | + "mcpServers": { |
| 60 | + "playwright": { |
| 61 | + "type": "local", |
| 62 | + "command": "npx", |
| 63 | + "args": ["@playwright/mcp@latest"], |
| 64 | + "env": {}, |
| 65 | + "tools": ["*"] |
| 66 | + }, |
| 67 | + "context7": { |
| 68 | + "type": "http", |
| 69 | + "url": "https://mcp.context7.com/mcp", |
| 70 | + "headers": { |
| 71 | + "CONTEXT7_API_KEY": "YOUR-API-KEY" |
| 72 | + }, |
| 73 | + "tools": ["*"] |
| 74 | + } |
| 75 | + } |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +For more information on MCP server configuration, see [AUTOTITLE](/copilot/how-tos/use-copilot-agents/coding-agent/extend-coding-agent-with-mcp#writing-a-json-configuration-for-mcp-servers). |
| 80 | + |
| 81 | +## Managing MCP servers |
| 82 | + |
| 83 | +You can manage your configured MCP servers using the following `/mcp` commands in {% data variables.copilot.copilot_cli_short %}. |
| 84 | + |
| 85 | +* **List configured MCP servers:** Use the command `/mcp show`. This displays all configured MCP servers and their current status. |
| 86 | + |
| 87 | +* **View details about a specific server:** Use the command `/mcp show SERVER-NAME`. This displays the status of the specified server and the list of tools it provides. |
| 88 | + |
| 89 | +* **Edit a server's configuration:** Use the command `/mcp edit SERVER-NAME`. |
| 90 | + |
| 91 | +* **Delete a server:** Use the command `/mcp delete SERVER-NAME`. |
| 92 | + |
| 93 | +* **Disable a server:** Use the command `/mcp disable SERVER-NAME`. A disabled server remains configured but is not used by {% data variables.product.prodname_copilot_short %} for the current session. |
| 94 | + |
| 95 | +* **Enable a previously disabled server:** Use the command `/mcp enable SERVER-NAME`. |
| 96 | + |
| 97 | +## Using MCP servers |
| 98 | + |
| 99 | +Once you have added an MCP server, {% data variables.product.prodname_copilot_short %} can automatically use the tools it provides when relevant to your prompt. You can also directly reference an MCP server and specific tools in a prompt to ensure they are used. |
| 100 | + |
| 101 | +## Further reading |
| 102 | + |
| 103 | +* [AUTOTITLE](/copilot/concepts/about-mcp) |
| 104 | +* [AUTOTITLE](/copilot/how-tos/provide-context/use-mcp/extend-copilot-chat-with-mcp) |
| 105 | +* [AUTOTITLE](/copilot/how-tos/use-copilot-agents/coding-agent/extend-coding-agent-with-mcp) |
0 commit comments