feat: add --corsAddAllowedHeader CLI flag#64
Merged
Conversation
Lets the CLI append header names to Access-Control-Allow-Headers without
forcing users to drop down to the programmatic API. Defaults are preserved.
The motivating case is `--apiKey` behind a browser: the proxy expects the
secret in `X-API-Key`, but that header is not in the default
Access-Control-Allow-Headers list, so the browser preflight rejects it and
the request never reaches the proxy. With `--corsAddAllowedHeader X-API-Key`
the preflight succeeds and the apiKey gate works as advertised.
npx mcp-proxy --port 8080 --apiKey secret \
--corsAddAllowedHeader X-API-Key \
-- node server.js
For broader CORS overrides (origin allowlist, wildcard headers, disabling
CORS) the programmatic `cors` option remains the right surface — this flag
is intentionally narrow.
|
🎉 This PR is included in version 6.5.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Author
|
@punkpeye thanks for merging. By any chance don't you think this should be a default (accept CORS header) when --apiKey is used? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a single
--corsAddAllowedHeaderCLI flag that appends header names toAccess-Control-Allow-Headers(defaults preserved). Repeatable.Motivation
When
mcp-proxyis started with--apiKey, the proxy expects the secret in theX-API-Keyheader.Browser-based apps (e.g. chat UIs) that support frontend-fetched streamable HTTP MCPs issue a CORS preflight for that header, and because
X-API-Keyis not in the defaultAccess-Control-Allow-Headerslist, the preflight is rejected. The--apiKeygate is therefore unreachable from a browser-hosted client.The library already exposes a programmatic
cors.allowedHeadersoption that solves this, but it requires users to abandon thenpx mcp-proxy ...one-liner and write a small Node wrapper. The README's "Common Use Cases" section explicitly calls this out as a known browser CORS friction point.What this changes
--corsAddAllowedHeader <name>(yargsarray: true, repeatable). Internally buildscors: { allowedHeaders: [...defaults, ...added] }and passes it tostartHTTPServer.src/startHTTPServer.ts.Example
```bash
npx mcp-proxy --port 8080 --apiKey secret \
--corsAddAllowedHeader X-API-Key \
-- npx -y @modelcontextprotocol/server-filesystem /srv
```
Test plan
Notes
Perhaps we should also make this a default (always accept X-API-Key when --apiKey is given), but not sure the maintainer's opinion on the security implications.