|
| 1 | +--- |
| 2 | +title: "Toolbox with MCP Authorization" |
| 3 | +type: docs |
| 4 | +weight: 4 |
| 5 | +description: > |
| 6 | + How to set up and configure Toolbox with [MCP Authorization](https://modelcontextprotocol.io/specification/2025-11-25/basic/authorization). |
| 7 | +--- |
| 8 | + |
| 9 | +## Overview |
| 10 | + |
| 11 | +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. |
| 12 | + |
| 13 | +This guide details the specific configuration steps required to deploy Toolbox with MCP Auth enabled. |
| 14 | + |
| 15 | +## Step 1: Configure the `generic` Auth Service |
| 16 | + |
| 17 | +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`). |
| 18 | + |
| 19 | +```yaml |
| 20 | +kind: authServices |
| 21 | +name: my-mcp-auth |
| 22 | +type: generic |
| 23 | +mcpEnabled: true |
| 24 | +authorizationServer: "https://accounts.google.com" # Your authorization server URL |
| 25 | +audience: "your-mcp-audience" # Matches the `aud` claim in the JWT |
| 26 | +scopesRequired: |
| 27 | + - "mcp:tools" |
| 28 | +``` |
| 29 | +
|
| 30 | +When `mcpEnabled` is true, Toolbox also provisions the `/.well-known/oauth-protected-resource` Protected Resource Metadata (PRM) endpoint automatically using the `authorizationServer`. |
| 31 | + |
| 32 | +## Step 2: Deployment |
| 33 | + |
| 34 | +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. |
| 35 | + |
| 36 | +You can set this either through the `TOOLBOX_URL` environment variable or the `--toolbox-url` command-line flag during deployment. |
| 37 | + |
| 38 | +### Local Deployment |
| 39 | + |
| 40 | +To run Toolbox locally with MCP auth enabled, simply export the `TOOLBOX_URL` referencing your local port before running the binary: |
| 41 | + |
| 42 | +```bash |
| 43 | +export TOOLBOX_URL="http://127.0.0.1:5000" |
| 44 | +./toolbox --tools-file tools.yaml |
| 45 | +``` |
| 46 | + |
| 47 | +If you prefer to use the `--toolbox-url` flag explicitly: |
| 48 | + |
| 49 | +```bash |
| 50 | +./toolbox --tools-file tools.yaml --toolbox-url "http://127.0.0.1:5000" |
| 51 | +``` |
| 52 | + |
| 53 | +### Cloud Run Deployment |
| 54 | + |
| 55 | +```bash |
| 56 | +export IMAGE="us-central1-docker.pkg.dev/database-toolbox/toolbox/toolbox:latest" |
| 57 | +
|
| 58 | +# Pass your target Cloud Run URL to the `--toolbox-url` flag |
| 59 | +gcloud run deploy toolbox \ |
| 60 | + --image $IMAGE \ |
| 61 | + --service-account toolbox-identity \ |
| 62 | + --region us-central1 \ |
| 63 | + --set-secrets "/app/tools.yaml=tools:latest" \ |
| 64 | + --args="--tools-file=/app/tools.yaml","--address=0.0.0.0","--port=8080","--toolbox-url=${CLOUD_RUN_TOOLBOX_URL}" |
| 65 | +``` |
| 66 | + |
| 67 | +### Alternative: Manual PRM File Override |
| 68 | + |
| 69 | +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. |
| 70 | + |
| 71 | +1. Create a `prm.json` containing the RFC-9207 compliant metadata. Note that the `resource` field must match the `TOOLBOX_URL`: |
| 72 | + ```json |
| 73 | + { |
| 74 | + "resource": "https://toolbox-service-123456789-uc.a.run.app", |
| 75 | + "authorization_servers": ["https://your-auth-server.example.com"], |
| 76 | + "scopes_supported": ["mcp:tools"], |
| 77 | + "bearer_methods_supported": ["header"] |
| 78 | + } |
| 79 | + ``` |
| 80 | +2. Set the `--mcp-prm-file` flag to the path of the PRM file. |
| 81 | + |
| 82 | + - If you are using local deployment, you can just provide the path to the file directly: |
| 83 | + ```bash |
| 84 | + ./toolbox --tools-file tools.yaml --mcp-prm-file prm.json |
| 85 | + ``` |
| 86 | + - 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. |
| 87 | + ```bash |
| 88 | + gcloud secrets create prm_file --data-file=prm.json |
| 89 | + |
| 90 | + gcloud run deploy toolbox \ |
| 91 | + # ... previous args |
| 92 | + --set-secrets "/app/tools.yaml=tools:latest,/app/prm.json=prm_file:latest" \ |
| 93 | + --args="--tools-file=/app/tools.yaml","--mcp-prm-file=/app/prm.json","--port=8080" |
| 94 | + ``` |
| 95 | + |
| 96 | +## Step 3: Connecting to the Secure MCP Endpoint |
| 97 | + |
| 98 | +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`). |
| 99 | + |
| 100 | +The client should provide this JWT via the standard HTTP `Authorization` header when connecting to the Streamable HTTP or SSE endpoint (`/mcp`): |
| 101 | + |
| 102 | +```bash |
| 103 | +{ |
| 104 | + "mcpServers": { |
| 105 | + "toolbox-secure": { |
| 106 | + "type": "http", |
| 107 | + "url": "https://toolbox-service-123456789-uc.a.run.app/mcp", |
| 108 | + "headers": { |
| 109 | + "Authorization": "Bearer <your-jwt-access-token>" |
| 110 | + } |
| 111 | + } |
| 112 | + } |
| 113 | +} |
| 114 | +``` |
| 115 | +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. |
| 116 | + |
| 117 | +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. |
| 118 | + |
| 119 | +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. |
| 120 | + |
| 121 | +[cloud-run-alternate-auth-header]: https://docs.cloud.google.com/run/docs/authenticating/service-to-service#acquire-token |
0 commit comments