Skip to content

fix(server): match Accept header as media ranges#912

Open
devcrocod wants to merge 1 commit into
mainfrom
fix/accept-header-media-range-matching
Open

fix(server): match Accept header as media ranges#912
devcrocod wants to merge 1 commit into
mainfrom
fix/accept-header-media-range-matching

Conversation

@devcrocod

Copy link
Copy Markdown
Contributor

The header is now parsed into media ranges (parseHeaderValue + ContentType.match)

Breaking Changes

none

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Copilot AI review requested due to automatic review settings July 22, 2026 21:57

Copilot AI 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.

Pull request overview

This PR fixes Streamable HTTP server Accept header validation by parsing it into proper media ranges and matching via ContentType.match, ensuring wildcards and quality factors are handled correctly and preventing substring false-positives (e.g., application/jsonp no longer matching application/json) in the kotlin-sdk-server transport layer.

Changes:

  • Replace naive substring-based Accept matching with parseHeaderValue(...) + ContentType.match(...), honoring wildcards and q=0.
  • Add parameterized tests covering valid/invalid Accept headers for POST (JSON/SSE dual-accept gate) and GET (SSE accept gate).
  • Add a regression test ensuring an unparsable Accept header is rejected without delivering messages to the transport.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
kotlin-sdk-server/src/commonMain/kotlin/io/modelcontextprotocol/kotlin/sdk/server/StreamableHttpServerTransport.kt Implements media-range parsing for Accept checks to correctly enforce JSON/SSE accept requirements.
kotlin-sdk-server/src/jvmTest/kotlin/io/modelcontextprotocol/kotlin/sdk/server/StreamableHttpServerTransportTest.kt Adds coverage for wildcard, case/parameter variations, q=0, and unparsable Accept header behaviors for POST/GET.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants