Title: Deprecate Builder.customizeRequest() in favor of httpRequestCustomizer() · Issue #788 · modelcontextprotocol/java-sdk · GitHub
Open Graph Title: Deprecate Builder.customizeRequest() in favor of httpRequestCustomizer() · Issue #788 · modelcontextprotocol/java-sdk
X Title: Deprecate Builder.customizeRequest() in favor of httpRequestCustomizer() · Issue #788 · modelcontextprotocol/java-sdk
Description: Bug description Builder.customizeRequest() in both HttpClientSseClientTransport and HttpClientStreamableHttpTransport executes its consumer once at build time, mutating the shared requestBuilder. Any headers set here (e.g., Authorization...
Open Graph Description: Bug description Builder.customizeRequest() in both HttpClientSseClientTransport and HttpClientStreamableHttpTransport executes its consumer once at build time, mutating the shared requestBuilder. A...
X Description: Bug description Builder.customizeRequest() in both HttpClientSseClientTransport and HttpClientStreamableHttpTransport executes its consumer once at build time, mutating the shared requestBuilder. A...
Opengraph URL: https://github.com/modelcontextprotocol/java-sdk/issues/788
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Deprecate Builder.customizeRequest() in favor of httpRequestCustomizer()","articleBody":"**Bug description**\n\n`Builder.customizeRequest()` in both `HttpClientSseClientTransport` and `HttpClientStreamableHttpTransport` executes its consumer **once at build time**, mutating the shared `requestBuilder`. Any headers set here (e.g., `Authorization`) are frozen into the template and copied to every subsequent request via `requestBuilder.copy()`. They cannot be updated after the transport is built.\n\nThis becomes a significant issue for OAuth token refresh scenarios: after refreshing an access token, the transport continues sending the **old expired token** because the header was baked into the request builder at construction time.\n\nThe method name `customizeRequest` strongly suggests per-request behavior, making it easy to use incorrectly. The correct alternatives — `httpRequestCustomizer()` and `asyncHttpRequestCustomizer()` — already exist and run on every request, but there's no deprecation notice guiding users toward them.\n\n**Environment**\n\nMCP Java SDK (latest main branch). Affects both `HttpClientSseClientTransport` and `HttpClientStreamableHttpTransport`.\n\n**Steps to reproduce**\n\n```java\nvar transport = HttpClientSseClientTransport.builder(baseUri)\n .customizeRequest(builder -\u003e {\n // This runs ONCE at build time — token is frozen\n builder.header(\"Authorization\", \"Bearer \" + tokenProvider.getAccessToken());\n })\n .build();\n\n// Later: token expires, tokenProvider returns a new token\n// But all requests still carry the old token from build time\n```\n\n**Expected behavior**\n\nUsers should be guided toward `httpRequestCustomizer()` or `asyncHttpRequestCustomizer()` for dynamic headers. Ideally, `customizeRequest()` should be marked `@Deprecated` with clear Javadoc explaining the build-time-only semantics.\n\n**Real-world impact**\n\nWe encountered this in production where our MCP connector's OAuth token refresh was completely non-functional:\n\n1. Access token expires → server returns 401\n2. Connector successfully refreshes the token (new token stored)\n3. Connector retries with the same transport (no re-creation, since `McpAsyncClient` is already initialized)\n4. But `requestBuilder` still has the old token baked in from build time\n5. Retry sends the old expired token → 401 again → permanent failure\n\nSwitching from `customizeRequest()` to `httpRequestCustomizer()` resolved the issue.\n\n**Additional note**\n\nThe current Javadoc for `customizeRequest()` says *\"Customizes the HTTP client builder\"* which is also slightly misleading — it customizes the request builder, not the client builder (that's `customizeClient()`).\n\nA PR with the deprecation annotation and updated Javadoc has been submitted: #791","author":{"url":"https://github.com/gyeo009","@type":"Person","name":"gyeo009"},"datePublished":"2026-02-13T12:44:31.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/788/java-sdk/issues/788"}
| 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:603e5644-a9f5-69f2-9376-96749d67c5e8 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A9E4:38536E:1AD8594:2696BF0:6A60989C |
| html-safe-nonce | ed01533764d2aae08574f56a3016274b8ee3d3cac8cb92458936b9725eef3d41 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOUU0OjM4NTM2RToxQUQ4NTk0OjI2OTZCRjA6NkE2MDk4OUMiLCJ2aXNpdG9yX2lkIjoiODI2NjgwMTkzODk5NjE3Mjk1NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | fd171db87257e01a5bb1a67fbc05c1d136754768cc0d4f7cdce020cd10a743ae |
| hovercard-subject-tag | issue:3937009938 |
| 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/788/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dc4437cb9904436b2a11b860e97609b192544459f28e2407fa561fbdaa2c6903/modelcontextprotocol/java-sdk/issues/788 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dc4437cb9904436b2a11b860e97609b192544459f28e2407fa561fbdaa2c6903/modelcontextprotocol/java-sdk/issues/788 |
| og:image:alt | Bug description Builder.customizeRequest() in both HttpClientSseClientTransport and HttpClientStreamableHttpTransport executes its consumer once at build time, mutating the shared requestBuilder. A... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | gyeo009 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5142d23feb6a650085422edf60d68c93777dfa6c4b0c9151eb464d3e4969f618 |
| 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 | b2111e158bcd758ab9d0446577ae8f5dd78fcca8 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width