Skip to content

Conversation

@CodeWithKyrian
Copy link
Contributor

This PR introduces the ability to configure CORS headers in StreamableHttpTransport, addressing the opinionated and inflexible header implementation that was previously hardcoded.

Motivation and Context

The current CORS implementation was explicitly set with fixed headers, limiting flexibility for different deployment scenarios. As raised in #112, this approach hid security settings and provided no way to adapt them when using reverse proxies like nginx or when specific CORS policies are required.

What's Changed

  • Added optional corsHeaders parameter to StreamableHttpTransport constructor
  • Secure default CORS headers are merged with any provided custom headers

Breaking Changes

Minor: The logger parameter has shifted one position in the constructor signature.
If you’re passing it positionally, you’ll now need to include the new corsHeaders array parameter before it. Named arguments or cases where logger is omitted remain unaffected.

This change aligns the parameter order with how logger is handled consistently across the SDK.

@chr-hertel
Copy link
Member

Thanks for jumping on that @CodeWithKyrian 👍

@soyuka does that solve the issue for you?

Copy link
Contributor

@soyuka soyuka left a comment

Choose a reason for hiding this comment

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

minor comment

private readonly ResponseFactoryInterface $responseFactory,
private readonly StreamFactoryInterface $streamFactory,
array $corsHeaders = [],
private readonly LoggerInterface $logger = new NullLogger(),
Copy link
Contributor

Choose a reason for hiding this comment

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

any reason you don't set corsHeaders at the end to avoid breaking current implementations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, wanted to keep things consistent with how the logger is passed across the SDK ie it’s always the last argument, and I think that consistency makes things more predictable overall. Since we haven’t tagged a release yet, this kind of breaking change is still fair game (for now).

Copy link
Member

Choose a reason for hiding this comment

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

yup agree, we'd need to tag soon and care more than tho

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure!

Copy link
Member

@chr-hertel chr-hertel left a comment

Choose a reason for hiding this comment

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

needs a rebase tho

@CodeWithKyrian CodeWithKyrian force-pushed the feat/make-cors-headers-configurable branch from e115158 to 78d1509 Compare October 26, 2025 22:57
@CodeWithKyrian CodeWithKyrian merged commit 48a19b9 into modelcontextprotocol:main Oct 26, 2025
10 checks passed
@CodeWithKyrian CodeWithKyrian deleted the feat/make-cors-headers-configurable branch October 26, 2025 22:58
chr-hertel added a commit to symfony/ai that referenced this pull request Oct 27, 2025
…ertel)

This PR was merged into the main branch.

Discussion
----------

[MCP Bundle] Fix transport arguments of McpController

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| Docs?         | no
| Issues        |
| License       | MIT

Follows modelcontextprotocol/php-sdk#118

Commits
-------

ee141ea Fix transport arguments of McpController
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.

3 participants