Skip to content

feat(MCP): OAuth 2.0 support for HTTP transport#7692

Open
khvn26 wants to merge 1 commit into
mainfrom
feat/mcp-oauth
Open

feat(MCP): OAuth 2.0 support for HTTP transport#7692
khvn26 wants to merge 1 commit into
mainfrom
feat/mcp-oauth

Conversation

@khvn26
Copy link
Copy Markdown
Member

@khvn26 khvn26 commented Jun 2, 2026

Thanks for submitting a PR! Please check the boxes below:

  • I have read the Contributing Guide.
  • I have added information to docs/ if required so people know about the feature.
  • I have filled in the "Changes" section below.
  • I have filled in the "How did you test this code" section below.

Changes

Closes Flagsmith/flagsmith-private#147

Adds OAuth 2.0 support for the MCP server's HTTP transport, as a pass-through resource server — the API stays the authorisation server and sole validator.

  • FlagsmithResourceAuth: serves Protected Resource Metadata (RFC 9728) advertising the Flagsmith AS and the mcp scope, and returns 401 + WWW-Authenticate when a request carries no credential, so MCP clients can discover and complete the OAuth flow.
  • Any-scheme gate: a request with any Authorization header, Bearer OAuth token or Api-Key, is accepted and forwarded upstream. No introspection.
  • OAuth discovery is the credential fallback: it is wired only when transport=http and no static FLAGSMITH_API_TOKEN is configured. stdio, a static token, and a forwarded --header all stay pure pass-through.
  • New MCP_SERVER_URL setting for the public resource URL advertised in the metadata.

How did you test this code?

  • make test (100% coverage), make lint, make typecheck — all green.
  • Manually against SaaS:
    • HTTP, no token, no credential → 401 + WWW-Authenticate pointing at /.well-known/oauth-protected-resource/mcp.
    • PRM document advertises https://api.flagsmith.com as the AS and the mcp scope.
    • Api-Key header over HTTP → forwarded → real data (gate is scheme-agnostic).
    • Static token / stdio → no PRM served (pass-through).
    • Full browser OAuth flow via Claude Code (claude mcp add --transport http …/mcp → log in at Flagsmith → authenticated tool calls).

Pass-through OAuth 2.0 protected resource for HTTP transport: serves
RFC 9728 metadata, 401 + WWW-Authenticate on missing credential, any-scheme
Authorization forwarded to the API. Tests migrated to respx.

beep boop
@khvn26 khvn26 requested a review from a team as a code owner June 2, 2026 18:52
@khvn26 khvn26 requested review from germangarces and removed request for a team June 2, 2026 18:52
@vercel
Copy link
Copy Markdown

vercel Bot commented Jun 2, 2026

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

3 Skipped Deployments
Project Deployment Actions Updated (UTC)
docs Ignored Ignored Jun 2, 2026 6:52pm
flagsmith-frontend-preview Ignored Ignored Jun 2, 2026 6:52pm
flagsmith-frontend-staging Ignored Ignored Jun 2, 2026 6:52pm

Request Review

@github-actions github-actions Bot added the feature New feature or request label Jun 2, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 2, 2026

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-e2e:pr-7692 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api-test:pr-7692 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-frontend:pr-7692 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-api:pr-7692 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-7692 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-7692 Finished ✅ Results

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 2, 2026

Playwright Test Results (oss - depot-ubuntu-latest-arm-16)

passed  1 passed

Details

stats  1 test across 1 suite
duration  44.8 seconds
commit  65657c2
info  🔄 Run: #17208 (attempt 1)

Playwright Test Results (oss - depot-ubuntu-latest-16)

passed  2 passed

Details

stats  2 tests across 2 suites
duration  40.9 seconds
commit  65657c2
info  🔄 Run: #17208 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-arm-16)

passed  2 passed

Details

stats  2 tests across 2 suites
duration  44.9 seconds
commit  65657c2
info  🔄 Run: #17208 (attempt 1)

Playwright Test Results (private-cloud - depot-ubuntu-latest-16)

passed  3 passed

Details

stats  3 tests across 3 suites
duration  37.6 seconds
commit  65657c2
info  🔄 Run: #17208 (attempt 1)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 2, 2026

Visual Regression

19 screenshots compared. See report for details.
View full report

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants