MCP Tunnels

MCP tunnels connect Allternit to externally hosted MCP servers over HTTPS. Each tunnel has a unique token that the MCP server uses to authenticate inbound connections, plus optional mTLS client certificates and OAuth issuer/audience validation enforced by mcp_tunnel_auth.

Base URL

Endpoints

Create a tunnel

Request body

Response

Save the tunnel_token immediately. It can be revealed later, but treat it as a secret.

List tunnels

Response

Update a tunnel

Response

Rotate the tunnel token

Response

Reveal the tunnel token

Response

Delete a tunnel

Response

Authentication policy

Tunnels support three layers of security:
  1. Tunnel token — a shared secret presented by the MCP server.
  2. mTLS client certificate — client_cert_pem can be provided for mutual TLS.
  3. OAuth issuer and audience — the request must come from the configured issuer and audience. How that is checked depends on the policy’s direction.

Policy direction

Each policy row in mcp_tunnel_auth has a direction:

Outbound headers come from the gateway only

/mcp/server is reachable by any signed-in user, so the API only believes the tunnel headers (x-allternit-tunnel-*, x-allternit-client-cert-thumbprint, x-allternit-oauth-issuer, x-allternit-oauth-audience) when the same request carries the internal service token in x-allternit-internal-token. The gateway holds that token (ALLTERNIT_INTERNAL_SERVICE_TOKEN); users and MCP clients never do.
  • A request with any tunnel header and no valid internal token is refused: HTTP 401, JSON-RPC error -32001, tunnel headers are set by the gateway only. Leaving out x-allternit-tunnel-id does not get around this.
  • A request with no tunnel headers runs as the signed-in user exactly as before.
  • A policy that pins client_cert_pem or oauth_issuer can therefore only be satisfied through the gateway. Clients cannot assert a certificate thumbprint or an issuer themselves.
For inbound_share, the JWKS comes from the policy’s jwks_url, or, when jwks_url is empty, from the issuer URL followed by /.well-known/jwks.json. Only https URLs are accepted (plain http only to localhost or 127.0.0.1). Keys are cached for an hour. A token signed with a key the cache does not know (key rotation) triggers a fresh fetch, at most once every 30 seconds.

Error codes

  • Tools / MCP — attaching MCP servers and server-side execution
  • Workspaces — scope tunnels to workspaces