modelcontextprotocol / modelcontextprotocol/java-sdk
MCP server to be able to return custom http codes
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Java
- Estrellas
- 3.7k
- Forks
- 1.1k
- Merge medio
- 1 d 15 h
- PR fusionados (30 d)
- 9
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con HttpServletStatelessServerTransport y McpStatelessServerHandler, especialmente con handleRequest y el método service del transporte. Rastrea cómo las excepciones llegan a responseError y cómo la solución temporal actual inspecciona el método de la solicitud MCP antes de llamar al transporte. El trabajo estará terminado cuando los errores del handler puedan devolver un estado HTTP y un mensaje de error MCP seleccionados por el llamador, incluidos los fallos de validación de sesión.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- java
- Área
- api, backend
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100