Blog ·

OAuth for your MCP server without writing an authorization server

Put an MCP server in front of your product and the MCP authorization specification gives you half a job. It says "a protected MCP server acts as an OAuth 2.1 resource server", which means your server checks access tokens. The other half goes elsewhere: "the authorization server is responsible for interacting with the user (if necessary) and issuing access tokens." Something has to sign the person in, ask whether the assistant may act for them, and mint the token. The specification doesn't make your MCP server do that.

Timonier can be that something. You turn on assistant sign-in for an app by giving it your MCP server's address, and Timonier then acts as the OAuth authorization server for that server. People sign in on your app's sign-in page and approve the assistant on a consent screen. The assistant gets a token bound to your server's address. The MCP quickstart runs a sample server on your machine and walks through all of it.

One limit before the details, because it's the one that decides whether you keep reading. The MCP Inspector, version 2.16.0, is the only client we have tested. We won't tell you it works with the assistant your users run, because we haven't seen it do so. If you need a particular assistant, tell us which one before you build on this.

The half you'd otherwise write

The resource server is the small half. Fetch a key set, verify a signature, compare three claims. The quickstart's sample server does exactly that.

The authorization server is where the work is, and the part we'd least want to write ourselves is deciding who the client is. The program asking for a token is one you've probably never heard of, installed by one of your users, and you have no prior relationship with its author. Any scheme where you register clients up front assumes you know in advance who will show up, and with assistants you don't.

Assistants register nothing

Assistants identify themselves with a Client ID Metadata Document, so you register nothing. The client ID is an HTTPS URL, and that URL serves a JSON document with the client's metadata. The format is an IETF Internet-Draft, not a standard, and we'd rather you hear that from us than find it in a review.

Timonier fetches that document itself, which means it fetches a URL that someone else chose. 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, byte for byte.

The last rule is the one that carries the weight. A document can only speak for the URL it was served from, so nobody can publish a document on their own host that claims to be a client living somewhere else.

A practical consequence for local development: the document can't live on localhost, since the host has to be a domain name. You need an HTTPS host that can serve one JSON file, and the quickstart says what it has to return.

Timonier caches a fetched document for at least 5 minutes, and for 1 hour when the response carries no Cache-Control: max-age. A typo you fix in the document can take that long to go away.

What the person sees

The sign-in page names the assistant. After sign-in, a consent page asks the person to allow or deny it. Deny sends the assistant back to its redirect with error=access_denied.

When sign-in returns to a program on the person's own device, the consent page says so and shows the device address, such as 127.0.0.1:6274. That's the screen we most want people to read. A desktop program is the case where the client ID URL tells a person the least about what is actually going to receive the result, and a plain sentence on the page is the cheapest place to say that.

On the operator side, the dashboard's Assistants page lists each assistant with the number of people connected to it and when it was last used.

What your server still checks

Access tokens are signed with EdDSA, and Timonier publishes the keys at {issuer}/.well-known/jwks.json. Each token carries iss, aud and exp, and aud is your MCP server's resource URI. Your server validates all three on every request. Your protected-resource metadata lists your app's issuer under authorization_servers, which is how a client finds where to sign in.

aud is what binds a token to your server. A token issued for another app's MCP server carries that server's address, and a server that checks aud refuses it with a 401. A server that skips the aud check accepts tokens meant for other servers.

Access tokens last 60 seconds. Your server checks them locally against the published keys, and a token that leaks stops working within a minute.

There's one check the authorization server can't do for you at all. The MCP Streamable HTTP transport requires your server to validate the Origin header on incoming connections, which guards against DNS rebinding, and to answer 403 when the header is present and invalid. That applies whichever authorization server you pick. The quickstart's sample has one strict way of doing it.

For development, the resource URI can be plain http on localhost, 127.0.0.1 or [::1], so http://localhost:3007/mcp works. Anywhere else it has to be https.

The MCP quickstart connects the MCP Inspector to a sample MCP server running on your machine.

← All posts