Per-request Notion token passthrough for HTTP transport#315
Merged
Conversation
This was referenced Jun 17, 2026
Merged
81cb5b1 to
b96fad4
Compare
Contributor
Author
|
Reconciled with #320 (page-as-Markdown tools) to keep the stack conflict-free. This branch is now stacked on
Merge order: land #320 first, then this. (If #320 is dropped, this needs a one-line revert to put |
vshen-notion
approved these changes
Jun 17, 2026
eb9a0eb to
1be339c
Compare
In Streamable HTTP mode the Notion token was fixed at startup (NOTION_TOKEN / OPENAPI_MCP_HEADERS), locking one deployment to a single Notion integration. This adds an opt-in mode where each client supplies its own Notion integration token per connection, so one deployment can serve many integrations. - New `--enable-token-passthrough` flag / `ENABLE_TOKEN_PASSTHROUGH=true` env (default off; existing single-token behavior unchanged). - Token resolved per init request: dedicated `Notion-Token` header first, then `Authorization: Bearer ntn_...` when the server's own gateway auth is disabled, then the startup env token as fallback. - Token shape validated; bound per MCP session; never logged (redacted prefix only). Malformed explicit token returns 401. - MCPProxy/initProxy now accept explicit headers; env resolution is the default when none are passed. New token helper module is unit-tested; proxy tests cover the explicit header override. Full suite green; build passes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
b96fad4 to
7ea4a71
Compare
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
In Streamable HTTP transport, the Notion token is currently fixed at startup (
NOTION_TOKEN/OPENAPI_MCP_HEADERS), which locks one deployment to a single Notion integration. This came up from a self-hosting user who wants one deployed server to serve multiple Notion integrations by passing the key as a header.This PR adds an opt-in mode where each MCP client supplies its own Notion integration token per connection.
What changed
--enable-token-passthroughflag andENABLE_TOKEN_PASSTHROUGH=trueenv var (default off — existing single-token behavior is unchanged).initializerequest, in order:Notion-Tokenheader (preferred; coexists with the server's ownAuthorizationgateway auth),Authorization: Bearer ntn_…— only when the server's own bearer auth is disabled (--unsafe-disable-auth),MCPProxy/initProxynow accept explicit headers; env resolution stays the default when none are passed. Each token is bound to its MCP session.Security
ntn_/ legacysecret_prefixes), so a tenant's Notion token can never be confused with the server's gateway secret.ntn_…(NN chars)).Notion-Tokenreturns401instead of silently falling back.How was this change tested?
token.test.ts(14 tests) covers token shape-checking and header resolution precedence;proxy.test.tsextended for the explicit-header override. Full suite: 96 passing.npm run buildpasses.🤖 Generated with Claude Code