Skip to content

fix: preserve configured Authorization in external MCP passthrough#3177

Merged
walker-tx merged 3 commits into
mainfrom
walker/ais-83-external-mcp-passthrough-overwrites-configured-authorization
Jun 3, 2026
Merged

fix: preserve configured Authorization in external MCP passthrough#3177
walker-tx merged 3 commits into
mainfrom
walker/ais-83-external-mcp-passthrough-overwrites-configured-authorization

Conversation

@walker-tx
Copy link
Copy Markdown
Member

@walker-tx walker-tx commented Jun 3, 2026

Summary

External MCP tools with requires_oauth=true forwarded the gating OAuth token (the token presented to the local Gram MCP server) upstream as Authorization: Bearer <token>, overwriting any Authorization header the user configured via env/user config in BuildHeaders (server/internal/externalmcp/config.go).

This broke setups where the local server is OAuth-guarded but the upstream MCP expects a static credential (e.g. Basic ...): the upstream rejected the forwarded gating token with 401.

Fix

Forward the gating OAuth token only when no explicit Authorization was already set from config. Config-provided Authorization now wins; the gating token remains the fallback when none is configured.

Tests

Added two TestBuildHeadersWithOAuthToken cases: config-provided and user-config-provided Authorization each take precedence over the OAuth token.

Resolves AIS-83.

🤖 Generated with Claude Code


Summary by cubic

Preserves the configured Authorization header in external MCP passthrough; only forwards the gating OAuth token if no Authorization is set. Prevents upstream 401s for MCPs that require static credentials (addresses AIS-83).

  • Bug Fixes
    • Updated BuildHeaders in server/internal/externalmcp/config.go to apply Bearer <oauthToken> only when Authorization isn’t set by system or user config.
    • Added tests ensuring both system- and user-configured Authorization take precedence over the OAuth token; added changeset patch entry for server.

Written for commit 87df9ec. Summary will update on new commits.

Review in cubic

External MCP tools with requires_oauth=true forwarded the gating OAuth
token (presented to the local Gram MCP server) upstream as
"Authorization: Bearer <token>", overwriting any Authorization header the
user configured via env/user config in BuildHeaders.

This broke setups where the local server is OAuth-guarded but the upstream
MCP expects a static credential (e.g. "Basic ..."): the upstream rejected
the forwarded gating token with 401.

Forward the gating OAuth token only when no explicit Authorization was
already set from config.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@walker-tx walker-tx requested a review from a team as a code owner June 3, 2026 18:20
@linear-code
Copy link
Copy Markdown

linear-code Bot commented Jun 3, 2026

AIS-83

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Jun 3, 2026

🦋 Changeset detected

Latest commit: 87df9ec

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
server Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 3, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
gram-docs-redirect Ready Ready Preview, Comment Jun 3, 2026 6:39pm

Request Review

@github-actions github-actions Bot added the preview Spawn a preview environment label Jun 3, 2026
@speakeasybot
Copy link
Copy Markdown
Collaborator

speakeasybot commented Jun 3, 2026

🚀 Preview Environment (PR #3177)

Preview URL: https://pr-3177.dev.getgram.ai

Component Status Details Updated (UTC)
✅ Database Ready Created and validated 2026-06-03 18:52:46.
✅ Images Available Container images ready 2026-06-03 18:52:30.

Gram Preview Bot

Comment thread server/internal/externalmcp/config_test.go Outdated
Copy link
Copy Markdown
Contributor

@subomi subomi left a comment

Choose a reason for hiding this comment

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

approved. with a non-blocking comment.

Address review nit: rename the case to "system config Authorization wins
over oauth token" so it is explicit and parallel to the user config case.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@walker-tx walker-tx enabled auto-merge June 3, 2026 18:39
@walker-tx walker-tx added this pull request to the merge queue Jun 3, 2026
Merged via the queue into main with commit 4856d7e Jun 3, 2026
33 checks passed
@walker-tx walker-tx deleted the walker/ais-83-external-mcp-passthrough-overwrites-configured-authorization branch June 3, 2026 18:53
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

preview Spawn a preview environment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants