modelcontextprotocol / modelcontextprotocol/java-sdk

MCP server to be able to return custom http codes

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

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

enhancement feature/session-storage
主要言語
Java
スター
3.7k
フォーク
1.1k
平均マージ
1日 15時間
マージ済み PR(30日)
9

説明

Please do a quick search on GitHub issues first, the feature you are about to request might have already been requested.

I am writing a custom MCP server. I am using an existing HttpServletStatelessServerTransport but mine is a stateful server with multiple pods. But since I do not have control on the session Id generation & validation & moreover, the validation in stateful transport is based on memory, I have chosen a stateless transport. But now on validating the sessionId in every MCP request, I want to be able to return an 404, if session id is not found or return 500 or other status codes. But I do not have this control now.

I was looking if there is a way in HttpServletStatelessServerTransport by which the MCP Error message can be passed by the McpStatelessServerHandler in the exception thrown by it

Current Behavior
In the below code, we can see that even if handleRequest method of McpStatelessServerHandler throws IllegalArgumentException, a customized error message cannot be returned to the client.

			logger.error("Failed to deserialize message: {}", e.getMessage());
			this.responseError(response, HttpServletResponse.SC_BAD_REQUEST, new McpError("Invalid message format"));
		}
		catch (Exception e) {
			logger.error("Unexpected error handling message: {}", e.getMessage());
			this.responseError(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
					new McpError("Unexpected error: " + e.getMessage()));
		}```

**Context**

The only work around is to find the MCP request method before calling the transport's service method and return appropriate http code with required message. This is not ideal though

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

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

はじめの一歩

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

調査の方向性

HttpServletStatelessServerTransport と McpStatelessServerHandler から始め、特に handleRequest と transport の service メソッドを確認します。例外がどのように responseError に到達するか、また現在の workaround が transport を呼び出す前に MCP リクエストメソッドをどのように調べているかを追跡します。handler の失敗が、呼び出し元が選択した HTTP ステータスと MCP エラーメッセージを返せるようになり、セッション検証の失敗も含まれることが完了条件です。

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

評価

技術スタック
java
領域
api, backend
issue の種類
機能追加
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

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

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