Skip to content

Fix: Remove charset=utf-8 from Content-Type: application/json in HTTP transport#1528

Draft
jayaraman-venkatesan wants to merge 1 commit intomodelcontextprotocol:mainfrom
jayaraman-venkatesan:fix/content-type-charset-utf8
Draft

Fix: Remove charset=utf-8 from Content-Type: application/json in HTTP transport#1528
jayaraman-venkatesan wants to merge 1 commit intomodelcontextprotocol:mainfrom
jayaraman-venkatesan:fix/content-type-charset-utf8

Conversation

@jayaraman-venkatesan
Copy link
Copy Markdown
Contributor

Fixes #1527

Summary

The HttpClientTransport was sending Content-Type: application/json; charset=utf-8 on all POST requests. Per RFC 8259 §11 and the IANA registration for application/json, charset is not a defined parameter for application/json — JSON is always Unicode. Strict servers such as GitHub Copilot's MCP endpoint (https://api.githubcopilot.com/mcp) reject the extra parameter with HTTP 415 Unsupported Media Type, making it impossible to connect without a custom DelegatingHandler workaround.

Changes

src/ModelContextProtocol.Core/Client/McpHttpClient.cs

  • Removed CharSet = "utf-8" from s_applicationJsonContentType — fixes the non-NET path and ClientOAuthProvider which shares the constant.
// Before
internal static readonly MediaTypeHeaderValue s_applicationJsonContentType = new("application/json") { CharSet = "utf-8" };
// ...
return JsonContent.Create(message, McpJsonUtilities.JsonContext.Default.JsonRpcMessage);

// After
internal static readonly MediaTypeHeaderValue s_applicationJsonContentType = new("application/json");
// ...
return JsonContent.Create(message, McpJsonUtilities.JsonContext.Default.JsonRpcMessage, s_applicationJsonContentType);

Tests

Two new tests added to HttpClientTransportTests.cs using a shared StrictJsonContentTypeHandler mock that mirrors GitHub Copilot's behavior — returns 200 only for bare application/json, otherwise 415:

References

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HttpClientTransport sends Content-Type: application/json; charset=utf-8`, which is rejected by spec-strict MCP servers (e.g. GitHub Copilot returns 415)

1 participant