Skip to main content

GitHub Copilot and MCP in VS Code

VS Code can reach the gateway in three ways, and this page covers the two that are built into VS Code. GitHub Copilot Chat can add models from a Custom Endpoint, so the chat and agent panels can use any model behind the gateway. VS Code's MCP client can connect to the gateway's /mcp endpoint, so Copilot's agent mode gets the tools of every MCP server the key may use. The third way is the Spanway VS Code extension, compared with the Custom Endpoint below.

Going through the gateway means engineers use the models and tools the company approved, every chat turn and tool call shows on the gateway's Logs page under the engineer's key, the key's budget and rate limit apply, and the gateway's routing, fallbacks and guardrails cover editor traffic.

A real-world scenario​

A company already pays for Copilot Business and wants its engineers to also use two models it runs through Spanway, one for long design questions and one that is cheaper for agent work, plus its internal Jira MCP server. The admin creates one key per engineer with both models and the Jira server. Each engineer adds the two models as a Custom Endpoint, adds the gateway to .vscode/mcp.json, and picks the gateway models in the Copilot model picker. The admin sees the spend per engineer on Usage and every tool call on Logs.

Before you start​

  • VS Code with GitHub Copilot Chat. On Copilot Business or Enterprise, the organization's Copilot policy Bring Your Own Language Model Key in VS Code must not be turned off by your administrator.
  • A gateway address your computer can reach. VS Code calls the Custom Endpoint and MCP servers from your machine, so a private or localhost address works.
  • Gateway chat models that support tool calling. Copilot only offers a model in agent mode when its entry says it supports tool calling.

Make a key for VS Code​

The full recipe is make a key for a tool.

  1. Open Virtual Keys (/ui/api-keys) and click + Create New Key.
  2. Pick the engineer under Key Ownership, set Key Name to something like jane-vscode and leave Key Type on AI APIs.
  3. In Models, pick the chat models the engineer adds to Copilot. VS Code also sends utility tasks, such as chat titles and summaries, to a bring your own key model when chat.utilityModel or chat.utilitySmallModel points at one, so add those models to the key too, otherwise the utility tasks fail with 403 while chat works.
  4. For MCP, grant the MCP servers in the key's MCP server picker, see MCP access control.
  5. Under Optional Settings, set Max Budget (USD), Reset Budget, Requests per minute Limit (RPM) and the Tags code-context and tool:vscode-copilot.
  6. Click Create Key and copy the key. It is shown once.
curl -X POST https://gateway.example.com/key/generate \
-H "Authorization: Bearer $SPANWAY_MASTER_KEY" -H "Content-Type: application/json" \
-d '{"key_alias": "jane-vscode", "key_type": "llm_api", "models": ["gpt-6.1-sol", "claude-sonnet-5-5"], "max_budget": 150, "budget_duration": "30d", "rpm_limit": 60, "tags": ["code-context", "tool:vscode-copilot"]}'

Key tags need an Enterprise license. Without one the gateway does not create the key and answers Only premium users can add tags to keys, so leave Tags empty and drop tags from the call. The tool then works the same, only data policy routing cannot match the code-context tag.

Steps​

Gateway models in Copilot Chat​

  1. Check the key, the model names and their limits from a terminal.

    curl https://gateway.example.com/model_group/info -H "Authorization: Bearer $SPANWAY_API_KEY"

    Each entry has model_group (the name to use as the model id), max_input_tokens, max_output_tokens, supports_function_calling and supports_vision. Copilot cannot read this list itself, so you copy these values by hand.

  2. Open the Command Palette and run Chat: Manage Language Models, or click the gear in the chat model picker.

  3. Click Add Models and pick Custom Endpoint. Enter a group name such as Spanway, a display name and the virtual key.

  4. Pick the API type. Chat Completions works for every gateway model. Messages suits Claude models, because prompt caching and thinking pass through in their native form. Responses suits models built for the OpenAI Responses API.

  5. VS Code opens chatLanguageModels.json. Fill in one entry per gateway model as in the block below, and save. Use the full URL with the API path, so VS Code uses it as written.

  6. Pick a gateway model in the chat model picker and send a prompt. If the model does not appear, restart VS Code.

[
{
"name": "Spanway",
"vendor": "customendpoint",
"apiKey": "${input:spanway-key}",
"apiType": "chat-completions",
"models": [
{
"id": "gpt-6.1-sol",
"name": "GPT 6.1 Sol (Spanway)",
"url": "https://gateway.example.com/v1/chat/completions",
"toolCalling": true,
"vision": true,
"maxInputTokens": 794000,
"maxOutputTokens": 128000
},
{
"id": "claude-sonnet-5-5",
"name": "Claude Sonnet 5.5 (Spanway)",
"url": "https://gateway.example.com/v1/messages",
"apiType": "messages",
"toolCalling": true,
"vision": true,
"maxInputTokens": 872000,
"maxOutputTokens": 128000
}
]
}
]
FieldWhat to put in it
vendorAlways customendpoint.
apiKey${input:...}, so VS Code keeps the key in its secret storage and not in the file.
apiTypechat-completions, messages or responses. A model's own apiType overrides the group's.
idThe gateway's public model name, the model_group from step 1, typed exactly.
urlhttps://gateway.example.com/v1/chat/completions, /v1/messages or /v1/responses, matching the API type.
toolCallingtrue only when supports_function_calling is true. Without it the model is missing from agent mode.
visiontrue only when supports_vision is true.
maxInputTokens, maxOutputTokensBuilt from max_input_tokens and max_output_tokens in /model_group/info, so Copilot sizes prompts to what the gateway accepts. VS Code requires the two together to stay within the model's context window, so copy maxOutputTokens as it is and set maxInputTokens to max_input_tokens minus max_output_tokens. The example uses the gateway model map's values (922000 and 128000 for gpt-6.1-sol, 1000000 and 128000 for claude-sonnet-5-5), so replace them with your key's own answer.
requestHeadersOptional. For example {"x-spanway-code-context": "true"} marks the traffic as code for data policy routing.

VS Code sends the key as Authorization: Bearer <key> for Chat Completions and Responses, and as x-api-key: <key> for Messages. The gateway accepts both. The older github.copilot.chat.customOAIModels setting is deprecated, use the Custom Endpoint instead.

Gateway tools through VS Code's MCP client​

  1. Check the tools the key will see.

    curl https://gateway.example.com/v1/mcp/tools -H "Authorization: Bearer $SPANWAY_API_KEY"
  2. Create .vscode/mcp.json in the workspace, or run MCP: Open User Configuration for every workspace, and add the block below. The top level key is servers, not mcpServers, and the entry needs "type": "http".

    {
    "inputs": [
    {"type": "promptString", "id": "spanway-key", "description": "Spanway virtual key", "password": true}
    ],
    "servers": {
    "spanway": {
    "type": "http",
    "url": "https://gateway.example.com/mcp",
    "headers": {"Authorization": "Bearer ${input:spanway-key}"}
    }
    }
    }

    Instead of editing the file, you can run MCP: Add Server, pick HTTP (HTTP or Server-Sent Events), enter https://gateway.example.com/mcp and add the header afterwards in the file.

  3. Start the server from MCP: List Servers, accept the trust prompt, and enter the key when VS Code asks for it. VS Code stores it and does not ask again.

  4. Open Copilot Chat in agent mode and open the tools picker. The gateway's tools are listed as <server>-<tool>, for example jira-search_issues.

The /mcp address has no /v1. Use https://gateway.example.com/mcp/jira for one server only, or add the header "x-mcp-servers": "jira". A long tool list costs context on every request, so narrow it to the servers you need.

Expected result​

The gateway models appear in the Copilot model picker under the group name, answers stream into the chat, and in agent mode Copilot calls tools. The gateway's tools appear in the tools picker, and the server shows as running in MCP: List Servers.

On the gateway, open Logs (/ui/logs), click Filters, pick your key under Key Alias and click Apply Filters. Every chat turn and every tool call is a row with the model or MCP server, the tokens and the cost. MCP Servers, Live Connections lists your MCP session with the client name and your key alias. VS Code does not show response headers, so send the same request with curl and -i to read them.

curl -i https://gateway.example.com/v1/chat/completions \
-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \
-d '{"model": "gpt-6.1-sol", "messages": [{"role": "user", "content": "Say hello"}]}'

Look at x-spanway-call-id (the id to search for on Logs), x-spanway-model-group and x-spanway-model-id (the name and the deployment that answered), x-spanway-response-cost and x-spanway-key-spend.

What works and what does not​

FeatureThrough the gateway
Chat, edits and agent modeYes, for models with toolCalling: true in agent mode.
StreamingYes, on all three API types.
Tool callsYes. A model behind the name that cannot call tools fails in agent mode, so set toolCalling from supports_function_calling.
ImagesYes, when vision is true and the model behind the name supports images.
Prompt caching and extended thinking for Claude modelsYes with the Messages API type. Through Chat Completions they depend on how the gateway translates the request for that provider.
Inline suggestions, code completion, semantic search and embeddingsNo. Copilot serves these with its own models, so they never reach the gateway.
Copilot harness sessionsOnly with the experimental chat.agentHost.byokModels.enabled setting turned on.

Which one to use​

Copilot Custom EndpointSpanway VS Code extension
InstallBuilt into Copilot Chatspanway-vscode.vsix from the release page
Model listTyped by hand in chatLanguageModels.jsonRead from the gateway for the key, refreshed with Spanway: Refresh Models
Context limitsCopied by handTaken from the gateway
Prices in the model pickerNoYes
API typesChat Completions, Messages, ResponsesChat Completions

Pick the extension when the model list changes often or several people need the same setup, because nothing has to be copied by hand. Pick the Custom Endpoint when you want Claude models through the Messages API, or cannot install an extension. Both can be used side by side.

Errors​

A chat turn that fails shows the error in the chat. The gateway's text is in the answer body and on the request's row on Logs. A request that never reached the gateway has no row on Logs. For MCP, VS Code writes the error to the server's output, see Troubleshooting.

Gateway messageStatusCauseFix
Authentication Error, Invalid proxy server token passed401The key VS Code stored for the group or the MCP input is wrong, deleted or blocked.Update the key from the gear on the group's row in Chat: Manage Language Models. For MCP, see Rotate or remove the key.
Authentication Error, No api key passed in.401The apiKey or the MCP header is empty, or the MCP header was written as a bare $SPANWAY_API_KEY, which VS Code sends as those characters.Use ${input:spanway-key} as in the blocks above.
The requested model '<model>' is not available for this API key, or the model name is invalid.403The key may not use the model in id.Use a model_group from /model_group/info, or ask the admin to add the model to the key.
Invalid model name passed in model=<name>400No gateway model has the name in id.Copy the name exactly from /model_group/info. Names are case sensitive.
does not support parameters: <names>, for model=<model>400The model behind the name does not take a setting Copilot sent.Ask the admin to set drop_params: true on the deployment, see drop params, or use another API type.
Budget has been exceeded! Key=<key alias> Current cost: <spend>, Max budget: <max>422The key's budget is used up.Wait for the reset, or ask the admin to raise Max Budget (USD).
Rate limit exceeded for <scope>: <value>. Limit type: <type>.429Too many requests or tokens per minute. Agent mode sends many requests in a row.Wait a minute, or ask the admin to raise the key's RPM or TPM.
Not Found404The url has a doubled /v1, a path that does not match the API type, or MCP at /v1/mcp.Use the URLs from the table above, and /mcp without /v1 for MCP.
None, the model is missing from agent modenonetoolCalling is not true.Set it, when the model supports tool calls.
None, VS Code shows no MCP servernoneThe file uses mcpServers, or the entry has no "type": "http".Use the MCP block above.
None, self signed certificate in certificate chain or unable to get local issuer certificatenoneThe gateway's certificate is signed by a company authority VS Code does not trust.Add the company root certificate to the operating system's trust store, which VS Code passes to extensions while http.systemCertificates is on, as it is by default. Or start VS Code with NODE_EXTRA_CA_CERTS pointing at the certificate file.
None, ECONNREFUSED or getaddrinfo ENOTFOUNDnoneNothing listens at that address, or the host name does not resolve.Check curl https://gateway.example.com/health/liveliness, the VPN and the DNS name.

The client error reference lists every gateway error, and MCP clients has the MCP specific ones, such as a session an admin closed.

Troubleshooting​

  1. Run the curl from step 1 with the same key. If it answers 200, the gateway side is fine and the problem is in VS Code's configuration.
  2. Open Logs, filter by your Key Alias and the time of the failure. A row means the request reached the gateway, and the drawer shows the error, the model the router picked and the provider's answer. No row means the request never arrived, so check the url, the network and the certificate.
  3. For chat, open the Output panel and pick the GitHub Copilot Chat channel, which logs each request and its error.
  4. For MCP, run MCP: List Servers, pick spanway and Show Output. After the admin changes the key's server grants, run MCP: Reset Cached Tools so VS Code reads the new tool list.
  5. For a wrong answer rather than an error, send the request with curl and -i and read x-spanway-model-id and x-spanway-routing-reason to see which deployment answered and why. On a test gateway, --detailed_debug logs every request with its route and key check.

More symptoms are in troubleshooting.

Rotate or remove the key​

To rotate, open the key in Virtual Keys, click Regenerate Key and set a Grace Period such as 24h. In VS Code, update the Custom Endpoint key from the gear on the group's row in Chat: Manage Language Models. For MCP, VS Code keeps the ${input:...} value, so change the input's id in mcp.json, for example to spanway-key-2, in the input and in the header, and VS Code asks for the new key on the next start. Regenerating needs an Enterprise license. Without one, create a new key, switch VS Code to it and delete the old key. To stop access at once, use Block Key in the key's actions menu.

To stop using the gateway, delete the group in Chat: Manage Language Models and the spanway entry in mcp.json.