Skip to content

Case study 01 · Public repo · reference implementation

Every tool callpasses one checkpoint.

A gateway that sits in front of MCP servers: single sign-on, role-based tool access, a request log, a usage ledger and a trace per call.

Role
Design, build, tests, deploy
Stack
TypeScript, MCP TypeScript SDK v2, OIDC, SQLite, OpenTelemetry
Runs on
Docker Compose, Kubernetes (kustomize)
Status
Public, MIT, 55 tests, CI green

Read the code ↗

localhost:16686 · Jaeger
Jaeger showing one span from the gateway's demo run: tools/call ops__summarize, with attributes for the user, department, roles, outcome and cost.
A real span from the bundled demo, viewed in Jaeger. User, department, role, outcome and cost ride on every tool call.

The problem

Agents get tools faster than anyone decides who may use them.

Each MCP server a team connects is another place where access is decided, or not decided at all. Nobody can say which department called which tool last week, or what it cost.

The gateway puts one checkpoint in front of all of them. A caller signs in with the company identity provider, sees only the tools their role allows, and every call is written down.

How it works

Follow one requestthrough it.

Drag sideways to follow it →

mcp-gatewayloginBearer tokenJWKSOIDC issuerOkta, or the dev issuerMCP clientassistant or agent, signed in1 Validate tokensignature, issuer, audience, expiry2 Policy checkgroups → roles → servers and tools3 Forward the callwith the gateway's own credential4 Recordrequest log + usage ledgerOTLP collectorone span per tool callopsupstream MCP serverfinanceupstream MCP serverSQLite + JSONLrequests, ledgerGET /reports/usage
Allowed call: validated, permitted, forwarded, recorded.Denied call: stops at the policy check, never reaches an upstream, and is still recorded.
  1. Check who is calling

    The access token is validated on every request against the issuer's signing keys.

  2. Check what they may use

    A YAML policy maps identity-provider groups to servers and tools. Default deny, and deny wins.

  3. Forward the call

    With the gateway's own credential. The caller's token never reaches an upstream.

  4. Write it down

    One log entry and one ledger row per request. If the log cannot be written, the call fails.

What is measured

What the repo can back up.

55
tests, passing in CI
≈1,200
lines of TypeScript for the gateway itself
6
outcomes a request can end in, each logged
0
tool arguments or results written to the log
docker compose run --rm demo · request log and ledger
user   department   roles            method              tool                outcome          latencyMs  costUsd
-      -            -                mcp                 -                   unauthenticated  0.46
alice  Engineering  engineer         tools/list          -                   allowed          34.21
alice  Engineering  engineer         tools/call          ops__summarize      allowed          7.41       0.00139
bob    Finance      finance-analyst  tools/list          -                   allowed          0.19
bob    Finance      finance-analyst  tools/call          ops__delete_record  denied           0.09
bob    Finance      finance-analyst  GET /reports/usage  -                   denied           0.48

key          calls  allowed  denied  errors  inputTokens  outputTokens  costUsd
Engineering  1      1        0       0       35           19            0.00139
Finance      1      0        1       0       0            0             0
Output of the scripted demo on a laptop, 12 Nov 2026: three sample users, two sample upstream servers. It shows the checks and the log working. It is not a load test.

Read this before the numbers

  • Tested against the bundled development issuer, including discovery and the authorization-code + PKCE flow, and with Okta-shaped tokens in unit tests. It has not been run against a live Okta tenant.
  • The ledger attributes the cost of tool calls. It does not see the tokens an assistant spends talking to a model provider.

What it leaves out

The limits,stated plainly.

  • Tools only

    Resources, prompts, sampling and elicitation are not proxied.

  • One replica

    The log and ledger live in SQLite on a local volume. More replicas need a shared database.

  • No rate limits or quotas

    The ledger tells you who spent what. It does not stop them.

  • Upstreams see the gateway, not the user

    Per-user authorization at an upstream needs a token-exchange step this does not have.

  • Policy reloads need a restart

    The policy is read once, at startup.

  • The log is not tamper-evident

    Ship the JSONL somewhere append-only if you need that.