Skip to content

Validate Content-Type on POST requests#304

Open
koic wants to merge 1 commit intomodelcontextprotocol:mainfrom
koic:validate_post_content_type
Open

Validate Content-Type on POST requests#304
koic wants to merge 1 commit intomodelcontextprotocol:mainfrom
koic:validate_post_content_type

Conversation

@koic
Copy link
Copy Markdown
Member

@koic koic commented Apr 8, 2026

Motivation and Context

The MCP Streamable HTTP specification requires POST request bodies to be JSON-RPC messages with Content-Type: application/json. The Ruby SDK did not validate Content-Type, accepting requests with any or no Content-Type. The Python SDK validates this and returns 415 Unsupported Media Type for non-JSON Content-Types.

How Has This Been Tested?

Added tests for Content-Type validation:

  • POST without Content-Type returns 415
  • POST with Content-Type: text/plain returns 415
  • POST with Content-Type: application/json; charset=utf-8 succeeds

Breaking Changes

POST requests without Content-Type: application/json now return 415 Unsupported Media Type. This is a spec compliance fix.

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

The MCP Streamable HTTP specification requires POST request bodies to
be JSON-RPC messages with `Content-Type: application/json`. The Ruby
SDK did not validate Content-Type, accepting requests with any or no
Content-Type. The Python SDK validates this and returns 415
Unsupported Media Type for non-JSON Content-Types.

## How Has This Been Tested?

Added tests for Content-Type validation:

- POST without Content-Type returns 415
- POST with `Content-Type: text/plain` returns 415
- POST with `Content-Type: application/json; charset=utf-8` succeeds

## Breaking Changes

POST requests without `Content-Type: application/json` now return
415 Unsupported Media Type. This is a spec compliance fix.
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.

1 participant