Repository navigation
fix(mcp): accept multi-org session tokens when the request names the org - #8414
Conversation
`superset mcp tools/call-tool --plugin …` failed from every Superset terminal with "OAuth token missing organizationId claim". In a Superset terminal the CLI sends the host-service's session JWT, which carries an `organizationIds` list, not the single `organizationId` claim that resolveMcpContext required. The tRPC API already accepts the same token by picking the org from the x-superset-organization-id header. The MCP auth now does the same: a token's own organizationId still wins; otherwise the header picks one of the token's organizationIds (or the only one), and the existing membership check still runs. The CLI sends the header for plugin MCP calls.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to The change appears mergeable after normal checks. Deployed CLI-to-server behavior has not been validated. Pre-merge checks ·
|
🧹 Preview Cleanup CompleteThe following preview resources have been cleaned up:
Thank you for your contribution! 🎉 |
|
| requestInit: { | ||
| headers: pluginMcpHeaders(auth.bearer, auth.organizationId), | ||
| }, |
There was a problem hiding this comment.
Dropped headers would escape tests
The new tests call tokenOrganizationId directly, so they would still pass if connectPluginMcp stopped sending ORGANIZATION_HEADER. That could break plugin commands in Superset terminals without a test failure.
Add a test that captures requests from connectPluginMcp and checks both Authorization and ORGANIZATION_HEADER during connection and a tool call.
Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/cli/src/lib/plugins/mcp-client.ts
Line: 50-52
Comment:
**Dropped headers would escape tests**
The new tests call `tokenOrganizationId` directly, so they would still pass if `connectPluginMcp` stopped sending `ORGANIZATION_HEADER`. That could break plugin commands in Superset terminals without a test failure.
Add a test that captures requests from `connectPluginMcp` and checks both `Authorization` and `ORGANIZATION_HEADER` during connection and a tool call.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.…s for multi-org users (#8450) Every Superset MCP server an agent loads (Linear, PostHog, Neon, Slack, ...) gets its auth from `superset auth mcp-headers`. Since #8274 (Oct 10) the CLI in a Superset terminal sends the host-service session JWT, which carries an `organizationIds` list instead of one `organizationId` claim. From then on every agent MCP connection failed with "OAuth token missing organizationId claim". #8414 (Oct 12) taught the MCP auth to accept that token when the request names the org in x-superset-organization-id, and made `superset mcp` send it. The headers helper was left out, so single-org users recovered and anyone in two or more orgs still gets "Token covers 2 organizations; name one in the x-superset-organization-id header". The helper now builds its headers with the same pluginMcpHeaders as the `superset mcp` commands, naming the terminal's organization (SUPERSET_ORGANIZATION_ID) or the active one from config. Checked against api.superset.sh with a two-org session token: Authorization alone is rejected, and with the org header the PostHog plugin lists its tools.
Problem
superset mcp tools --plugin <name>andsuperset mcp call-tool --plugin <name>fail from every Superset terminal, for every plugin:In a Superset terminal the CLI sends the host-service's token instead of its own login (
resolveAuth→readHostApiToken). That token is a better-auth session JWT, and it lists every org the user belongs to:resolveMcpContext→resolveOAuthonly accepted a singleorganizationIdclaim. The tRPC API accepts the same token becausejwtProcedurepicks the org from thex-superset-organization-idheader. The same command works from a plain terminal, where the CLI uses its own single-org OAuth token.Fix
packages/mcp:tokenOrganizationIdpicks the session org.organizationId, that wins, as before.x-superset-organization-idheader picks one of the token'sorganizationIds.packages/cli: plugin MCP calls sendx-superset-organization-id, taken fromresolveOrganizationId(config)(SUPERSET_ORGANIZATION_IDin a Superset terminal).The header is optional, so this is backward compatible. OAuth clients and API keys behave as before. Released CLIs that don't send the header still get a 401 for multi-org tokens, now with a message that says what to send.
Validation
Added
packages/mcp/src/token-organization.test.ts(6 cases) and ran it locally: 6 pass. Note:packages/mcphas notestscript, so turbo CI does not run this package's tests.Decoded the claims of a live host-service token to confirm the shape above.
Confirmed the failure from a Superset terminal, and the same call succeeding with the CLI's own login (
list_eventson google-calendar).End to end against a local API (this branch, worktree Neon branch, not production). I minted a session JWT through the local better-auth for a dev user in 2 orgs. It has the same shape as the prod host token:
organizationIdsonly, iss/aud = API. Then I sent it in an MCPinitializeto/mcpand/mcp/plugins/superset/google-calendar:auth.ts)OAuth token missing organizationId claim/mcp: 200 initialize result; plugin route: gets past auth to the plugin lookup (404, because the dev user hasn't installed the plugin)Token covers 2 organizations; name one in the x-superset-organization-id headerToken does not cover organization …The CLI sends the header. From a Superset terminal, pointed at a stub server,
mcp tools --plugin google-calendarsentAuthorization: Bearer <host JWT>plusx-superset-organization-id: <terminal org>.Not verified against a deployed API.
typecheckinpackages/mcpandpackages/clireports errors only in the untouchedpackages/trpc/src/trpc.ts(better-auth typings). A cleanorigin/maincheckout fails the same way in this environment.Summary by cubic
Fixes
superset mcp tools --pluginandsuperset mcp call-tool --pluginfailing from Superset terminals with "OAuth token missing organizationId claim". The CLI now sends thex-superset-organization-idheader for plugin calls, and the MCP server accepts session tokens that carry anorganizationIdsarray by resolving the org from that header (or the single org when no header is sent).Details
organizationIdclaim still takes precedence; otherwise the header picks one of the token'sorganizationIds.Written for commit d9abe38. Summary will update on new commits.
Summary by CodeRabbit