Skip to content

Ignore empty members of the Accept header - #616

Open
koic wants to merge 1 commit into
modelcontextprotocol:mainfrom
koic:ignore_empty_members_of_the_accept_header
Open

koic wants to merge 1 commit into
modelcontextprotocol:mainfrom
koic:ignore_empty_members_of_the_accept_header

Conversation

@koic

@koic koic commented Oct 15, 2026

Copy link
Copy Markdown
Member

Motivation and Context

An Accept header with an empty list member, such as application/json,,text/event-stream or one with a leading comma, makes the Streamable HTTP transport answer a POST with 500 and report a NoMethodError to the exception reporter, and raise out of a GET, although the required media types are listed (issue #609): parse_accept_header splits each member on ; and an empty member yields nothing to strip. RFC 9110 section 5.6.1.2 has a recipient parse and ignore a reasonable number of empty list elements, and the TypeScript and Python servers accept such a header, the one by substring checks and the other by stripping each member.

parse_accept_header now skips empty members, so the POST and GET checks see the media types that are there.

Fixes #609.

How Has This Been Tested?

Two new tests in test/mcp/server/transports/streamable_http_transport_test.rb, a POST with a doubled and with a leading comma and a GET with a leading comma. Against the previous library the POST test fails with a 500 and the GET test raises.

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

## Motivation and Context

An `Accept` header with an empty list member, such as `application/json,,text/event-stream` or one with
a leading comma, makes the Streamable HTTP transport answer a POST with 500 and report a `NoMethodError`
to the exception reporter, and raise out of a GET, although the required media types are listed
(issue modelcontextprotocol#609): `parse_accept_header` splits each member on `;` and an empty member yields nothing to strip.
RFC 9110 section 5.6.1.2 has a recipient parse and ignore a reasonable number of empty list elements,
and the TypeScript and Python servers accept such a header, the one by substring checks and the other by
stripping each member.

`parse_accept_header` now skips empty members, so the POST and GET checks see the media types that are there.

Fixes modelcontextprotocol#609.

## How Has This Been Tested?

Two new tests in `test/mcp/server/transports/streamable_http_transport_test.rb`, a POST with a doubled and
with a leading comma and a GET with a leading comma. Against the previous library the POST test fails with
a 500 and the GET test raises.

## Breaking Changes

None.

This branch has not been deployed

No deployments
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.

Empty members in the Accept header cause a 500

2 participants