Skip to content

fix(streamable_http): allow Content-Type header override#2383

Open
haroldfabla2-hue wants to merge 1 commit intomodelcontextprotocol:mainfrom
haroldfabla2-hue:fix/2375-hardcoded-content-type-override
Open

fix(streamable_http): allow Content-Type header override#2383
haroldfabla2-hue wants to merge 1 commit intomodelcontextprotocol:mainfrom
haroldfabla2-hue:fix/2375-hardcoded-content-type-override

Conversation

@haroldfabla2-hue
Copy link
Copy Markdown

Summary

Allow and to accept a custom parameter instead of hardcoding application/json. This enables clients to override the Content-Type header to include custom charsets (e.g. application/json; charset=utf-8) or other attributes required by specific server implementations.

Changes

  • ****: Added parameter and stored it as
  • ****: Changed hardcoded "content-type": "application/json" to use self.content_type
  • ****: Added parameter, passed through to
  • Added test file with 3 test cases

Fixes

Fixes #2375

Example usage

# Before (hardcoded, no way to override):
transport = StreamableHTTPTransport(url)

# After (custom charset supported):
transport = StreamableHTTPTransport(
    url,
    content_type="application/json; charset=utf-8",
)

# Or via the client helper:
async with streamable_http_client(
    url,
    content_type="application/json; charset=utf-8",
) as (read, write):
    ...

Allow StreamableHTTPTransport and streamable_http_client to accept a
custom content_type parameter instead of hardcoding 'application/json'.
This enables clients to override the Content-Type header to include
custom charsets (e.g. 'application/json; charset=utf-8') or other
attributes required by specific server implementations.

Fixes: modelcontextprotocol#2375
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.

Harcoded Content-Type in the client cannot be overriden

1 participant