modelcontextprotocol / modelcontextprotocol/csharp-sdk
MCP Server is unstable when deployed to AWS AgentCore
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 4.5k
- Forks
- 814
- Avg merge
- 9d 19h
- Merged PRs (30d)
- 4
Description
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:
https://github.com/modelcontextprotocol/csharp-sdk/blob/609499b2988e3f4a4c732552290bc9241fb90db9/src/ModelContextProtocol.AspNetCore/StreamableHttpHandler.cs#L89
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
WriteJsonRpcErrorAsyncshould expose what exactly went wrong with parsing the json-rpc. The data is present inJsonExceptionbut is not used.
Logs
Additional context
- I tried to solve the issue on my own by preparing custom
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:
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/ModelContextProtocol.AspNetCore/StreamableHttpHandler.cs around line 89 and reproduce the malformed, truncated JSON-RPC payload through an AWS AgentCore deployment. Trace how the request body is read and how JsonException reaches WriteJsonRpcErrorAsync. Done means AgentCore requests are handled reliably and parsing failures expose the available error details instead of only returning status 400.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- aws, csharp
- Domain
- api, backend, cloud
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100