Open the console

Guides

MCP authentication by example

Every way a credential moves around an MCP call, as a worked example: who holds it, what you write, and what each side sees. The mechanisms behind them are in MCP servers and Security context. How you authenticate to the platform's own API is Authentication.

What is supported

Who is asking, whose agent asks for them, and whose MCP server answers. You are the developer deploying here; a third party runs its MCP server somewhere else.

UserAgent providerMCP providerSupported?
Your user, in your appYouYou, in the same projectYes. No credential (1), or as the user with their token (7)
Your user, in your appYouA third party, with your keyYes (5)
Your user, in your appYouA third party, with the user's OAuth 2 sign-inYes, two ways. The platform runs the sign-in and keeps the tokens — connected accounts — or your app runs it and passes each run the access token (6)
Your user, in your appYouA third party, signing the user in mid-conversationYes, with connected accounts: the run pauses with a sign-in link and carries on by itself once the user signs in. No token enters the conversation
Your user, in your appYouA third party that wants a DPoP-bound token, a client certificate, plain HTTP or a port other than 443No. Bearer tokens, over HTTPS on 443
Your user, in your appYouYou, in another project, or another tenantNo. The gateway admits only agents in the server's own project
Your user, in your appYouYou, and your server calls a third party as the userYours to build. The platform exchanges no tokens: keep each user's third-party token in your server's own database, keyed by the verified sub (3)
Someone outsideTheir MCP app (Claude, ChatGPT, Cursor…)You, with auth: serverYes (3). They sign in with your provider
Someone outsideTheir MCP appYou, with auth: platformNot yet. The platform's sign-in issues tokens to machines only. An app that takes a custom header can use a minted token for an hour (2); otherwise use auth: server
Your backend or a scriptNoneYou, publicYes (2)
You, in the consoleThe InspectorYou, private or publicYes. The server page's Inspector tab, as you
Anyone, anonymouslyAnythingYou, public, checking nobodyNo, by design. A public server always has a caller check: the platform's, or your verifier

Which one is yours

#SituationThe credential isYou write
1Your agents call your MCP serverNone. The platform knows your agentserver= on the binding
2A script or backend calls your public serverA token the platform mints for that serverauth: platform and elan mcp token
3People connect it from their MCP app and sign in (OAuth 2)Your sign-in provider's tokenauth: server and a verifier
4Your MCP server calls an API with your keyYours, in a secretsecrets: and egress:
5Your agent calls another MCP server with your keyYours, in a secretcredentials.own and ToolAuth
6Your agent acts as your user, who signed in in your app (OAuth 2)Your user's access token, per invocationcredentials.caller, ToolAuth and security_context
7Your agent calls your own server as your userYour user's token for that server6, with server= instead of a URL
8A Python tool needs a key or a tokenYour user's, yours, or one your code mintsauth_config or a credential service
9Your agent acts as your user at a third party, and the platform signs them in (OAuth 2)Your user's tokens, kept by the platformconnections: and credentials.connections
  • A server's auth decides who can call it from outside (2 and 3). The agent's credentials= decides what it sends when it calls out (5 to 8). The two are independent, and a server can be called both ways at once.
  • MCP App views add no sign-in of their own. See MCP App views.

1. Your agents call your MCP server

No credential at all. The gateway admits only this project's own agents and tells your server which run and which user the call is for.

agents/marine_mammals/agent.py
from agentkit_core.manifest import ToolBinding

tools=[ToolBinding(kind="mcp", ref="tides", server="tide-tables",
                   tool_filter=["high_tide"])],
mcp_servers/tide_tables/server.py
from fastmcp import FastMCP
from fastmcp.server.dependencies import get_http_headers

MANIFEST = {"slug": "tide-tables", "version": "0.1.0", "auth": "platform"}


def build(ctx) -> FastMCP:
    server = FastMCP("Tide Tables")

    @server.tool()
    def high_tide(port: str) -> str:
        """The next high tide at a port."""
        sent = get_http_headers()
        user = sent.get("x-agentkit-subject", "")    # the run's user
        run = sent.get("x-agentkit-invocation", "")  # which run asked
        ...

    return server
  • Works for any expose, and is how a private server is called at all.
  • The subject is your agent's word, not a signature. Trust it as far as “an agent in this project says so”. To act as a user you have verified, use 7.
  • Billed at the from your agents rates, never the public ones.

2. A script or backend calls your public server

With auth: platform (the default) and expose: public, the platform checks the caller, so your server verifies nothing. The caller sends a token minted for that one server:

Shell
elan mcp token tide-tables > token.txt     # an hour, this server only

curl https://api.acme.example/mcp/acme/salmon/tide-tables \
  -H "Authorization: Bearer $(cat token.txt)" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -H "MCP-Protocol-Version: 2025-06-18" \
  -d '{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}'
  • Three ways to mint one: the server's Connect tab in the console, elan mcp token, or, from a backend with a service user, POST /v1/token with grant_type=client_credentials and resource= the server's URL.
  • The token stops at the gateway. Your server sees X-Agentkit-Caller: external and the token's holder in X-Agentkit-Subject, never the token.
  • It works for that one server and nothing else on the platform, so pasting it into an MCP client's config risks one server for an hour.

3. People connect it from their MCP app and sign in (OAuth 2)

For Claude, ChatGPT, Cursor, VS Code or any MCP client that signs its user in with OAuth 2. Your server is the resource server and verifies tokens from your sign-in provider:

mcp_servers/notes/server.py
from fastmcp import FastMCP
from fastmcp.server.auth import RemoteAuthProvider
from fastmcp.server.auth.providers.jwt import JWTVerifier
from fastmcp.server.dependencies import get_access_token

MANIFEST = {"slug": "notes", "version": "0.1.0", "auth": "server"}

ISSUER = "https://login.acme.example/"


def build(ctx) -> FastMCP:
    verifier = JWTVerifier(
        jwks_uri=ISSUER + ".well-known/jwks.json",   # fetched on first use
        issuer=ISSUER,
        audience=ctx.public_url,     # tokens issued for THIS server only
    )
    server = FastMCP("Notes", auth=RemoteAuthProvider(
        token_verifier=verifier,
        authorization_servers=[ISSUER],
        base_url=ctx.public_origin,  # FastMCP adds the server's path itself
    ))

    @server.tool()
    def my_notes() -> list[str]:
        """The signed-in user's notes."""
        user = get_access_token().claims["sub"]      # verified, never from the body
        ...

    return server
elan.yaml
targets:
  notes:
    expose: public
  1. Somebody adds the server's URL to their MCP app.
  2. The first call is answered 401 naming your server's metadata, which names your provider.
  3. They sign in there. The app receives a token whose audience is your server's URL.
  4. Every call carries it. The gateway passes Authorization through untouched, and your verifier checks it.
  • Your provider must issue a token for this URL, as its audience. Most call that the API identifier or the resource indicator.
  • The app has to be a client of your provider: either your provider lets MCP apps register themselves, or you register each one.
  • Refused before your code runs: a token this platform issued, and, at deploy, a public auth: server server that configures no verifier.
  • The platform does not know who your callers are. Observability lists them as public and not identified; your server knows them by sub.
  • The same server code serves your own agents too, through 7.

4. Your MCP server calls an API with your key

One key of yours, used for every caller. It reaches the server as an environment variable.

elan.yaml
targets:
  tide-tables:
    egress:
      - host: api.tides.example      # this server's own allowlist
    secrets:
      - {name: tides-api-key, env: TIDES_API_KEY}
Shell
elan secret set secrets tides-api-key      # reads stdin
mcp_servers/tide_tables/server.py
import os

import httpx


def build(ctx) -> FastMCP:
    server = FastMCP("Tide Tables")

    @server.tool()
    async def high_tide(port: str) -> str:
        """The next high tide at a port."""
        async with httpx.AsyncClient() as http:      # uses the egress proxy
            answer = await http.get(
                "https://api.tides.example/v1/high", params={"port": port},
                headers={"X-API-Key": os.environ["TIDES_API_KEY"]})
        return answer.text

    return server
  • Read it inside the tool. build() also runs at deploy, offline, to list your tools.
  • The host is this server's alone. Your agents cannot reach it, and this server cannot reach theirs. HTTPS on 443 only.
  • Use a client that honors the proxy. httpx does by default; aiohttp needs trust_env=True. One that ignores it times out rather than failing.
  • Setting, rotating and removing the value: Secrets.

5. Your agent calls another MCP server with your key

A third-party server that takes one key, yours, for every user. Declare it as the agent's own credential and name it on the binding:

agents/triage/agent.py
from agentkit_core.manifest import (
    AgentManifest, Credentials, FromEnv, ToolAuth, ToolBinding,
)

MANIFEST = AgentManifest(
    slug="triage",
    version="0.1.0",
    credentials=Credentials(own={
        "tracker": FromEnv(env="TRACKER_KEY", kind="bearer",
                           resource="https://mcp.tracker.example/mcp"),
    }),
    tools=[
        ToolBinding(kind="mcp", ref="tracker", url="https://mcp.tracker.example/mcp",
                    auth=ToolAuth(credential="tracker")),
    ],
    ...
)
elan.yaml
targets:
  triage:
    egress:
      - host: mcp.tracker.example
    secrets:
      - {name: tracker-key, env: TRACKER_KEY}   # fills credentials.own["tracker"]
  • Sent as Authorization: Bearer. For a key in a header of its own, use kind="api_key", header="X-Tracker-Key".
  • The tracker sees your agent, not your user. Every user shares what this key can do.
  • A caller cannot replace it: a credential named tracker in an invocation is ignored.
  • The deploy refuses it if no secret fills TRACKER_KEY.

6. Your agent acts as your user, who signed in in your app (OAuth 2)

Your user uses your agent, and your agent uses a third party's MCP server that signs people in with OAuth 2 — a tracker, a CRM, a calendar. Your user connects their account in your app, and your agent then works in it as them. The OAuth 2 client is your app; the platform only carries the resulting access token for one run.

Your user connects their tracker account in your app, which is the OAuth 2 client: the tracker's sign-in shows your app's name, and the code and tokens come back to your app. Your backend keeps the refresh token. Each time the user asks the agent something, your backend sends a fresh access token with the invocation; the agent attaches it to the tracker's MCP server and nothing else, and the events that come back carry no token.Your usersigned in to your appYour appthe OAuth 2 clientTracker sign-inits OAuth serverThe platformruns your agentTracker MCPa third partyconnect tracker1authorize + PKCE2sign in, consent3code4code for tokens5access + refresh6keep refresh token7asks the agent8invoke + access token9Bearer <token>10the result11events, no token12
Your user connects their tracker account in your app, which is the OAuth 2 client: the tracker's sign-in shows your app's name, and the code and tokens come back to your app. Your backend keeps the refresh token. Each time the user asks the agent something, your backend sends a fresh access token with the invocation; the agent attaches it to the tracker's MCP server and nothing else, and the events that come back carry no token.

Once, while you build: find its sign-in

  1. Read the server's Protected Resource Metadata. Its authorization_servers names the sign-in to use. A call with no token is answered 401 naming the same URL.
  2. Read that sign-in's own metadata for its authorize, token and, if it has one, registration endpoints.
  3. Register your app there as a client: in the provider's developer settings, or through its registration endpoint. The redirect URI is your app's. The platform is not part of this flow.
Shell
curl https://mcp.tracker.example/.well-known/oauth-protected-resource/mcp

For each user: connect, then invoke

  1. A Connect tracker button in your app starts the authorization code flow with PKCE, asking for a token for resource=https://mcp.tracker.example/mcp so it is issued for that server.
  2. Your backend exchanges the code and keeps the refresh token, encrypted, per user.
  3. On each invoke it sends a fresh access token in the security_context, and the agent attaches it to the one binding that names it.
agents/triage/agent.py
MANIFEST = AgentManifest(
    slug="triage",
    version="0.1.0",
    # The invoking user's, sent with each invocation.
    credentials=Credentials(caller=["tracker"]),
    tools=[
        ToolBinding(kind="mcp", ref="tracker", url="https://mcp.tracker.example/mcp",
                    auth=ToolAuth(credential="tracker")),
    ],
    ...
)
Request
from elan_sdk import Elan
from elan_sdk.security import OAuth2, SecurityContext

elan = Elan.from_env()

# Your OAuth client, on your backend: it holds Ada's refresh token and
# returns a short-lived access token. The refresh token never leaves it.
access_token = tracker_tokens.access_token_for("ada")

accepted = elan.runtime.invoke(
    "triage",
    "What is assigned to me this week?",
    project="salmon",
    session_id="sess-ada-1",
    end_user_id="ada",
    security_context=SecurityContext(credentials=[
        OAuth2(name="tracker", access_token=access_token,
               scopes=["issues:read"], resource="https://mcp.tracker.example/mcp"),
    ]),
)
  • Only the access token reaches the platform. A refresh_token or client_secret is refused by name.
  • Set resource, so not even a mistake in agent code can send the token anywhere else.
  • Nothing is stored. The token is sealed for the run and deleted when it ends. A run waiting for approval keeps it until ttl_seconds; replace it with refresh_security_context before approving one that waited longer.
  • Ask before you invoke. Your app holds the tokens, so it knows whether this user has connected; show Connect tracker instead of starting a run that cannot work.
  • A run that starts without one anyway ends with an error event of type CredentialNotSupplied, and one whose token runs out mid-run with CredentialExpired. The tracker is never called without it. To let the agent carry on without the tracker's tools instead, use ToolAuth(credential="tracker", required=False).
  • The agent cannot sign the user in itself. It has no browser to show a consent screen in, and ADK's interactive sign-in writes the token into the stored conversation, so the platform ends a run that asks for it.
  • The agent still needs the host under egress:, as in 5.
  • To try it before your app exists, the Playground's run options take one test credential.

7. Your agent calls your own server as your user

Your own auth: server server from 3, called by your agent with the user's token from your provider. The binding names the server instead of a URL:

agents/notes_assistant/agent.py
credentials=Credentials(caller=["notes"]),
tools=[
    ToolBinding(kind="mcp", ref="notes", server="notes",
                auth=ToolAuth(credential="notes")),
],
Request
from elan_sdk import Elan
from elan_sdk.security import Bearer, SecurityContext

elan = Elan.from_env()

accepted = elan.runtime.invoke(
    "notes-assistant",
    "What did I write about the launch?",
    project="salmon",
    session_id="sess-ada-1",
    end_user_id="ada",
    security_context=SecurityContext(credentials=[
        # Issued by your sign-in provider, for the server's public URL.
        Bearer(name="notes", token=ada_notes_token,
               resource="https://api.acme.example/mcp/acme/salmon/notes"),
    ]),
)
  • Bind the token to the server's public URL, https://<api host>/mcp/<tenant>/<project>/<server>. That is the audience its tokens are issued for, and what the reach rule checks, even though the call itself stays inside the cluster.
  • No egress rule. The call goes through the gateway, which passes Authorization through to an auth: server server untouched.
  • One server, two kinds of caller. The same verifier accepts your agents' calls here and people's calls from their MCP apps in 3, and acts as the token's sub in both.
  • The server does not need expose: public for this; a private one is reached the same way.

8. A Python tool needs a key or a token

The same three sources reach a function tool through ADK's own credential API, answered by the platform's credential service:

WhoseDeclareRead it with
Your user's, per invocationcredentials.callerAuthenticatedFunctionTool(auth_config=auth_config(name))
Yours, from a secretcredentials.ownsecurity.headers(name, url=…, context=tool_context)
One your code mints, like a back-office tokencredentials.servicetool_context.load_credential(…)

Worked examples of all three are in In a function tool and Your own service.

MCP App views

  • A view travels with its tool's call. Its ui:// resource is read over the same binding, so whatever credential the binding sends (1, 5, 6 or 7) is sent for the view too. There is nothing extra to declare.
  • A view cannot sign anybody in. In this console it runs in a frame allowed scripts only: no pop-ups, no cookies of its own, no access to the page around it. Sign-in happens in your app (6 and 7) or in the MCP app (3).
  • A view shows what its tool returned, and the tool computed that as the verified user. Do per-user work in the tool, never in the view.

What your server sees

The call comes fromAuthorizationX-Agentkit-CallerX-Agentkit-Subject
Your agent (1)NoneThe workload the agent runs inThe run's user, as your agent states it
Your agent, as your user (7)The user's tokenThe workload the agent runs inThe run's user, as your agent states it
A platform token (2)None. It stops at the gatewayexternalWhoever the token was minted for
An MCP app, signed in (3)The caller's tokenexternalNot set. Read sub from the token
The console's InspectorA pasted token, for auth: server onlyinspectorThe person signed in to the console
  • Every call also carries X-Agentkit-Tenant and X-Agentkit-Project, and an agent's call carries X-Agentkit-Invocation, the run it came from.
  • Only the platform sets them. Any X-Agentkit-* header a caller sends is removed first, and nothing but the gateway can reach your server.
  • get_http_headers() leaves out Authorization; read a verified token with get_access_token().

Reading this as a model? llms.txt indexes every page, and each page has a “Copy for AI” control.