Title: Support application/json responses in Streamable HTTP transport (opt-in JSON response mode) · Issue #844 · modelcontextprotocol/java-sdk · GitHub
Open Graph Title: Support application/json responses in Streamable HTTP transport (opt-in JSON response mode) · Issue #844 · modelcontextprotocol/java-sdk
X Title: Support application/json responses in Streamable HTTP transport (opt-in JSON response mode) · Issue #844 · modelcontextprotocol/java-sdk
Description: 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(mappe...
Open Graph Description: Expected Behavior An opt-in configuration to return application/json for JSON-RPC requests within the Streamable HTTP transport, even with active sessions. Example: HttpServletStreamableServerTrans...
X Description: Expected Behavior An opt-in configuration to return application/json for JSON-RPC requests within the Streamable HTTP transport, even with active sessions. Example: HttpServletStreamableServerTrans...
Opengraph URL: https://github.com/modelcontextprotocol/java-sdk/issues/844
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Support application/json responses in Streamable HTTP transport (opt-in JSON response mode)","articleBody":"**Expected Behavior**\n\nAn opt-in configuration to return `application/json` for JSON-RPC requests within the Streamable HTTP transport, even with active sessions. Example:\n\n```java\nHttpServletStreamableServerTransportProvider.builder()\n .jsonMapper(mapper)\n .mcpEndpoint(\"/mcp\")\n .jsonResponse(true) // opt-in, default false\n .build();\n```\n\nWhen 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](https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#listening-for-messages-from-the-server)).\n\nAll other official MCP SDKs already support this as an opt-in option:\n\n| SDK | Config option | Default |\n|-----|--------------|---------|\n| [Go](https://github.com/modelcontextprotocol/go-sdk/blob/main/mcp/streamable.go#L144-L148) | `StreamableHTTPOptions.JSONResponse bool` | `false` |\n| [Python](https://github.com/modelcontextprotocol/python-sdk/blob/main/src/mcp/server/streamable_http.py#L131) | `is_json_response_enabled: bool` | `False` |\n| [TypeScript](https://github.com/modelcontextprotocol/typescript-sdk/blob/main/packages/server/src/server/streamableHttp.ts#L108) | `enableJsonResponse?: boolean` | `false` |\n| [Rust](https://github.com/modelcontextprotocol/rust-sdk/blob/main/crates/rmcp/src/transport/streamable_http_server/tower.rs#L45) | `StreamableHttpServerConfig.json_response: bool` | `false` |\n\n**Current Behavior**\n\nIn `HttpServletStreamableServerTransportProvider.doPost()`, session-bound `JSONRPCRequest` messages always get `text/event-stream`:\n\n```java\nelse if (message instanceof McpSchema.JSONRPCRequest jsonrpcRequest) {\n // For streaming responses, we need to return SSE\n response.setContentType(TEXT_EVENT_STREAM); // ← always SSE\n // ...\n}\n```\n\nThere 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.\n\n**Context**\n\nThe [MCP Streamable HTTP spec (2025-06-18, §2.1.5)](https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#sending-messages-to-the-server) states:\n\n\u003e \"If the input is a JSON-RPC request, the server MUST either return `Content-Type: text/event-stream` [...] or `Content-Type: application/json`, to return one JSON object.\"\n\nThis 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.\n\nThe 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.\n\nIn 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.\n\nWould it make sense to add this? Happy to contribute a PR if the maintainers agree.\n","author":{"url":"https://github.com/thiagomendes","@type":"Person","name":"thiagomendes"},"datePublished":"2026-03-04T01:20:55.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":11},"url":"https://github.com/844/java-sdk/issues/844"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:cb4a0fc2-6a85-5ba2-b48d-65a4e3610988 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8FC8:225DC1:50596ED:6907806:6A5D82C8 |
| html-safe-nonce | b09e97adf435f9477f39f99b7bc7c18776d24e2bf826aaede4f5848055f6deab |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RkM4OjIyNURDMTo1MDU5NkVEOjY5MDc4MDY6NkE1RDgyQzgiLCJ2aXNpdG9yX2lkIjoiOTUwMTIyNjU1NDM2ODY2MjQ4IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | b0a04c855cfbd744fe548afe53c5fbdfe5805c95139a4d928c3a4e97a48b889c |
| hovercard-subject-tag | issue:4019513941 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/java-sdk/844/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3a5bbb7fb6f26e3c526683f18df0472b00d3ceff87b80ef92f5fc2860f7622a1/modelcontextprotocol/java-sdk/issues/844 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3a5bbb7fb6f26e3c526683f18df0472b00d3ceff87b80ef92f5fc2860f7622a1/modelcontextprotocol/java-sdk/issues/844 |
| og:image:alt | Expected Behavior An opt-in configuration to return application/json for JSON-RPC requests within the Streamable HTTP transport, even with active sessions. Example: HttpServletStreamableServerTrans... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | thiagomendes |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| turbo-cache-control | no-preview |
| go-import | github.com/modelcontextprotocol/java-sdk git https://github.com/modelcontextprotocol/java-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 919609219 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/java-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 919609219 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/java-sdk |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width