Title: Streamable HTTP client: slow reception of large SSE tool responses (fromLineSubscriber line-assembly bottleneck) · Issue #1042 · modelcontextprotocol/java-sdk · GitHub
Open Graph Title: Streamable HTTP client: slow reception of large SSE tool responses (fromLineSubscriber line-assembly bottleneck) · Issue #1042 · modelcontextprotocol/java-sdk
X Title: Streamable HTTP client: slow reception of large SSE tool responses (fromLineSubscriber line-assembly bottleneck) · Issue #1042 · modelcontextprotocol/java-sdk
Description: Summary When a tool returns a large response over the Streamable HTTP client transport, the client takes ~5s to receive a ~4 MB body that curl/HttpClient.ofString() reads in ~0.4s. The bottleneck is the client-side SSE body reading in Re...
Open Graph Description: Summary When a tool returns a large response over the Streamable HTTP client transport, the client takes ~5s to receive a ~4 MB body that curl/HttpClient.ofString() reads in ~0.4s. The bottleneck i...
X Description: Summary When a tool returns a large response over the Streamable HTTP client transport, the client takes ~5s to receive a ~4 MB body that curl/HttpClient.ofString() reads in ~0.4s. The bottleneck i...
Opengraph URL: https://github.com/modelcontextprotocol/java-sdk/issues/1042
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Streamable HTTP client: slow reception of large SSE tool responses (fromLineSubscriber line-assembly bottleneck)","articleBody":"## Summary\n\nWhen a tool returns a large response over the Streamable HTTP **client** transport, the client takes ~5s to receive a ~4 MB body that `curl`/`HttpClient.ofString()` reads in ~0.4s. The bottleneck is the client-side SSE body reading in `ResponseSubscribers.sseToBodySubscriber`, not the server, network, or JSON parsing.\n\n## Environment\n\n- `io.modelcontextprotocol.sdk:mcp-core` / `mcp` **2.0.0** (latest)\n- JDK 25, Reactor (via SDK)\n- Server: Spring AI 2.0.0 `mcp-spring-webmvc` (`HttpServletStreamableServerTransportProvider`) returning a single large SSE `message` event — one compact-JSON `data:` line (~4.17 MB)\n- Client: `HttpClientStreamableHttpTransport` (`McpSyncClient.callTool`)\n\n## Measurements (steady-state, 3 runs)\n\n| Path | Time to receive ~4.17 MB |\n|---|---|\n| `McpSyncClient.callTool` (this SDK) | **~5,300 ms** |\n| Same payload via `curl` / `HttpClient` `BodyHandlers.ofString()` | ~0.4–0.75 s |\n| Jackson parse of the received JSON | \u003c 70 ms |\n\n→ ~10–13× slower than a plain one-shot read of the identical bytes.\n\n## Root cause analysis\n\nThe response body is effectively a single huge `data:` line (compact JSON has no newlines). `ResponseSubscribers.sseToBodySubscriber` uses `HttpResponse.BodySubscribers.fromLineSubscriber(...)`; assembling that one ~4 MB line through the JDK line subscriber is the cost.\n\nThings I tried:\n- Changing `SseLineSubscriber` demand from `upstream().request(1)` to `request(Long.MAX_VALUE)` → **no improvement** (so it isn't per-line backpressure).\n- Replacing the body subscriber with a **streaming byte-level SSE parser** (`BodySubscribers.fromSubscriber`, unbounded demand, accumulate `ByteBuffer`s, split on `\\n\\n` event boundaries, decode each event once) → **~0.4 s (≈13×)**.\n\n## Important constraint (must stay streaming)\n\nA whole-body `ofString` read fixes the speed but **breaks progress**: the server interleaves `notifications/progress` on the *same* POST response SSE stream before the final result. So the fix must remain a **streaming** parser that emits each SSE event as its boundary arrives (a byte-level parser does this while still avoiding the line-assembly cost).\n\n## Questions\n\n1. Is there a recommended approach/workaround for large tool responses on the client that we're missing?\n2. Would you accept a PR replacing `fromLineSubscriber` with a streaming byte-level SSE parser in `ResponseSubscribers.sseToBodySubscriber` (preserving incremental event emission)?\n3. Is this related to #844 (opt-in `application/json` response mode)? That would avoid SSE framing on the server side, but clients receiving SSE responses would still benefit from this fix.\n\nHappy to open a PR with the streaming parser + a benchmark if that's welcome.","author":{"url":"https://github.com/TaJoal","@type":"Person","name":"TaJoal"},"datePublished":"2026-06-28T00:29:09.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/1042/java-sdk/issues/1042"}
| 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:0080e390-b459-9810-60d8-fc2f0a064f49 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A352:33B318:27496BD:32FFBA8:6A5CAF66 |
| html-safe-nonce | 25e10a76269832a6ac50058b9a37ed491f5de0ba90b93cd34fb463f31e40b6ca |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMzUyOjMzQjMxODoyNzQ5NkJEOjMyRkZCQTg6NkE1Q0FGNjYiLCJ2aXNpdG9yX2lkIjoiNDkzMTQxODk5MzYzNzI0MDY3OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | df62b46ff524fbcbf30e35bc3ee13b75d051bea331fa59679465df7db39ab307 |
| hovercard-subject-tag | issue:4760498988 |
| 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/1042/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5560ed18f26e103ba556981a322adfb212a29de379b68ea20319827fc0f7ec37/modelcontextprotocol/java-sdk/issues/1042 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5560ed18f26e103ba556981a322adfb212a29de379b68ea20319827fc0f7ec37/modelcontextprotocol/java-sdk/issues/1042 |
| og:image:alt | Summary When a tool returns a large response over the Streamable HTTP client transport, the client takes ~5s to receive a ~4 MB body that curl/HttpClient.ofString() reads in ~0.4s. The bottleneck i... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | TaJoal |
| 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