Improve HTTP transport for DNS allowlists and stateless mode#327
Open
almirmcunhajr wants to merge 5 commits into
Open
Improve HTTP transport for DNS allowlists and stateless mode#327almirmcunhajr wants to merge 5 commits into
almirmcunhajr wants to merge 5 commits into
Conversation
Add allowed hosts support for DNS rebinding protection
Add stateless HTTP mode
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.
Description
This PR brings two related HTTP transport improvements to the local Notion MCP server:
--allowed-hosts, so unauthenticated HTTP deployments can explicitly permit additional hosts in the DNS rebinding allowlistPOST /mcprequest independently without persisting MCP sessionsTogether, these changes make HTTP deployments more flexible for reverse proxies, tunnels, and stateless gateway setups while keeping the default stateful behavior unchanged.
Changes in this PR:
--allowed-hosts <hosts>CLI parsing as a comma-separated, additive listallowedHostsandallowedOrigins--stateless-httpCLI parsing andENABLE_STATELESS_HTTPenvironment variable supportPOST /mcprequest when stateless mode is enabled--stateless-http --enable-token-passthroughmodePOST /mcphandler by extracting the stateful and stateless flows into dedicated functionsHow was this change tested?
Reproducible manual testing steps
Build the project:
Export a valid Notion token:
Start the server locally without
--allowed-hostsand without stateless mode:In another terminal, attempt to initialize an MCP session through
app.local, forcing it to resolve locally:Expected result: the request is rejected because
app.localis not in the DNS rebinding allowlist.Stop the server and restart it with the new host allowlist support:
Initialize an MCP session again through
app.local:Expected result: initialization succeeds and returns an MCP session id.
Stop the server and restart it in stateless mode with token passthrough enabled:
Call
initializewithout sending a Notion token:Expected result: the request is rejected with
401because stateless passthrough requires a Notion token on every request.Call
initializeagain, this time with a Notion token:Expected result: initialization succeeds and no
mcp-session-idheader is returned.Call a Notion-backed tool in a separate request, again sending the token:
Expected result: the tool call succeeds without any MCP session id.
Expected result:
405 Method not allowed.Expected result:
--allowed-hosts app.local, initialization throughapp.localis rejected--allowed-hosts app.local, initialization throughapp.localsucceeds401initializeandtools/callsucceed without using an MCP session idGET /mcpandDELETE /mcpare rejected in stateless mode