Support application/json responses in Streamable HTTP transport (opt-in JSON response mode)
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 64/100
Direção de pesquisa
Comece em HttpServletStreamableServerTransportProvider.doPost() e compare seu caminho JSON-RPC vinculado à sessão com o tratamento de application/json no caminho initialize e em HttpServletStatelessServerTransport. Considera-se concluído quando uma configuração jsonResponse opt-in tem false como padrão, retorna JSON armazenado em buffer para solicitações vinculadas à sessão quando habilitada e mantém o caminho SSE independente para notificações do servidor.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Expected Behavior
An opt-in configuration to return application/json for JSON-RPC requests within the Streamable HTTP transport, even with active sessions. Example:
HttpServletStreamableServerTransportProvider.builder()
.jsonMapper(mapper)
.mcpEndpoint("/mcp")
.jsonResponse(true) // opt-in, default false
.build();
When enabled, doPost() for JSONRPCRequest would buffer the response from session.responseStream() and return it as application/json instead of opening an SSE stream. Server-initiated notifications would go through the standalone SSE stream (GET on the same /mcp endpoint, as defined in the Streamable HTTP spec).
All other official MCP SDKs already support this as an opt-in option:
| SDK | Config option | Default |
|---|---|---|
| Go | StreamableHTTPOptions.JSONResponse bool |
false |
| Python | is_json_response_enabled: bool |
False |
| TypeScript | enableJsonResponse?: boolean |
false |
| Rust | StreamableHttpServerConfig.json_response: bool |
false |
Current Behavior
In HttpServletStreamableServerTransportProvider.doPost(), session-bound JSONRPCRequest messages always get text/event-stream:
else if (message instanceof McpSchema.JSONRPCRequest jsonrpcRequest) {
// For streaming responses, we need to return SSE
response.setContentType(TEXT_EVENT_STREAM); // ← always SSE
// ...
}
There is no way to get application/json for session-bound requests. The initialize request (line 461) and HttpServletStatelessServerTransport (line 173) already return application/json - so the pattern exists in the codebase.
Context
The MCP Streamable HTTP spec (2025-06-18, §2.1.5) states:
"If the input is a JSON-RPC request, the server MUST either return
Content-Type: text/event-stream[...] orContent-Type: application/json, to return one JSON object."
This means session management does not require SSE for every response. There are scenarios where a server benefits from sessions (capability negotiation, logging, server-initiated notifications via GET) but its tool handlers produce simple single-message responses that don't need SSE framing.
The existing STATELESS mode (HttpServletStatelessServerTransport) does return application/json, but it removes session management entirely - no server-to-client notifications, no sampling, no capability tracking. This feature request is about supporting application/json responses within the Streamable transport, with sessions, as the spec allows and as the other SDKs already implement.
In local benchmarks comparing MCP server implementations across different SDKs, we observed that switching from SSE-only to JSON responses for simple tool calls (single request-response, no intermediate notifications) resulted in significant performance improvements, primarily due to eliminating chunked transfer encoding, AsyncContext lifecycle overhead, and SSE framing/parsing on both server and client sides.
Would it make sense to add this? Happy to contribute a PR if the maintainers agree.
- Linguagem predominante
- Java
- Estrelas
- 3.7k
- Forks
- 1.1k
- Merge médio
- 1d 15h
- PRs com merge (30d)
- 9
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de modelcontextprotocol/java-sdk
-
area/transport bug P2
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
modelcontextprotocol/java-sdk#1136 ·
-
area/client bug P2
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
modelcontextprotocol/java-sdk#1124 · 1 comentário ·
-
ServerCapabilities.logging is added unconditionally, overriding the caller's explicit capabilities Abertabug P2 ready for work
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
modelcontextprotocol/java-sdk#1086 · 1 comentário ·
-
enhancement good first issue P3
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
modelcontextprotocol/java-sdk#1067 ·
-
bug P2 ready for work
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
modelcontextprotocol/java-sdk#898 · 1 comentário ·
Todas as issues de modelcontextprotocol/java-sdk
Issues semelhantes
-
Bug Java Platform: Java
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
getsentry/sentry-java#6138 · 1 comentário ·
-
bug needs triage p2
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
GoogleCloudPlatform/DataflowTemplates#4273 · 1 comentário ·
-
[Studio][Bug] Bulk-deleting a full page of alert rules steps the page back while more rules remain Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
apache/rocketmq-dashboard#4654 · 1 comentário ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100