-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat(auth): add Protected Resource Metadata endpoint #2698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
d40c753
add initial generic authService
duwenxin99 110bb28
fix lint
duwenxin99 90d8fe5
update getClaimsFromHeader
duwenxin99 5ce12ac
move changes from metadat
duwenxin99 a1bc417
Restore authService changes to mcp-as
duwenxin99 2a7a91b
Make AuthorizationServerUrl required and always verify signatures
duwenxin99 e639be8
nit
duwenxin99 3200622
resolve comments
duwenxin99 f452e12
remove https check
duwenxin99 22b1810
add mcp auth specific handling
duwenxin99 4e63fcc
add test
duwenxin99 0ea0f90
remove ports
duwenxin99 53e5236
fix test
duwenxin99 8f82b2e
update tests
duwenxin99 b2a5cd7
add header
duwenxin99 dafa400
add initial generic authService
duwenxin99 46dc97b
rebase
duwenxin99 2799ff2
update authUrl to authorizationServer
duwenxin99 bc5d9a2
update server test
duwenxin99 5e15dcb
update instruction on cloud run token
duwenxin99 29e1e31
Apply suggestions from code review
duwenxin99 878bac2
resolve comment
duwenxin99 ea93028
fix merge error
duwenxin99 c78d11d
fix rebase
duwenxin99 49489ac
Merge branch 'main' into metadata
Yuan325 155fac3
Merge branch 'main' into metadata
duwenxin99 7a2bb29
Merge branch 'main' into metadata
duwenxin99 d620c55
Merge branch 'main' into metadata
duwenxin99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
121 changes: 121 additions & 0 deletions
121
docs/en/documentation/configuration/toolbox_mcp_auth.md
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| --- | ||
| title: "Toolbox with MCP Authorization" | ||
| type: docs | ||
| weight: 4 | ||
| description: > | ||
| How to set up and configure Toolbox with [MCP Authorization](https://modelcontextprotocol.io/specification/2025-11-25/basic/authorization). | ||
| --- | ||
|
|
||
| ## Overview | ||
|
|
||
| Toolbox supports integration with Model Context Protocol (MCP) clients by acting as a Resource Server that implements OAuth 2.1 authorization. This enables Toolbox to validate JWT-based Bearer tokens before processing requests for resources or tool executions. | ||
|
|
||
| This guide details the specific configuration steps required to deploy Toolbox with MCP Auth enabled. | ||
|
|
||
| ## Step 1: Configure the `generic` Auth Service | ||
|
|
||
| Update your `tools.yaml` file to use a `generic` authorization service with `mcpEnabled` set to `true`. This instructs Toolbox to intercept requests on the `/mcp` routes and validate Bearer tokens using the JWKS (JSON Web Key Set) fetched from your OIDC provider endpoint (`authorizationServer`). | ||
|
|
||
| ```yaml | ||
| kind: authServices | ||
| name: my-mcp-auth | ||
| type: generic | ||
| mcpEnabled: true | ||
| authorizationServer: "https://accounts.google.com" # Your authorization server URL | ||
| audience: "your-mcp-audience" # Matches the `aud` claim in the JWT | ||
| scopesRequired: | ||
| - "mcp:tools" | ||
| ``` | ||
|
|
||
| When `mcpEnabled` is true, Toolbox also provisions the `/.well-known/oauth-protected-resource` Protected Resource Metadata (PRM) endpoint automatically using the `authorizationServer`. | ||
|
|
||
| ## Step 2: Deployment | ||
|
|
||
| Deploying Toolbox with MCP auth requires defining the `TOOLBOX_URL` that the deployed service will use, as this URL must be included as the `resource` field in the PRM returned to the client. | ||
|
|
||
| You can set this either through the `TOOLBOX_URL` environment variable or the `--toolbox-url` command-line flag during deployment. | ||
|
|
||
| ### Local Deployment | ||
|
|
||
| To run Toolbox locally with MCP auth enabled, simply export the `TOOLBOX_URL` referencing your local port before running the binary: | ||
|
|
||
| ```bash | ||
| export TOOLBOX_URL="http://127.0.0.1:5000" | ||
| ./toolbox --tools-file tools.yaml | ||
| ``` | ||
|
|
||
| If you prefer to use the `--toolbox-url` flag explicitly: | ||
|
|
||
| ```bash | ||
| ./toolbox --tools-file tools.yaml --toolbox-url "http://127.0.0.1:5000" | ||
| ``` | ||
|
|
||
| ### Cloud Run Deployment | ||
|
|
||
| ```bash | ||
| export IMAGE="us-central1-docker.pkg.dev/database-toolbox/toolbox/toolbox:latest" | ||
|
|
||
| # Pass your target Cloud Run URL to the `--toolbox-url` flag | ||
| gcloud run deploy toolbox \ | ||
| --image $IMAGE \ | ||
| --service-account toolbox-identity \ | ||
| --region us-central1 \ | ||
| --set-secrets "/app/tools.yaml=tools:latest" \ | ||
| --args="--tools-file=/app/tools.yaml","--address=0.0.0.0","--port=8080","--toolbox-url=${CLOUD_RUN_TOOLBOX_URL}" | ||
| ``` | ||
|
|
||
| ### Alternative: Manual PRM File Override | ||
|
|
||
| If you strictly need to define your own Protected Resource Metadata instead of auto-generating it from the `AuthService` config, you can use the `--mcp-prm-file <path>` flag. | ||
|
|
||
| 1. Create a `prm.json` containing the RFC-9207 compliant metadata. Note that the `resource` field must match the `TOOLBOX_URL`: | ||
| ```json | ||
| { | ||
| "resource": "https://toolbox-service-123456789-uc.a.run.app", | ||
| "authorization_servers": ["https://your-auth-server.example.com"], | ||
| "scopes_supported": ["mcp:tools"], | ||
| "bearer_methods_supported": ["header"] | ||
| } | ||
| ``` | ||
| 2. Set the `--mcp-prm-file` flag to the path of the PRM file. | ||
|
|
||
| - If you are using local deployment, you can just provide the path to the file directly: | ||
| ```bash | ||
| ./toolbox --tools-file tools.yaml --mcp-prm-file prm.json | ||
| ``` | ||
| - If you are using Cloud Run, upload it to GCP Secret Manager and Attach the secret to the Cloud Run deployment and provide the flag. | ||
| ```bash | ||
| gcloud secrets create prm_file --data-file=prm.json | ||
|
|
||
| gcloud run deploy toolbox \ | ||
| # ... previous args | ||
| --set-secrets "/app/tools.yaml=tools:latest,/app/prm.json=prm_file:latest" \ | ||
| --args="--tools-file=/app/tools.yaml","--mcp-prm-file=/app/prm.json","--port=8080" | ||
| ``` | ||
|
|
||
| ## Step 3: Connecting to the Secure MCP Endpoint | ||
|
|
||
| Once the Cloud Run instance is deployed, your MCP client must obtain a valid JWT token from your authorization server (the `authorizationServer` in `tools.yaml`). | ||
|
|
||
| The client should provide this JWT via the standard HTTP `Authorization` header when connecting to the Streamable HTTP or SSE endpoint (`/mcp`): | ||
|
|
||
| ```bash | ||
| { | ||
| "mcpServers": { | ||
| "toolbox-secure": { | ||
| "type": "http", | ||
| "url": "https://toolbox-service-123456789-uc.a.run.app/mcp", | ||
| "headers": { | ||
| "Authorization": "Bearer <your-jwt-access-token>" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
| Important: The token provided in the Authorization header must be a JWT token (issued by the auth server you configured previously), not a Google Cloud Run access token. | ||
|
|
||
| Toolbox will intercept incoming connections, fetch the latest JWKS from your authorizationServer, and validate that the aud (audience), signature, and scopes on the JWT match the requirements defined by your mcpEnabled auth service. | ||
|
|
||
| If your Cloud Run service also requires IAM authentication, you must pass the Cloud Run identity token using [Cloud Run's alternate auth header][cloud-run-alternate-auth-header] to avoid conflicting with Toolbox's internal authentication. | ||
|
|
||
| [cloud-run-alternate-auth-header]: https://docs.cloud.google.com/run/docs/authenticating/service-to-service#acquire-token |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.