- Newest
- Most votes
- Most comments
Yes, this is a known gap. Cognito supports PKCE with S256, but its discovery document doesn't include code_challenge_methods_supported. Strict MCP clients like ChatGPT reject that. I can't say whether AWS plans to add the field, since there's no public roadmap. A support case or feature request is the way to register interest.
Why the CloudFront fix didn't work
MCP clients find the authorization server in two steps:
- When an unauthenticated request gets a 401, the client reads the
resource_metadataURL from theWWW-Authenticateheader and fetches the protected resource metadata (PRM). - The PRM's
authorization_serversvalue is Cognito's issuer, so the client then fetches Cognito's discovery document and never sees your corrected one.
So publishing corrected metadata isn't enough. The client has to be directed to it by both the PRM and the 401 header.
A workaround that stays on AWS
Put CloudFront, with a custom domain, in front of the AgentCore Runtime endpoint, and have CloudFront Functions control discovery:
1. Serve your own PRM. At https://mcp.example.com/.well-known/oauth-protected-resource:
{ "resource": "https://mcp.example.com/mcp", "authorization_servers": ["https://auth.example.com"], "scopes_supported": ["<your-resource-server>/<scope>"] }
2. Serve your own authorization server metadata. At https://auth.example.com/.well-known/oauth-authorization-server, and optionally also at /.well-known/openid-configuration:
{ "issuer": "https://auth.example.com", "authorization_endpoint": "https://<cognito-domain>/oauth2/authorize", "token_endpoint": "https://<cognito-domain>/oauth2/token", "jwks_uri": "https://cognito-idp.us-east-1.amazonaws.com/<POOL_ID>/.well-known/jwks.json", "response_types_supported": ["code"], "grant_types_supported": ["authorization_code", "refresh_token"], "code_challenge_methods_supported": ["S256"], "token_endpoint_auth_methods_supported": ["none", "client_secret_basic", "client_secret_post"] }
issuer has to exactly match the URL the client used to find this document. That's why it's your own domain and not Cognito's. The actual authorization and token requests still go straight to Cognito.
3. Rewrite the 401 response. In a viewer-response function, replace the resource_metadata value in AgentCore's WWW-Authenticate header with your PRM URL. This is the piece that's usually missed. Without it, clients keep following AgentCore's PRM.
4. Proxy the MCP traffic. Forward /mcp to the AgentCore Runtime invocation endpoint, including the Authorization header.
Your customJWTAuthorizer doesn't need to change. It still validates Cognito-issued access tokens against Cognito's discovery URL. The facade only changes what the client finds during discovery.
One more thing to check: client registration
Cognito doesn't support Dynamic Client Registration (DCR). If ChatGPT only connects through DCR, you'll hit that next. Check whether its connector settings accept a pre-registered client ID: a public Cognito app client with no secret, PKCE, ChatGPT's callback URL, and your custom scope. If that works, the setup above is all you need. If DCR is required, the only AWS-only option is a small DCR Lambda that creates Cognito app clients. That's the custom OAuth component you wanted to avoid, so check this before building anything.
Is this worth doing?
The facade is a few static JSON documents plus a header rewrite, which is about as small as this workaround gets. Once Cognito adds the metadata field, you can remove it.
Relevant content
asked a year ago
asked a year ago
asked a year ago

Hey, just wanted to come back and say thank you! Your comment really helped me figure this out.
I ended up using a CloudFront Function as a proxy in front of AgentCore, handling the OAuth discovery endpoints, the 401 challenge, and advertising PKCE S256, while keeping Cognito for authentication.
And it finally worked! I managed to connect my MCP server to ChatGPT successfully.
I'd been stuck on this for quite a while, and your explanation pointed me in the right direction. Really appreciate you taking the time to help!