# Secrets and API keys in GitHub Copilot (VS Code agent mode): keep credentials out of the agent's reach

Source: https://botpassword.com/agents/github-copilot
Last checked: 2026-10-25

GitHub Copilot's agent in VS Code supports MCP servers over stdio and HTTP/SSE, configured in `.vscode/mcp.json` (workspace), a user-profile `mcp.json`, or the portable `mcpServers` format. VS Code can prompt for secrets with `inputs` marked `password`, and recognises `.github/copilot-instructions.md`, `AGENTS.md` and `CLAUDE.md` as instruction files.

## MCP support

Yes. Transports: stdio, http, sse.

- workspace: `.vscode/mcp.json`
- user: `user-profile mcp.json (VS Code profile; added by `code --add-mcp`)`
- global: `$COPILOT_HOME/mcp-config.json (default ~/.copilot/mcp-config.json), portable `mcpServers` format`

Add a server with `code --add-mcp '{"name":"playwright","type":"stdio","command":"npx","args":["-y","@playwright/mcp@latest"]}'`.

## Environment variables and .env files

In the VS Code format, `${env:NAME}` reads an environment variable, `envFile` points a stdio server at an environment file, and `inputs` entries of type `promptString` with `password: true` are referenced as `${input:id}`; VS Code prompts the first time the server starts and stores the value securely. Portable configs (`.mcp.json`, `$COPILOT_HOME/mcp-config.json`) use `${NAME}` or `${NAME:-default}` and do not support VS Code inputs or environment files.

## File access

The agent works on the open workspace. Copilot content exclusion (set by repository, organisation or enterprise admins) does not apply to Agent or Edit mode in VS Code according to GitHub's documentation; it does apply to the agent in Visual Studio, on GitHub.com and in the Copilot CLI. VS Code MCP servers can be sandboxed per server (macOS and Linux) with `sandboxEnabled` and a `sandbox` block.

## Credential risks

- **CVE-2025-53773.** Prompt injection in source files, web pages or issues could make Copilot write an auto-approve setting into the workspace's `.vscode/settings.json`, disabling confirmations and allowing command execution. Microsoft patched it in August 2025; reports also mention abuse of `tasks.json` and adding malicious MCP servers.
- **Content exclusion does not cover VS Code agent mode.** GitHub's content-exclusion page lists Agent and Edit modes in VS Code as unsupported, so a file an administrator excluded can still be read by the agent there.
- **Local MCP servers run with your permissions.** VS Code's own guidance says local servers can run code on your machine and that you should not paste credentials into chat or commit them; the page's examples place a personal access token directly in the config file.

## FAQ

### Where is the VS Code MCP configuration file for Copilot?

`.vscode/mcp.json` in the workspace, or a user-profile `mcp.json` created by `code --add-mcp` or the MCP commands. Portable configs use `$COPILOT_HOME/mcp-config.json` or a workspace `.mcp.json` when the experimental setting is on.

### How do I keep an API key out of mcp.json in VS Code?

Declare an `inputs` entry with `"type": "promptString"` and `"password": true`, then reference it as `${input:id}`, or use `${env:NAME}`. VS Code prompts once and stores the value securely.

### Does Copilot agent mode read AGENTS.md?

Yes. VS Code lists `AGENTS.md` at the repository root, alongside `.github/copilot-instructions.md` and `CLAUDE.md`, as recognised instruction files.

### How do I give GitHub Copilot (VS Code agent mode) an API key without it seeing the key?

Don't put the key in the prompt, in a file GitHub Copilot (VS Code agent mode) can read, or in an environment variable it can print. Give it a tool that performs the authenticated step instead: a credential broker exposed over MCP or a CLI that injects the key into the command or HTTP request and returns only the result. BotPassword is that broker, through `bpw mcp` and the `bpw` CLI.

## Sources

- https://code.visualstudio.com/docs/copilot/customization/mcp-servers
- https://code.visualstudio.com/docs/agents/reference/mcp-configuration
- https://code.visualstudio.com/docs/copilot/customization/custom-instructions
- https://docs.github.com/en/copilot/concepts/context/content-exclusion
- https://www.tenable.com/cve/CVE-2025-53773
- https://www.wiz.io/vulnerability-database/cve/cve-2025-53773
