Skip to content

Conversation

@domdomegg
Copy link
Member

Summary

This PR relaxes the Accept header validation for servers with is_json_response_enabled=True. These servers only return application/json responses and never use SSE, so they should only require application/json in the Accept header rather than requiring both application/json and text/event-stream.

Changes

  • Modified _handle_post_request to conditionally validate the Accept header based on response mode
  • Extracted validation logic into a new _validate_accept_header method to reduce complexity
  • Added test coverage for JSON-only Accept header validation
  • Maintained backward compatibility - requests with both content types still work

Benefits

  • Easier to test JSON-only MCP servers with tools like curl
  • Follows the principle that servers should only require what they actually need to return
  • All existing tests pass

When is_json_response_enabled is True, servers only return application/json
responses and never use SSE. This change relaxes the Accept header validation
to only require application/json in this mode, rather than requiring both
application/json and text/event-stream.

This makes it easier to test JSON-only MCP servers with tools like curl,
which is useful when developing and debugging MCP servers.

For servers with is_json_response_enabled=False (SSE mode), the existing
requirement for both content types is maintained.
@domdomegg domdomegg requested a review from maxisbey October 20, 2025 19:06
Copy link
Contributor

@felixweinberger felixweinberger left a comment

Choose a reason for hiding this comment

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

Should we add tests that also cover the failure cases of this new validation?

E.g. missing Accept header and incorrect accept header (e.g. sending event/stream on a JSON server)

I think these should return 406

@felixweinberger felixweinberger added enhancement New feature or request needs more work Not ready to be merged yet, needs additional changes. labels Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request needs more work Not ready to be merged yet, needs additional changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants