MCP quickstart

The MCP authorization specification makes your MCP server an OAuth resource server and leaves issuing tokens to an authorization server. A resource server accepts access tokens, and an authorization server issues them. Timonier acts as the authorization server for your MCP server.

An assistant identifies itself with a Client ID Metadata Document, so you register nothing for it. The client ID is an HTTPS URL, and that URL serves a JSON document with the client's metadata. The format is an IETF draft, not a standard. People sign in on your app's sign-in page and approve the assistant on a consent screen. The assistant then gets a token bound to your MCP server's address.

This guide runs a sample MCP server on your machine and connects the MCP Inspector to it. The MCP Inspector (2.16.0) is the client we have tested.

Before you start

  • Node.js ^22.23.4, ^24.22.1 or >=26.12.1.
  • A project in your operator dashboard. Steps 1 and 2 of the Next.js quickstart create one.
  • An HTTPS host you control that can serve one JSON file publicly. Part 3 uses it. Any static file host works if it serves the file as step 7 describes: status 200, application/json and no redirect. A localhost URL cannot work, because Timonier fetches the file from its own servers.

Part 1 — turn on assistant sign-in

1. Create an app

From the project's apps list, create a new app. Fill in Display name, Slug and Redirect URI 1. The form requires one redirect URI, for example http://localhost:3000/callback. Confirm, then save your credentials.

2. Set your server's address

Open the app's page. In the Assistant sign-in card, set MCP server resource URI to http://localhost:3007/mcp, then click Save. The status reads On.

3. Copy the issuer

Open the app's Integration tab and copy Issuer. Step 5 needs it.

Part 2 — run the sample server

4. Save the server

Save this as server.mjs:

// Sample MCP server for the Timonier MCP quickstart: protected-resource metadata,
// a 401 challenge, EdDSA access-token validation, and one tool over Streamable HTTP.

import { createServer } from "node:http";
import { createPublicKey, verify } from "node:crypto";

const ISSUER = process.env.TIMONIER_ISSUER;
if (!ISSUER) {
  console.error("Set TIMONIER_ISSUER to your app's issuer.");
  process.exit(1);
}

const PORT = 3007;
const ORIGIN = `http://localhost:${PORT}`;
const RESOURCE = `${ORIGIN}/mcp`;
const METADATA_PATH = "/.well-known/oauth-protected-resource/mcp";
const METADATA_URL = `${ORIGIN}${METADATA_PATH}`;

const keys = new Map();
const b64 = (s) => Buffer.from(s, "base64url");

async function keyFor(kid) {
  if (!keys.has(kid)) {
    const res = await fetch(`${ISSUER}/.well-known/jwks.json`);
    if (!res.ok) throw new Error(`jwks ${res.status}`);
    const { keys: jwks } = await res.json();
    keys.clear();
    for (const jwk of jwks) {
      if (jwk.kty === "OKP" && jwk.crv === "Ed25519") {
        keys.set(jwk.kid, createPublicKey({ key: jwk, format: "jwk" }));
      }
    }
  }
  return keys.get(kid);
}

async function validate(header) {
  const m = /^Bearer (\S+)$/.exec(header ?? "");
  if (m === null) return null;
  const [h, p, s, extra] = m[1].split(".");
  if (s === undefined || extra !== undefined) return null;
  try {
    const head = JSON.parse(b64(h).toString());
    if (head.alg !== "EdDSA") return null;
    const key = await keyFor(head.kid);
    if (key === undefined || !verify(null, Buffer.from(`${h}.${p}`), key, b64(s))) return null;
    const claims = JSON.parse(b64(p).toString());
    const accepted =
      claims.iss === ISSUER &&
      claims.aud === RESOURCE &&
      typeof claims.exp === "number" &&
      Number.isFinite(claims.exp) &&
      claims.exp > Date.now() / 1000;
    return accepted ? claims : null;
  } catch {
    return null;
  }
}

function send(res, status, body, headers = {}) {
  res.writeHead(status, { "Content-Type": "application/json", ...headers });
  res.end(body === undefined ? undefined : JSON.stringify(body));
}

function rpc(claims, msg) {
  const reply = (result) => ({ jsonrpc: "2.0", id: msg.id, result });
  switch (msg.method) {
    case "initialize":
      return reply({
        protocolVersion: "2025-06-18",
        capabilities: { tools: {} },
        serverInfo: { name: "timonier-sample-mcp", version: "0.0.1" },
      });
    case "tools/list":
      return reply({
        tools: [
          {
            name: "whoami",
            description: "Returns the signed-in subject and the client that holds the token.",
            inputSchema: { type: "object", properties: {} },
          },
        ],
      });
    case "tools/call":
      if (msg.params?.name !== "whoami") {
        return { jsonrpc: "2.0", id: msg.id, error: { code: -32602, message: "unknown tool" } };
      }
      return reply({
        content: [{ type: "text", text: JSON.stringify({ sub: claims.sub, client_id: claims.client_id }) }],
      });
    default:
      return { jsonrpc: "2.0", id: msg.id, error: { code: -32601, message: "method not found" } };
  }
}

const readBody = async (req) => {
  const chunks = [];
  for await (const c of req) chunks.push(c);
  return Buffer.concat(chunks).toString();
};

const server = createServer(async (req, res) => {
  let path;
  try {
    path = new URL(req.url, ORIGIN).pathname;
  } catch {
    return send(res, 400, { error: "bad_request" });
  }
  if (path === METADATA_PATH) {
    return send(res, 200, {
      resource: RESOURCE,
      authorization_servers: [ISSUER],
      bearer_methods_supported: ["header"],
    });
  }
  if (path !== "/mcp") return send(res, 404, { error: "not_found" });
  if (req.headers.origin !== undefined) return send(res, 403, { error: "forbidden_origin" });
  if (req.method !== "POST") return send(res, 405, { error: "method_not_allowed" }, { Allow: "POST" });

  const claims = await validate(req.headers.authorization);
  if (claims === null) {
    return send(res, 401, { error: "invalid_token" }, {
      "WWW-Authenticate": `Bearer resource_metadata="${METADATA_URL}"`,
    });
  }
  let msg;
  try {
    msg = JSON.parse(await readBody(req));
  } catch {
    return send(res, 400, { jsonrpc: "2.0", id: null, error: { code: -32700, message: "parse error" } });
  }
  if (typeof msg !== "object" || msg === null || Array.isArray(msg) || typeof msg.method !== "string") {
    return send(res, 400, { jsonrpc: "2.0", id: null, error: { code: -32600, message: "invalid request" } });
  }
  if (msg.id === undefined) return send(res, 202);
  return send(res, 200, rpc(claims, msg));
});

server.listen(PORT, "127.0.0.1", () => {
  console.log(`Listening on ${ORIGIN}`);
});

5. Start it

Put the issuer from step 3 in place of the placeholder and start the server. Leave it running.

TIMONIER_ISSUER='<your-issuer>' node server.mjs

6. Check the challenge

In a second terminal, call the server without a token:

curl -i -X POST http://localhost:3007/mcp

The response is 401 with the header WWW-Authenticate: Bearer resource_metadata="http://localhost:3007/.well-known/oauth-protected-resource/mcp". An MCP client reads that URL to find your platform.

The sample checks requests to /mcp in two ways. A request that carries an Origin header gets 403. A request without Origin, such as curl's, still needs a valid bearer token. The protected-resource metadata route answers without these checks. The MCP Streamable HTTP transport requires a server to validate Origin to prevent DNS rebinding attacks.

Part 3 — publish the Inspector's metadata document

7. Host the document

Save this JSON and serve it from an HTTPS URL you control. Put that URL in place of the placeholder:

{
  "client_id": "<your-metadata-url>",
  "client_name": "MCP Inspector",
  "redirect_uris": ["http://localhost:6274/oauth/callback"],
  "grant_types": ["authorization_code", "refresh_token"],
  "response_types": ["code"],
  "token_endpoint_auth_method": "none"
}

Timonier fetches the document from that URL, and it refuses the document unless all of these hold:

  • The URL uses HTTPS, its host is a domain name, and its path is not /.
  • The response has status 200 and Content-Type: application/json.
  • The response is not a redirect.
  • The document is at most 5,120 bytes.
  • client_id in the document equals the URL it was fetched from.

Timonier caches the document for at least 5 minutes, and for 1 hour when the response has no Cache-Control: max-age. A change you make to the document may take that long to show up.

Check that the URL answers correctly:

curl -sS -o /dev/null -w '%{http_code} %{content_type}\n' '<your-metadata-url>'

Expect 200 application/json. curl may print media-type parameters, for example application/json; charset=utf-8, and that is fine.

Part 4 — connect the MCP Inspector

8. Start the Inspector

npx @modelcontextprotocol/inspector@2.16.0 --web

The Inspector prints a link that ends in ?MCP_INSPECTOR_API_TOKEN= and a token. Open it with localhost in place of 127.0.0.1, so the address matches the redirect_uris in your document.

9. Add your server

Open Client settings, then OAuth Client ID Metadata Document. Tick Use Client ID Metadata Document, enter <your-metadata-url>, and click Close.

Click Add Servers, then + Add manually, and fill in:

  • Server ID — sample
  • Transport — streamable-http
  • URL — http://localhost:3007/mcp

Click Add.

10. Sign in and approve

Turn on the connect switch for sample. The Inspector sends you to your app's sign-in page, which names MCP Inspector. Enter your email, then open the emailed link in the same browser and click Continue sign-in.

The consent page warns that sign-in returns to a program on this device. Click Allow access.

11. Call the tool

In the Inspector, open Tools, select whoami, and click Execute Tool. The result shows sub, the person's ID, and client_id, your metadata URL.

12. See the assistant in the dashboard

Open Assistants in the project navigation. The list shows MCP Inspector with one connected person.

Going to production

  • Set MCP server resource URI to your server's https address.
  • Validate iss, aud and exp on every token, as the sample does. Timonier signs access tokens with EdDSA and publishes the keys at {issuer}/.well-known/jwks.json.
  • Access tokens last 60 seconds.