Skip to content

fix(mcpproxy): parse JSON content types with parameters - #2306

Open
immanuwell wants to merge 1 commit into
envoyproxy:mainfrom
immanuwell:fix/mcpproxy-json-content-type-params
Open

fix(mcpproxy): parse JSON content types with parameters#2306
immanuwell wants to merge 1 commit into
envoyproxy:mainfrom
immanuwell:fix/mcpproxy-json-content-type-params

Conversation

@immanuwell

Copy link
Copy Markdown
Contributor

Description

mcpproxy only treated the exact header application/json as JSON. If a backend returns application/json; charset=utf-8, it kinda falls into the SSE path by mistake. That can skip JSON-RPC decoding, miss resources/read URI rewriting, and proxyResponseBody can panic when no session is present.

This parses the media type instead, so JSON responses with params still use the JSON path. Pretty small fix, same behavior for existing bare application/json and text/event-stream cases.

Related Issues/PRs (if applicable)

Related to #2218
Related PR: #2229

Special notes for reviewers (if applicable)

Repro:

  1. Return Content-Type: application/json; charset=utf-8 from an MCP backend with a valid JSON-RPC body.
  2. Hit resources/read, or the GET notification path.
  3. Before this patch, the proxy takes the SSE path. resources/read stops rewriting downstream URIs, and proxyResponseBody can panic if no session is present.
  4. With this patch, the same responses decode as JSON like normal.

@immanuwell
immanuwell requested a review from a team as a code owner June 30, 2026 18:11
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jun 30, 2026
Signed-off-by: immanuwell <pchpr.00@list.ru>
@immanuwell
immanuwell force-pushed the fix/mcpproxy-json-content-type-params branch from 3b3d10e to 1c3b9b3 Compare June 30, 2026 18:45
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 84.89%. Comparing base (53e58b4) to head (1c3b9b3).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2306   +/-   ##
=======================================
  Coverage   84.88%   84.89%           
=======================================
  Files         144      145    +1     
  Lines       21255    21263    +8     
=======================================
+ Hits        18043    18051    +8     
  Misses       2132     2132           
  Partials     1080     1080           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@missBerg missBerg added the area/mcp MCP proxy, MCPRoute, and MCP spec conformance label Jul 13, 2026

@Hritik003 Hritik003 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, 1 minor comment

Comment on lines +13 to +16

func hasMediaType(header http.Header, want string) bool {
got, _, err := mime.ParseMediaType(header.Get("Content-Type"))
if err == nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can we add this helper function inside the handler file itself?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/mcp MCP proxy, MCPRoute, and MCP spec conformance size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants