fix: add sdpm-mcp/invoke scope to WebClient OAuth config#112
Merged
okamoto-aws merged 2 commits intomainfrom May 3, 2026
Merged
fix: add sdpm-mcp/invoke scope to WebClient OAuth config#112okamoto-aws merged 2 commits intomainfrom
okamoto-aws merged 2 commits intomainfrom
Conversation
651f738 to
c67889a
Compare
WebClient's access token lacked sdpm-mcp/invoke scope, causing Agent to MCP Server requests to fail with 401 Unauthorized after PR #83. Scope is added via the UpdateCognitoCallbackUrls custom resource in web-ui-stack.ts, not via CDK's addClient oAuth.scopes. This avoids Cognito UserPoolClient replacement (which would break existing cross-stack exports) and keeps the change safe for in-place upgrades of already-deployed environments. - web-ui-stack.ts: add sdpm-mcp/invoke to AllowedOAuthScopes and to aws-exports.json scope field - infra.ts: pass authStack.mcpCustomScope to WebUiStack
c67889a to
13c37e1
Compare
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.
Summary
PR #83 introduced scope-based auth for the MCP Server (
allowedScopes: ["sdpm-mcp/invoke"]), but did not add that scope to the WebClient's allowed OAuth scopes. As a result, tokens issued to WebUI users are missingsdpm-mcp/invoke, and Agent → MCP Server requests fail with401 Unauthorized. Chat stops streaming and the user sees a perpetual loading indicator.This PR adds
sdpm-mcp/invoketo the WebClient via the existingUpdateCognitoCallbackUrlscustom resource in WebUiStack. This approach avoids any changes toAuthStack'sUserPoolClientconstruct — which matters because modifyingoAuth.scopeson the CDK construct triggers a CloudFormationUserPoolClientreplacement, and the client's ID is exported via auto-generatedFn::ImportValueto SdpmAgent / SdpmRuntime / SdpmWebUi. A replacement would fail with "Cannot delete export" on any in-place upgrade.Changes
infra/lib/web-ui-stack.tsmcpCustomScopeprop; include it inAllowedOAuthScopesof theUpdateCognitoCallbackUrlscustom resource; append it to thescopefield written toaws-exports.jsonso that the browser OIDC library explicitly requests it on token refreshinfra/bin/infra.tsauthStack.mcpCustomScopetoWebUiStackAuthStackis intentionally left untouched. The Cognito Resource Server and the WebClient itself are not modified — only theAllowedOAuthScopesvalue on the existing client is updated via a Cognito API call, which is an in-place update with no replacement.Why custom resource instead of CDK oAuth.scopes
Changing
oAuth.scopesonuserPool.addClient(...)causes CDK to emit aUserPoolClientreplacement. CloudFormation then tries to delete the outgoing client's auto-generated export (SdpmAuth:ExportsOutputRefUserPoolWebClient...), which is currently imported by three downstream stacks. The delete fails, and the entire Auth stack rolls back. The custom resource route sidesteps that by leaving CloudFormation resource definitions unchanged and just patching the live Cognito client.Verification
npx tsc --noEmitpassesus-east-1viabash scripts/deploy.sh— all stacksCREATE_COMPLETE/UPDATE_COMPLETEsdpm-mcp/invokein its allowed scopesFollow-up
There is a broader refactor being considered to stop using auto-generated CloudFormation exports for cross-stack references and migrate to SSM Parameter Store instead. That work will be tracked in a separate PR (#113). The current PR is deliberately minimal and only fixes the immediate 401 regression.