fix(mcp): relax Accept header validation for broader client compatibility#1799
Open
ctonneslan wants to merge 2 commits intohonojs:mainfrom
Open
fix(mcp): relax Accept header validation for broader client compatibility#1799ctonneslan wants to merge 2 commits intohonojs:mainfrom
ctonneslan wants to merge 2 commits intohonojs:mainfrom
Conversation
…lity The strict Accept header check in handlePostRequest rejects requests from widely-used MCP clients (Gemini CLI, Java MCP SDK, Open WebUI, curl) that don't send both application/json and text/event-stream. Apply Postel's Law: accept requests that include either application/json OR text/event-stream OR */*. Only reject when the client explicitly accepts neither. Default to */* when no Accept header is present. Fixes honojs#1773
🦋 Changeset detectedLatest commit: 9742e5e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Member
|
@MathurAditya724 Can you also take a look at this? |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1799 +/- ##
=======================================
Coverage 91.73% 91.73%
=======================================
Files 113 113
Lines 3785 3785
Branches 957 958 +1
=======================================
Hits 3472 3472
Misses 281 281
Partials 32 32
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Relaxes the strict Accept header validation in the Streamable HTTP transport's
handlePostRequestto accommodate MCP clients that don't send bothapplication/jsonandtext/event-stream.Before: Requests must include both
application/jsonANDtext/event-streamin the Accept header, or get a 406.After: Requests are accepted if they include
application/jsonORtext/event-streamOR*/*. Missing Accept header defaults to*/*. Only rejects when the client explicitly accepts neither.Problem
The strict check breaks compatibility with several widely-used MCP clients:
Accept: application/jsonAccept: text/event-streamtext/event-streamin validation requests*/*or no Accept headerThis is a known pain point across the MCP ecosystem (see linked issues in #1773).
Changes
packages/mcp/src/streamable-http.ts: Updated Accept header validation to use Postel's Law (be liberal in what you accept)packages/mcp/src/streamable-http.test.ts: Updated existing test + added 4 new tests forapplication/jsononly,text/event-streamonly,*/*, and missing Accept headerTest plan
application/jsonAccept — acceptedtext/event-streamAccept — accepted*/*Accept — acceptedtext/plainAccept — rejected with 406Fixes #1773