|
| 1 | +--- |
| 2 | +title: Scanning for secrets with the GitHub MCP server |
| 3 | +shortTitle: Scan for secrets with MCP |
| 4 | +allowTitleToDifferFromFilename: true |
| 5 | +intro: 'Detect exposed secrets in real time from your AI coding agent, before they ever reach your repository.' |
| 6 | +versions: |
| 7 | + feature: copilot |
| 8 | +permissions: 'People with write access to a repository.' |
| 9 | +contentType: how-tos |
| 10 | +category: |
| 11 | + - Protect your secrets |
| 12 | +--- |
| 13 | + |
| 14 | +The {% data variables.product.github %} Model Context Protocol (MCP) server lets you run {% data variables.product.prodname_secret_scanning %} directly from {% data variables.product.prodname_copilot %} agent mode, {% data variables.copilot.copilot_cli %}, and other MCP-compatible tools. Scan your code for exposed keys, tokens, and credentials as you work, and fix them before you push. |
| 15 | + |
| 16 | +The secret scanning tools are only available via the {% data variables.product.github %} remote MCP server. **Local MCP server configurations are not supported**. |
| 17 | + |
| 18 | +This works with any MCP-compatible agent or IDE, including {% data variables.product.prodname_vscode %}, JetBrains, Claude Code, Cursor, and Windsurf. The experience varies across clients. |
| 19 | + |
| 20 | +> [!NOTE] Findings returned by MCP-invoked scans are **ephemeral**. They are surfaced in your agent's chat for the current session only and are not persisted as alerts on {% data variables.product.github %}. This means these findings won't appear in the Security tab, in the {% data variables.product.prodname_secret_scanning %} alerts list, or in the REST/GraphQL APIs for alerts. MCP scans should be treated as a pre-commit safety check, not as a system of record. Remediate findings before they are pushed to the repository and persisted in Git history. |
| 21 | +
|
| 22 | +## Prerequisites |
| 23 | + |
| 24 | +* **{% data variables.product.prodname_GH_secret_protection %}** is enabled for the repository. |
| 25 | +* **{% data variables.product.github %} MCP server** is connected in your IDE or agent. See [AUTOTITLE](/copilot/how-tos/provide-context/use-mcp/set-up-the-github-mcp-server). |
| 26 | +* Your organization's **security configuration** determines which secret types are detected and whether push protection is enforced. The MCP tools respect your organization's push protection configuration (repository-level push protection settings are not used). |
| 27 | + |
| 28 | +## Step 1: Install and configure tools |
| 29 | + |
| 30 | +### Enable the `secret_protection` toolset |
| 31 | + |
| 32 | +Enable the `secret_protection` toolset to make the scanning tools available to your agent. The default toolsets do not include it. |
| 33 | + |
| 34 | +The `run_secret_scanning` tool is currently attached to the `copilot` toolset rather than `secret_protection`. You must explicitly include `run_secret_scanning` as an additional tool alongside the `secret_protection` toolset in your MCP configuration. |
| 35 | + |
| 36 | +{% cli %} |
| 37 | + |
| 38 | +{% data variables.copilot.copilot_cli %} has the {% data variables.product.github %} MCP server built in: |
| 39 | + |
| 40 | +```shell |
| 41 | +copilot mcp --toolsets=secret_protection --tools=run_secret_scanning |
| 42 | +``` |
| 43 | + |
| 44 | +{% endcli %} |
| 45 | + |
| 46 | +{% vscode %} |
| 47 | + |
| 48 | +Add the `secret_protection` toolset and the `run_secret_scanning tool` to your MCP configuration: |
| 49 | + |
| 50 | +```json copy |
| 51 | +{ |
| 52 | + "servers": { |
| 53 | + "github": { |
| 54 | + "url": "https://api.githubcopilot.com/mcp/", |
| 55 | + "headers": { |
| 56 | + "X-MCP-Toolsets": "secret_protection", |
| 57 | + "X-MCP-Tools": "run_secret_scanning" |
| 58 | + } |
| 59 | + } |
| 60 | + } |
| 61 | +} |
| 62 | +``` |
| 63 | + |
| 64 | +{% endvscode %} |
| 65 | + |
| 66 | +{% jetbrains %} |
| 67 | + |
| 68 | +In your JetBrains IDE, edit your MCP server configuration to include the `secret_protection` toolset and `run_secret_scanning` tool headers. For more information on configuring MCP servers in JetBrains, see [MCP Server](https://www.jetbrains.com/help/idea/mcp-server.html) in the JetBrains documentation. |
| 69 | + |
| 70 | +```json copy |
| 71 | +{ |
| 72 | + "servers": { |
| 73 | + "github": { |
| 74 | + "type": "http", |
| 75 | + "url": "https://api.githubcopilot.com/mcp/", |
| 76 | + "headers": { |
| 77 | + "GitHub-MCP-Toolsets": "secret_protection", |
| 78 | + "GitHub-MCP-Tools": "run_secret_scanning" |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | +} |
| 83 | +``` |
| 84 | + |
| 85 | +{% endjetbrains %} |
| 86 | + |
| 87 | +### (Optional) Install the {% data variables.product.prodname_AS %} plugin |
| 88 | + |
| 89 | +The [{% data variables.product.prodname_AS %} plugin](https://github.com/github/copilot-plugins/tree/main/plugins/advanced-security) gives you a `/secret-scanning` slash command for a streamlined scanning experience in {% data variables.copilot.copilot_cli %} and {% data variables.product.prodname_vscode %}. |
| 90 | +The plugin uses the MCP tools under the hood, so you'll still need to enable the `secret_protection` toolset. |
| 91 | + |
| 92 | +Instructions for installing the plugin: |
| 93 | +* For **{% data variables.copilot.copilot_cli %}**, see [AUTOTITLE](/copilot/how-tos/copilot-cli/customize-copilot/plugins-finding-installing#installing-plugins). |
| 94 | +* For **{% data variables.product.prodname_vscode %}**, see [Discover and install plugins](https://code.visualstudio.com/docs/copilot/customization/agent-plugins#_discover-and-install-plugins) in the {% data variables.product.prodname_vscode %} documentation. |
| 95 | + |
| 96 | +## Step 2: Scan your code |
| 97 | + |
| 98 | +Once the toolset is enabled, you can trigger a scan in several ways depending on your client. |
| 99 | + |
| 100 | +**Natural-language prompt**. In any MCP-compatible agent, you can ask: |
| 101 | + |
| 102 | +> "Scan my current changes for exposed secrets and show me the files and lines I should update before I commit." |
| 103 | +
|
| 104 | +> "Run {% data variables.product.prodname_secret_scanning %} on the files I've changed since my last commit and summarize any high-confidence findings." |
| 105 | +
|
| 106 | +**Slash command (requires the {% data variables.product.prodname_AS %} plugin)**. If you installed the optional plugin in Step 1, you can also use: |
| 107 | + |
| 108 | +>"/secret-scanning Review the staged diff for credentials, keys, or tokens and propose replacements using environment variables." |
| 109 | +
|
| 110 | +**Direct tool invocation:** You can also invoke the scanning tool directly from your client. |
| 111 | + |
| 112 | +{% cli %} |
| 113 | + |
| 114 | +Run `copilot --add-github-mcp-tool run_secret_scanning`. |
| 115 | + |
| 116 | +{% endcli %} |
| 117 | + |
| 118 | +{% vscode %} |
| 119 | + |
| 120 | +Type `/secret-scanning` in {% data variables.copilot.copilot_chat_short %}. |
| 121 | + |
| 122 | +{% endvscode %} |
| 123 | + |
| 124 | +{% jetbrains %} |
| 125 | + |
| 126 | +1. In your IDE, open {% data variables.copilot.copilot_chat_short %} |
| 127 | +1. Click the **Agent** tab |
| 128 | +1. Use a prompt like: "Scan my recent changes for exposed secrets before I commit." You can also click the tools icon in the chat box to browse available `secret_protection` tools directly. |
| 129 | + |
| 130 | +{% endjetbrains %} |
| 131 | + |
| 132 | +The agent returns: |
| 133 | + |
| 134 | +* The **type** of secret found |
| 135 | +* The **file and line** where it was detected |
| 136 | +* **Remediation steps**, such as removing or rotating the credential |
| 137 | + |
| 138 | +If push protection is enabled, the MCP server also blocks secrets from being included in any actions it takes on your behalf, such as commits, pull requests, or the creation of files. See [AUTOTITLE](/code-security/concepts/secret-security/working-with-push-protection-and-the-github-mcp-server). |
| 139 | + |
| 140 | +## Troubleshooting |
| 141 | + |
| 142 | +| Problem | Check | |
| 143 | +|---|---| |
| 144 | +| Scanning returns no results | Verify the `secret_protection` toolset is enabled in your MCP configuration. | |
| 145 | +| Repository not eligible |{% data variables.product.prodname_secret_scanning_caps %} via MCP is available to public repositories and requires {% data variables.product.prodname_GH_secret_protection %} to be enabled for private and internal repositories. | |
| 146 | +| Agent doesn't recognize the tool | Confirm your IDE or agent supports MCP. See [AUTOTITLE](/copilot/concepts/context/mcp#availability). | |
| 147 | +| Unexpected detection results | Your organization's security configuration controls which patterns are scanned. Check your repository security settings. | |
| 148 | +| Tool works in one client but not another | The experience varies across MCP-compatible clients. Check your client's MCP documentation for supported features. | |
| 149 | + |
| 150 | +## Further reading |
| 151 | + |
| 152 | +* [AUTOTITLE](/copilot/how-tos/provide-context/use-mcp-in-your-ide/configure-toolsets) |
0 commit comments