feat(amazonq): add consent prompt for workspace-scoped MCP servers#2708
Merged
laileni-aws merged 4 commits intoaws:mainfrom Apr 28, 2026
Merged
feat(amazonq): add consent prompt for workspace-scoped MCP servers#2708laileni-aws merged 4 commits intoaws:mainfrom
laileni-aws merged 4 commits intoaws:mainfrom
Conversation
* fix: add missing closing brace in mcpManager.test.ts * fix: use getGlobalMcpConfigPath for cross-platform path in consent gate test
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2708 +/- ##
==========================================
+ Coverage 60.43% 60.53% +0.10%
==========================================
Files 278 279 +1
Lines 66065 66245 +180
Branches 4221 4248 +27
==========================================
+ Hits 39927 40103 +176
- Misses 26054 26057 +3
- Partials 84 85 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Will-ShaoHua
approved these changes
Apr 28, 2026
chungjac
approved these changes
Apr 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Workspace-scoped MCP server configurations (
.amazonq/mcp.jsonor.amazonq/agents/default.jsoninside a project folder) are started without user consent. Since these config files live in the workspace directory, they could be attacker-controlled — a cloned repo could contain a malicious MCP config that executes arbitrary commands on the user's machine when opened in the IDE.Additionally, the original implementation in #2702 had several issues:
isWorkspaceScopedcheck missedgetGlobalPersonaConfigPath— configs from~/.aws/amazonq/personas/default.jsonwere incorrectly treated as workspace-scoped, triggering unnecessary consent prompts for trusted global configs.sessionDeniedConsentwas not cleared inclose()— stale denial entries persisted throughreinitializeMcpServers()calls, inconsistent with how all other state is managed.sessionDeniedConsentused unnecessary!non-null assertion — the field was initialized in the constructor, making the definite assignment assertion redundant.mcp-approvals.json— when a server's config changed (new fingerprint), the old approval entry was kept alongside the new one instead of being replaced, causing the store to grow unbounded.fingerprintWorkspacewas not OS-agnostic — path hashing didn't normalize separators, so the same workspace could produce different hashes on Windows vs macOS/Linux.Solution
Consent gate (from #2702)
initOneServerInternalthat fires before connecting to any workspace-scoped MCP server~/.aws/amazonq/mcp.json,agents/default.json,personas/default.json) are trusted implicitly and bypass the prompt~/.aws/amazonq/mcp-approvals.json, keyed on(serverName, configFingerprint, workspaceHash)(command, args, env, url)— any mutation invalidates prior approvals and re-triggers the promptFixes on top of #2702
getGlobalPersonaConfigPathto the trusted set — theisWorkspaceScopedcheck now compares against all three global paths (mcp, agent, persona)sessionDeniedConsentinclose()— addedthis.sessionDeniedConsent.clear()alongside the other state clears!assertion with inline initialization —private sessionDeniedConsent = new Set<string>()recordApprovalnow filters by(serverName, workspaceHash)instead of(serverName, fingerprint, workspaceHash), so config changes replace the old entry instead of accumulatingfingerprintWorkspacenow normalizes paths withpath.resolve()and replaces backslashes with forward slashes before hashingTesting
mcpConsentStore(fingerprinting, approval CRUD, deduplication, stale eviction, edge cases)mcpManager(global path bypass for mcp/agent/persona, workspace prompts, denial caching, fingerprint invalidation, approval recording)Testing done
License
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.