Fix GitHub App multi-repo token handling for MCP server#18159
Conversation
- Use YAML block scalar (newline-separated) for multiple repositories in actions/create-github-app-token, improving clarity and explicit formatting - Add GH_AW_GITHUB_APP_CONFIGURED env var to lockdown detection step when a GitHub App is configured (values: 'single' or 'multi') - Update determine_automatic_lockdown.cjs to recognize single-repo GitHub App tokens as custom tokens for lockdown on public repos; multi-repo app tokens are excluded from lockdown to preserve cross-repo access - Update test to expect the new block scalar format for multiple repos Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
@copilot do not generate determine-automatic-lockdown when tools.github.app is used. document this. |
…gured GitHub App tokens are already scoped to specific repositories via the app installation, so the automatic lockdown detection step is unnecessary and should not be generated. Changes: - generateGitHubMCPLockdownDetectionStep: return early when GitHub App is configured - mcp_renderer.go: set shouldUseStepOutput=false when app is configured - mcp_environment.go: skip GITHUB_MCP_LOCKDOWN env var when app is configured - determine_automatic_lockdown.cjs: remove GH_AW_GITHUB_APP_CONFIGURED complexity (step no longer runs when app is configured) - Add test: TestGitHubMCPAppTokenNoLockdownDetectionStep Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Done in 31beec6. When Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot update the compiler to NOT generate the automatic lockdown step when tools.github.app is set. |
This was already implemented in 31beec6. The |
There was a problem hiding this comment.
Pull request overview
This PR fixes GitHub App multi-repository token handling for the MCP server. When tools.github.app.repositories contains multiple repositories, the previous comma-separated inline format is replaced with a YAML block scalar format for better clarity. Additionally, the automatic lockdown detection step is now skipped when GitHub Apps are configured, since GitHub App tokens are already repository-scoped.
Changes:
- Modified repository formatting in GitHub App token minting to use YAML block scalar format (
|-) for multiple repositories instead of comma-separated values - Disabled automatic lockdown detection when GitHub App is configured, as app tokens are inherently scoped to specific repositories
- Updated environment variable and step output logic to skip
GITHUB_MCP_LOCKDOWNreferences when GitHub App is used
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
pkg/workflow/safe_outputs_app.go |
Changed multi-repository formatting from comma-separated to block scalar YAML format; removed unused strings import |
pkg/workflow/safe_outputs_app_test.go |
Updated test assertions to verify block scalar format for multiple repositories |
pkg/workflow/mcp_github_config.go |
Added logic to skip automatic lockdown detection step when GitHub App is configured |
pkg/workflow/mcp_renderer.go |
Modified shouldUseStepOutput logic to exclude GitHub App configurations |
pkg/workflow/mcp_environment.go |
Prevented GITHUB_MCP_LOCKDOWN environment variable from being added when GitHub App is configured |
pkg/workflow/github_mcp_app_token_test.go |
Added comprehensive test to verify lockdown detection is not generated with GitHub Apps |
actions/setup/js/determine_automatic_lockdown.cjs |
Updated JSDoc to document that script is not invoked when GitHub App is configured |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…hasGitHubApp helper Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Done in 1fd49dd. Added Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
hasGitHubApp(githubTool any) boolhelper tomcp_github_config.go, consistent with existing helpers (getGitHubToken,getGitHubLockdown, etc.)generateGitHubMCPLockdownDetectionStepto usehasGitHubApp(githubTool)instead ofdata.ParsedTools.GitHub.App != nilmcp_renderer.goshouldUseStepOutputcheck to usehasGitHubApp(githubTool)mcp_environment.goapp token and lockdown env var checks to usehasGitHubApp(githubTool)Original prompt
This section details on the original issue you should resolve
<issue_title>GitHub MCP
issue_readtool unavailable when app token is scoped to multiple repositories</issue_title><issue_description>## Summary
When
tools.github.app.repositoriescontains multiple repositories, the GitHub MCPissue_readtool becomes unavailable to the agent. The agent falls back to unauthenticated CLI/curl calls, which fail on private repos. Single-repo tokens work correctly.Reproduction
Working configuration (single repo):
Broken configuration (two repos — only change):
Both compile successfully. The lock file diff between the two is minimal — only the
repositories:value changes:This change appears in all three
actions/create-github-app-tokensteps (agent, safe_outputs, conclusion). No other differences.Evidence
Working run (single repo)
Run: 22346404501
Commit:
dc74a432("Test only on vscode-engineering")Result: Agent successfully called MCP
issue_readonmicrosoft/vscode-engineering#1905✅Failing run (two repos)
Run: 22346782685
Commit:
3c33ea38("compile with two repos")Result: Agent could not use MCP tools at all ❌
Agent log from the failing run:
The agent never attempted to use
issue_read— it went straight to CLI/curl, suggesting the MCP tool wasn't available or the token was not passed through.Lock File Analysis
The compiled lock file is structurally correct in both cases. The token generation step uses
actions/create-github-app-token@v2.2.1:The token is then passed as
GITHUB_MCP_SERVER_TOKENto the agent job and wired into the MCP config:{ "mcpServers": { "github": { "type": "stdio", "container": "ghcr.io/github/github-mcp-server:v0.31.0", "env": { "GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_MCP_SERVER_TOKEN}", "GITHUB_READ_ONLY": "1", "GITHUB_TOOLSETS": "issues" } } } }The plumbing is identical between the working and failing runs — only the
repositoriesvalue differs.Possible Root Causes
actions/create-github-app-tokenmay produce a token that doesn't cover all listed repos when the app's installation spans multiple repos.github-mcp-server:v0.31.0) doesn't handle multi-repo tokens: The server may check the token's repo scope and fail if more than one is listed.The GitHub App (CODE_REVIEW) IS installed on both repos — confirmed by the single-repo runs working independently with either
vscodeorvscode-engineering.Use Case
Cross-repository triage workflow in
microsoft/vscode-engineeringthat reads issues from bothmicrosoft/vscodeandmicrosoft/vscode-engineering(repo is specified at dispatch time viarepo_nameinput).Environment
issue_readtool unavailable when app token is scoped to multiple repositories #18115💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.