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:
- Prepare any hello-world MCP Server and deploy it to AWS AgentCore
- Make sure it listens at /mcp on port 8000
- Try to test the MCP using AgentCore Playground (it allows you to send the json compliant with the JsonRpcMessage class)
- Response with error 400 is being returned
Expected behavior
- MCP should work in AgentCore, just like Python FastMCP
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
- 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.
- 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.
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:
csharp-sdk/src/ModelContextProtocol.AspNetCore/StreamableHttpHandler.cs
Line 89 in 609499b
To Reproduce
Steps to reproduce the behavior:
Expected behavior
WriteJsonRpcErrorAsyncshould expose what exactly went wrong with parsing the json-rpc. The data is present inJsonExceptionbut is not used.Logs
Additional context
StreamableHttpHandlerand 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:
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.