modelcontextprotocol / modelcontextprotocol/java-sdk

MCP server to be able to return custom http codes

Aperta
#737 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

enhancement feature/session-storage
Lingua principale
Java
Stelle
3.7k
Fork
1.1k
Merge medio
1g 15h
PR unite (30g)
9

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con HttpServletStatelessServerTransport e McpStatelessServerHandler, in particolare con handleRequest e il metodo service del transport. Traccia il modo in cui le eccezioni raggiungono responseError e il modo in cui l’attuale workaround esamina il metodo della richiesta MCP prima di chiamare il transport. Il lavoro è completato quando gli errori del handler possono restituire uno stato HTTP e un messaggio di errore MCP scelti dal chiamante, inclusi gli errori di convalida della sessione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
java
Ambito
api, backend
Tipo di issue
Funzionalità
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.