awslabs / awslabs/agentcore-samples
Gateway mcpServer target to AgentCore Runtime: JWT-auth sessions start but requests never reach container
- Dominant language
- Python
- Stars
- 3.4k
- Forks
- 1.3k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 30
Description
## Description
When using an AgentCore MCP Gateway to target an AgentCore Runtime (mcpServer target type with OAUTH credential provider), the Runtime starts a session and the MCP server container boots successfully, but **no HTTP requests are ever routed to the container**. The Gateway times out after 20 seconds.
The same Runtime works correctly when accessed via `mcp-proxy-for-aws` (SigV4 auth). The issue is specific to JWT/Bearer token authentication.
## Reproduction Steps
### Setup
- Runtime: MCP server using FastMCP with `stateless_http=True`, port 8000
- Gateway: CUSTOM_JWT authorizer with Cognito
- Credential provider: CustomOauth2 with Cognito M2M client (client_credentials grant)
- Runtime authorizer: customJWTAuthorizer with same Cognito pool, allowedClients includes the M2M client_id
### Steps
1. Create Gateway target pointing to Runtime invocations URL with OAUTH credential provider
2. Or: `curl -X POST` to Runtime invocations URL with `Authorization: Bearer `
### Expected
- Runtime validates JWT, routes request to container on port 8000/mcp
- Container processes MCP initialize/tools_list
- Gateway target becomes ACTIVE
### Actual
- Runtime starts a new session (container boots, server logs show "Uvicorn running on http://0.0.0.0:8000")
- **No HTTP request ever reaches the container** (no uvicorn access logs)
- Gateway times out: "Did not observe any item or terminal signal within 20000ms"
- Direct curl with Bearer token hangs indefinitely (0 bytes received after 90+ seconds)
## Evidence
**SigV4 works (via mcp-proxy-for-aws):**
```
Response: {"jsonrpc":"2.0","id":1,"error":{"code":-32602,"message":"Invalid request parameters","data":""}}
```
(Response received in ~10s including cold start)
**Bearer token hangs:**
```bash
curl -X POST "https://bedrock-agentcore.us-east-1.amazonaws.com/runtimes/{ARN}/invocations?qualifier=DEFAULT" \
-H "Authorization: Bearer " \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"initialize","params":{...},"id":1}'
# Hangs indefinitely - upload completes, 0 bytes downloaded
```
**NO_AUTH (no Bearer token) returns clear error:**
```json
{"jsonrpc":"2.0","error":{"code":-32001,"message":"Missing Authentication Token"},"id":"null"}
```
**CloudWatch shows session starts but no requests:**
```
2026-03-02 01:37:06 [INFO] Starting MCP server on 0.0.0.0:8000 (streamable-http)
INFO: Started server process [1]
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
# No access logs - no requests ever arrive
```
## Configuration
Runtime authorizer:
```json
{
"customJWTAuthorizer": {
"discoveryUrl": "https://cognito-idp.us-east-1.amazonaws.com/{pool_id}/.well-known/openid-configuration",
"allowedClients": ["{m2m_client_id}"]
}
}
```
JWT token claims (valid):
```json
{
"sub": "{m2m_client_id}",
"token_use": "access",
"scope": "qualio-mcp-gateway/invoke",
"iss": "https://cognito-idp.us-east-1.amazonaws.com/{pool_id}",
"client_id": "{m2m_client_id}"
}
```
## Environment
- Region: us-east-1
- bedrock-agentcore-starter-toolkit: 0.3.0
- FastMCP (mcp[cli]) with streamable-http, stateless_http=True
- Python 3.12
## Note
The official sample notebook `01-tutorials/02-AgentCore-gateway/05-mcp-server-as-a-target/01-mcp-server-target.ipynb` shows this pattern working. Our configuration matches the sample but the Runtime does not forward JWT-authenticated requests to the container.
Contributor guide
Research direction
Start by comparing the configuration in 01-tutorials/02-AgentCore-gateway/05-mcp-server-as-a-target/01-mcp-server-target.ipynb with the reported Runtime and Gateway setup. Reproduce the request with curl and inspect CloudWatch startup and access logs to trace the JWT-authenticated path. Done means the valid Bearer request reaches the container and the Gateway target becomes ACTIVE.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, python
- Domain
- api, authentication, cloud
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100