modelcontextprotocol / modelcontextprotocol/csharp-sdk

MCP Server is unstable when deployed to AWS AgentCore

Open
#1,842 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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:

  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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.