Skip to content

MCP Server is unstable when deployed to AWS AgentCore #1842

Description

@JakubK

Describe the bug
MCP deployed to AgentCore responds with Error 400 for every jsonrpc request.
The AWS Logs did not show anything more than the status code, but I did dig out that its scenario from this Path:

await WriteJsonRpcErrorAsync(context,

To Reproduce
Steps to reproduce the behavior:

  1. Prepare any hello-world MCP Server and deploy it to AWS AgentCore
  2. Make sure it listens at /mcp on port 8000
  3. Try to test the MCP using AgentCore Playground (it allows you to send the json compliant with the JsonRpcMessage class)
  4. Response with error 400 is being returned

Expected behavior

  1. MCP should work in AgentCore, just like Python FastMCP
  2. WriteJsonRpcErrorAsync should expose what exactly went wrong with parsing the json-rpc. The data is present in JsonException but is not used.

Logs

Additional context

  1. I tried to solve the issue on my own by preparing custom StreamableHttpHandler and printing what it sees. This way I learned that it sees malformed payloads, JSON documents cut in half.

Then I tried to get away with Middleware like this to mitigate the issue:

app.Use(async(context, next) => {
  context.Request.EnableBuffering();
  ResetStream(context);
  await next();
  ResetStream(context);
};
// ...

static void ResetStream(HttpContext context) {
 if (context.Request.Body.CanSeek) context.Request.Body.Position = 0;
}

After doing this, I'm able to send the request in the AWS AgentCore Tester UI, but only once, after that I need to refresh the page, so there is still something missing.

  1. In AgentCore, MCP Servers are not accessible directly, instead there's AWS AgentCore API to be used, and some other entity inside AWS infrastructure is sending the requests to target MCP.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions