@scute/mcp-gateway sits between MCP clients and your MCP server (Streamable HTTP). It:
- serves the protected resource metadata (RFC 9728) that sends clients to your app's OAuth server, and checks every access token: signature, issuer, audience and expiry;
- trades each person's access token for a task token of the client's agent (RFC 8693), so every tools/call runs through the agent and person and task check and your harness guards;
- shows in tools/list only the tools the task could ever use;
- answers a missing scope with insufficient_scope, so the client asks the person for more access;
- hashes tool definitions and holds new or changed ones for review (tool pinning);
- forwards to your server with the gateway's own credential. The person's token never reaches it.
Before you run it#
- Turn on MCP sign-in for the app.
- Add the gateway's public URL as an MCP server, for example https://mcp.acme.io/mcp.
- Link MCP clients to an agent, or set a default agent. The agent's roles are the most a client can do.
Run the CLI#
SCUTE_APP_ID=app_xxx SCUTE_SECRET=YOUR_APP_SECRET \MCP_RESOURCE=https://mcp.acme.io/mcp \MCP_UPSTREAM=http://localhost:9000/mcp \MCP_UPSTREAM_AUTHORIZATION="Bearer UPSTREAM_KEY" \npx @scute/mcp-gatewayThe package's binary is scute-mcp-gateway.
| Variable | Required | Meaning |
|---|---|---|
| SCUTE_APP_ID | yes | The app's id or public id |
| SCUTE_SECRET | yes | The app's secret key. Used for token exchange and tool reports. |
| MCP_RESOURCE | yes | The gateway's public MCP URL, exactly as registered in Scute |
| MCP_UPSTREAM | yes | The MCP server behind the gateway |
| MCP_UPSTREAM_AUTHORIZATION | no | The Authorization header the gateway sends upstream |
| MCP_RESOURCE_NAME | no | Shown to clients in the resource metadata |
| SCUTE_BASE_URL | no | Default https://api.scute.io |
| PORT | no | Default 8787 |
| TRUST_PROXY | no | 1 to build the request URL from X-Forwarded-Proto and X-Forwarded-Host, behind a proxy you run |
The CLI runs with the default guard, guards.permissions(). To add guards, use the library.
Use the library#
import { createGateway, nodeListener } from "@scute/mcp-gateway";import { guards } from "@scute/harness";import { createServer } from "node:http";const gateway = createGateway({ resource: "https://mcp.acme.io/mcp", upstream: { url: "http://localhost:9000/mcp", headers: { authorization: `Bearer ${process.env.UPSTREAM_KEY}` } }, guards: [guards.permissions(), guards.content()],});createServer(nodeListener(gateway.handle)).listen(8787);gateway.handle is a standard fetch handler, (request: Request) => Promise<Response>, so it runs in any runtime with fetch. In a Next.js route handler:
import { createGateway } from "@scute/mcp-gateway";const gateway = createGateway({ resource: "https://mcp.acme.io/mcp", upstream: { url: process.env.MCP_UPSTREAM! },});export const POST = gateway.handle;export const GET = gateway.handle;export const DELETE = gateway.handle;The gateway also answers its resource metadata at /.well-known/oauth-protected-resource plus the resource's path (here /.well-known/oauth-protected-resource/mcp). In a framework with file routes, send that path to the same handler.
nodeListener(handler, { trustProxy }) adapts it to node:http.
Config#
What happens on a request#
Discovery
GET /.well-known/oauth-protected-resource (and the path-suffixed form) answers resource, authorization_servers (your app's issuer), scopes_supported and bearer_methods_supported. A request without a valid token answers 401 with WWW-Authenticate: Bearer resource_metadata="...", which starts the client's sign-in.
Token exchange
On the first tool call for an access token, the gateway calls POST /v1/oauth/:app_id/token with the token exchange grant and gets a task token for the client's agent. The task lives as long as the access token. A new task starts when it expires. See Token exchange for a task.
Tool calls
Each tools/call runs through the harness guards with the person's task. A call the guards refuse comes back as a tool error with a message for the model; the upstream never sees it. An allowed call is forwarded with the guards' arguments, and the result goes through the guards' after hooks.
Tool lists
tools/list drops held tools, drops tools whose permission is outside the task's ceiling (from whoami), and adds the gateway's own tools.
Step-up consent for scopes#
When the MCP server in Scute maps scopes to permissions (scope_actions), a call refused as outside_task whose permission belongs to a scope the person has not granted answers HTTP 403:
WWW-Authenticate: Bearer error="insufficient_scope", scope="tools:read tools:write", resource_metadata="..."The client then asks the person again with the wider scope.
Bringing the person in#
Next to your server's tools, the gateway lists its own tools and answers them itself, never forwarding them upstream. Each works with the person's task and answers with a say line.
| Tool | Does |
|---|---|
| scute_verify_person | Sends the person a code or a push |
| scute_submit_code | Passes on the code they read out |
| scute_check_verification | Checks a push or a link |
| scute_approval_status | Checks a reviewer's answer |
| scute_whoami | Who the task works for, what it may do, and what needs verification or approval |
When a call needs verification, the model is told to use scute_verify_person and try again. An upstream tool with one of these names is replaced by the gateway's. humanTools: false turns them off. Signing in is not a tool: the client signs the person in when it connects.
Limits and errors#
| Case | Answer |
|---|---|
| Wrong Host, or an unexpected Origin | 403 |
| No token, or a token that is invalid, expired or for another server | 401 with WWW-Authenticate |
| A JSON-RPC batch that contains a tools/* request | 400. Send tools/* requests one at a time. |
| A body over 5,000,000 characters | 413 |
| Token exchange failed (no agent linked, agent suspended) | A tool error naming the reason |
| A failure while checking the upstream's answer | A JSON-RPC error; the unchecked answer is never passed on |
| Any other gateway failure | 502 with a JSON-RPC error |
Forwarded upstream: the gateway's upstream.headers, plus the client's Accept, Content-Type, Mcp-Session-Id, Mcp-Protocol-Version, Last-Event-ID, traceparent and tracestate. Server-sent event streams pass through event by event; only the event carrying the answer is changed.