MCP Server is unstable when deployed to AWS AgentCore

オープン
#1,842 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
aws, csharp
領域
api, backend, cloud

調査の方向性

src/ModelContextProtocol.AspNetCore/StreamableHttpHandler.cs の 89 行目付近から始め、AWS AgentCore のデプロイメントを通じて不正で途中で切り詰められた JSON-RPC ペイロードを再現します。リクエストボディがどのように読み取られ、JsonException がどのように WriteJsonRpcErrorAsync に到達するかを追跡します。AgentCore リクエストが確実に処理され、パース失敗時にステータス 400 だけを返すのではなく、利用可能なエラー詳細が示されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

bug

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.
主要言語
C#
スター
4.5k
フォーク
814
平均マージ
9日 19時間
マージ済み PR(30日)
4

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

modelcontextprotocol/csharp-sdk のほかの issue

modelcontextprotocol/csharp-sdk の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。