Skip to content

Connect an external MCP client

SupaCloud exposes a developer-facing MCP gateway at POST /api/mcp. It is a standard Model Context Protocol Streamable-HTTP endpoint (stateless JSON-RPC 2.0), so any conformant MCP client — a local IDE, a coding agent, or a hand-rolled curl — can list and call a curated set of SupaCloud tools. Auth is a scoped scmt_ management token in the Authorization header, or an access token SupaCloud’s own OAuth authorization server issues after a workspace owner or admin consents in the browser. A standard MCP client finds that server from the 401 alone, see Authorization discovery. Follow these steps to wire a client to it.

  • The instance must run the enterprise edition. The gateway is gated by the mcp_gateway_external feature (fail-closed in interfaces/http/external_mcp.rs); on a Community instance every request to /api/mcp returns 403.
  • You need permission to mint a management token for the target Workspace (the token must be workspace-scoped — a global/bootstrap token is rejected).
  1. Mint a scoped scmt_ token.

    The gateway reuses the existing Management-API token (scmt_…, hash-only), extended with two MCP scopes:

    • mcp:read — the read tools (list/get/observe), including run.list / run.get / run.events.
    • mcp:ops — implies mcp:read and adds the ops + script-run tools (workflow.trigger, script.run, the whole schedule.* group, issue/PR/ repo-sync ops). Use this when your local dev should actually run workflows and scripts, not just watch.

    Create the token via the Management API. The response carries the plaintext bearer once — it is never re-readable:

    Terminal window
    curl -sS -X POST \
    "$SUPACLOUD_URL/api/management/v1/workspaces/$WORKSPACE_SLUG/api-tokens" \
    -H "Authorization: Bearer $BOOTSTRAP_MGMT_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{ "label": "local-ide-mcp", "scopes": ["mcp:ops"] }'

    The returned token field (starting scmt_) is your MCP bearer. Store it in $SC_MCP_TOKEN.

  2. Point your MCP client at the gateway.

    The transport is Streamable HTTP, stateless — a single endpoint, no Mcp-Session-Id, every request self-contained from the bearer. Most clients take an HTTP MCP server URL plus a static Authorization header. For example, a local IDE / agent MCP config:

    {
    "mcpServers": {
    "supacloud": {
    "url": "https://your-instance.example.com/api/mcp",
    "headers": {
    "Authorization": "Bearer scmt_your_token_here"
    }
    }
    }
    }

    The gateway advertises protocol version 2025-06-18 and a tools capability in its initialize result.

  3. List the tools your token can reach.

    tools/list returns only the tools on the external surface for your scope. A read token sees the read tier; an ops token additionally sees ops + script-run:

    Terminal window
    curl -sS -X POST "$SUPACLOUD_URL/api/mcp" \
    -H "Authorization: Bearer $SC_MCP_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{ "jsonrpc": "2.0", "id": 1, "method": "tools/list" }'
    {
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
    "tools": [
    { "name": "run.list", "description": "…", "inputSchema": { … }, "outputSchema": { … } }
    ]
    }
    }
  4. Call a tool.

    tools/call takes a name and an optional arguments object. A read example (lists recent runs in the workspace):

    Terminal window
    curl -sS -X POST "$SUPACLOUD_URL/api/mcp" \
    -H "Authorization: Bearer $SC_MCP_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
    "jsonrpc": "2.0",
    "id": 2,
    "method": "tools/call",
    "params": { "name": "run.list", "arguments": {} }
    }'

    A successful call returns a result whose structuredContent is the typed tool output (the content text block is the same value as a JSON string):

    {
    "jsonrpc": "2.0",
    "id": 2,
    "result": {
    "content": [ { "type": "text", "text": "{\"runs\":[…]}" } ],
    "structuredContent": { "runs": [ … ] },
    "isError": false
    }
    }

    A nested result object leaves out every member whose value is null unless the tool’s outputSchema lists it in required, so a run row without a model has no model member at all. Read an absent member as null. Members of the result object itself (such as total of backlog.list) are always present.

    An ops example (requires an mcp:ops token) triggers a workflow:

    Terminal window
    curl -sS -X POST "$SUPACLOUD_URL/api/mcp" \
    -H "Authorization: Bearer $SC_MCP_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
    "jsonrpc": "2.0",
    "id": 3,
    "method": "tools/call",
    "params": { "name": "workflow.trigger", "arguments": { "workflow_id": "…" } }
    }'

The surface is a positive filter (services/mcp/external.rs::external_tool_allowed) applied to both tools/list and tools/call, on top of the inherited tier allowlist:

Scope Reachable tools
mcp:read Read tier — run.list, run.get, run.events, workflow.list/get, project.list, issue.list/get, conversation reads, app-build/migration reads, memory.list_closeouts, and the reference reads docs.search, docs.get, spec.get, spec.validate, models.list
mcp:ops (adds) Ops + ScriptRun — workflow.trigger, script.run, the whole schedule.* group (create/update/pause/resume), issue/PR/repo-sync ops

A few read-tier tools are deliberately excluded because they need an agent identity an M2M token doesn’t have: memory.create (profile-gated write) and permission.list. On the ops surface, permission.grant / permission.revoke are excluded for the same reason.

  • The Deploy tier is never reachable. app.deploy / app.migration.apply are excluded by the surface filter and the external allowlist set, and every deploy-tier call waits for a person to approve its tool-approval gate before it runs. Deploy stays inside the agent runner.
  • No token pass-through. Every tool call runs through SupaCloud’s internal services::* — which act as their own OAuth client against GitHub/Linear/etc. Your scmt_ token never leaves SupaCloud.
  • Its authorization server mints nothing wider than a token. An OAuth connection is an ordinary workspace scmt_ token with mcp:read, or mcp:read and mcp:ops: never a management:* scope, never owner power, never another workspace.

The gateway follows the MCP authorization specification (revisions 2025-11-25 and 2026-07-28). SupaCloud is the OAuth 2.1 resource server for /api/mcp and its own authorization server, so a client connects with nothing configured but the URL:

  1. The challenge names the metadata. A 401 from POST /api/mcp carries WWW-Authenticate: Bearer resource_metadata="https://<your-instance>/.well-known/oauth-protected-resource/api/mcp", scope="mcp:read mcp:ops".

  2. Protected resource metadata (RFC 9728). GET /.well-known/oauth-protected-resource/api/mcp and the root fallback GET /.well-known/oauth-protected-resource return the same document: the resource (https://<your-instance>/api/mcp), authorization_servers with SupaCloud’s issuer (https://<your-instance>) first, scopes_supported (mcp:read, mcp:ops) and bearer_methods_supported: ["header"]. An approved agent-identity registration profile (ADR 0088) adds its issuer and scopes after SupaCloud’s; offline_access is never listed. The document exists whenever the instance’s public URL is https.

  3. Authorization server metadata (RFC 8414). GET /.well-known/oauth-authorization-server names the authorization_endpoint (/api/mcp-auth/authorize), the token_endpoint (/api/mcp-auth/token), the registration_endpoint (/api/mcp-auth/register), the revocation_endpoint (/api/mcp-auth/revoke), code_challenge_methods_supported: ["S256"], token_endpoint_auth_methods_supported: ["none"], client_id_metadata_document_supported: true and authorization_response_iss_parameter_supported: true (RFC 9207). Every endpoint it names is served; an error is JSON, never an HTML page.

  4. The client identifies itself. Either its client_id is an https URL of a client ID metadata document (fetched through the egress guard: public addresses only, no redirects, 5 KiB at most, redirect_uris required), or it registers (RFC 7591) with client_name and redirect_uris. A redirect URI is https, or http on a loopback address (127.0.0.1, [::1], localhost), where any port matches (RFC 8252 §7.3); everything else must match exactly. Clients are public: no client secret.

  5. A person consents in the browser. The authorization request needs response_type=code, an S256 code_challenge and resource=https://<your-instance>/api/mcp (RFC 8707). The browser lands on /oauth/consent, where a signed-in workspace owner or admin sees the client name, where the browser returns to (with a warning for a loopback redirect), picks the workspace and the access levels, and allows or denies. The client redirect carries code, state and iss.

  6. The token exchange. POST /api/mcp-auth/token (form-encoded) with the code, the same redirect_uri, the code_verifier and the same resource returns a Bearer access token (an scmt_ workspace token, valid one hour) and a refresh token (scrt_, valid 30 days, rotated on every use). The code is single-use and lives five minutes.

  • The connection is a workspace token. It is listed on Settings → API tokens as MCP connection: <client name>, created by the person who consented. Revoking it there, or POST /api/mcp-auth/revoke with either token (RFC 7009), ends the whole connection.
  • Replay ends a connection. A code or refresh token presented twice, or a refresh token presented by another client, revokes every token of that connection.
  • Every refresh re-checks the person. A refresh succeeds only while the consenting person still administers the workspace and the plan still includes the external MCP gateway; a refresh may narrow the scopes, never widen them. A refresh that names a scope outside the connection’s grant is refused with invalid_scope and leaves the refresh token usable.
  • Storage and limits. Codes, refresh tokens and request handles are stored as hashes only. Registration is capped at 10 new clients per hour per source address and at 500 per hour per instance. The four client endpoints (registration, authorization, token and revocation) also share the per-address rate of the sign-in endpoints. A throttled call answers 429 Too Many Requests with a Retry-After header in seconds and the JSON body {"error": "too_many_requests", "error_description": "…"}; wait that long, then retry. Consent and every issued token write an audit event in the same transaction as the decision or the token, so the event exists exactly when the grant does.
  • A static token needs none of this. A client configured with an Authorization: Bearer scmt_… header never receives the 401 and never starts the OAuth flow.
  • POST only. GET and DELETE on /api/mcp answer 405 Method Not Allowed with Allow: POST. The gateway opens no standalone SSE stream and keeps no session, which is the Streamable HTTP shape of revision 2026-07-28 (and what earlier revisions allow for a server without a GET stream). A client does not need to probe them.

The external identity is the token row, so limits key on the token, not a user:

  • A per-identity in-process burst limit stops one token from flooding the gateway.
  • A per-identity hourly ops cap — the external analog of the per-profile cap — counts the token’s own ops audit rows in a rolling hour. Default 30, tunable via AGENT_MCP_EXTERNAL_OPS_HOURLY_LIMIT. Over the cap, an ops call returns a Forbidden tool error.
  • An ops call also reserves a slot against the shared workspace daily ops cap.

So a single developer’s token cannot drain the workspace ops budget on its own.

  • The consent page says the request expired or was decided — a request lives ten minutes and is decided once. Start the connection again from the client.
  • invalid_grant at the token endpoint — the code expired, was already used, or the redirect_uri, code_verifier or resource differ from the authorization request. A refresh answers it once the connection was revoked or the consenting person no longer administers the workspace.
  • 401 Unauthorized — missing or empty Authorization: Bearer header, or a token that does not resolve.
  • 403 Forbidden at the transport — one of: the instance is not enterprise edition (mcp_gateway_external disabled); the token is global/bootstrap, not workspace-scoped; or a present Origin header does not match the control-plane host (the DNS-rebind guard — an absent Origin, as a server-to-server client sends, is allowed).
  • JSON-RPC error -32601 “tool not available on the external surface” — the tool is not on your scope’s surface. A read token calling an ops tool, or any caller hitting an excluded tool (deploy, memory.create, permission.*), lands here. Mint an mcp:ops token if you need the ops tier.
  • JSON-RPC error -32601 project_credential_required — the tool acts on one project (artifact comments, forms, exports, shares), and a workspace token has no project to bind it to. The message names the project and the exact capabilities (artifacts:comment, artifacts:form, …); connect with a project credential (scpj_) that carries them, as Connect a local agent session describes.
  • JSON-RPC error -32700 “parse error” — the request body was not a JSON object.
  • "isError": true in a tools/call result — the call ran but the tool failed (HTTP is still 200). Server-class detail (SQL/vault/internal) is redacted to a generic message; the raw error is logged server-side.
  • Ops call rejected as Forbidden — you have hit the hourly ops cap (default 30) or the workspace daily ops cap.
  • 429 from /api/mcp-auth/register — this address registered 10 clients in the last hour, or the instance reached 500. Reuse the client you registered instead of registering on every start, and retry after the Retry-After seconds.

initialize answers tools.listChanged: true and issues Mcp-Session-Id. Echo that header on every later request. When the catalog you can see changes — a new server build, or a change of your credential’s grants — the next response is text/event-stream whose FIRST message is notifications/tools/list_changed and whose second is your response; call tools/list after it. A tools/list answer is itself the statement that you refreshed, so you are not notified again for a list you already hold. If you cannot read an event stream (no text/event-stream in Accept), you are answered in JSON and told on a later request.

The notification is bounded, not a broadcast: a workspace token’s record lives in the gateway process, so with several replicas you may be told once per replica, and a deploy starts empty — one extra notification after it. An enrolled identity’s record lives on its request session row instead, so it survives both. A notification is idempotent; re-list and carry on. AGENT_MCP_CATALOG_NOTIFY_RETRY_SECS (default 600) bounds how often an unanswered notification repeats.