Sign your people in¶
Your server vouches for each person with a pass: a short JWT signed with your private key. Klaris checks it
and gives back an MCP token for that person. The token goes on every MCP call as
Authorization: Bearer <token>. Nobody clicks through a Klaris sign-in, and Klaris never sees your people's
passwords.
This follows the OAuth 2.0 JWT bearer grant (RFC 7523).
The pass¶
A JWT signed with RS256 (no other algorithm is accepted), with the kid of your key in its header.
| Claim | What it holds | |
|---|---|---|
iss |
required | Your issuer, exactly as set up in Klaris. |
aud |
required | The audience Klaris gave you, exactly. |
sub |
required | Your id for the person, up to 255 characters. It must never change for them: Klaris finds the person by it. |
exp |
required | When the pass expires: at most 10 minutes ahead. Make a pass just before you swap it. |
jti |
A new random id each time. Each pass works once: a second swap with the same pass is refused. (Without jti, the whole pass is what counts as used.) |
|
iat |
When you made it. | |
email |
required the first time | The person's email. The first pass for a person adds them to the workspace with it. |
name |
Their name, as Klaris shows it. | |
role |
Their role on your side, by name. Your role rules turn it into a Klaris role. May also be an object {"id": …, "name": …}, or role_id. |
|
department_code |
Optional, kept with the person: their department's code on your side. May also be sent as department: {"code": …}. |
email, name, role and department_code may also sit together under one claim,
https://klarislabs.com/claims, if you keep your own claims namespaced.
Klaris allows 60 seconds of clock difference between your server and ours.
Swap it for a token¶
POST https://app.klarislabs.com/mcp/token
Content-Type: application/x-www-form-urlencoded
grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer
&assertion=<the pass>
&resource=https://app.klarislabs.com/mcp
resourceishttps://app.klarislabs.com/mcp. A token is good for that MCP server only, and nothing else in Klaris.expires_inis in seconds. A Klaris admin sets the length for your app: an hour unless changed, between 5 minutes and 24 hours.- There is no refresh token. When the token runs out, sign a new pass and swap again.
- Keep one token per person and reuse it until about a minute before it runs out. Don't swap a pass for every call: up to 600 swaps a minute are accepted from one address.
The Quickstart has a token cache in Python and TypeScript.
When a swap or token is refused¶
| You get | It means | Do this |
|---|---|---|
400 invalid_grant from /mcp/token |
The pass was refused: see the list below. | Don't retry in a loop. Ask your Klaris admin: they see the exact reason in Klaris. |
400 invalid_target from /mcp/token |
resource isn't Klaris's MCP address. |
Send https://app.klarislabs.com/mcp. |
429 slow_down from /mcp/token |
More than 600 swaps a minute from one address. | Reuse tokens; slow down. |
401 from /mcp |
The token ran out, or was ended (see below). | Sign a new pass and swap once. If that is refused too, stop for that person. |
The reply to a refused pass doesn't say why, on purpose. Common reasons:
- a signature that doesn't match your published key, or an unknown
kid; - a pass that has expired, lasts more than 10 minutes, or was already used;
- an
issoraudthat doesn't match; - a person whose role matches no role rule, when the workspace lets in nobody else;
- an email that already belongs to another Klaris workspace, or to an account someone already signs in to another way (Klaris won't hand over an existing account on an email alone);
- the person was switched off in Klaris;
- your app, its MCP switch, or the Klaris agent was switched off.
A token stops working at once (401) when the person is switched off or moved to another workspace, when your
app or its MCP switch is switched off, or when the workspace switches off MCP apps or the Klaris agent.
Keys¶
Klaris checks each pass against your public key, found by the pass's kid.
A key address (recommended). Publish your keys as a JWKS page ({"keys": [...]}) at an https address.
Klaris fetches it, keeps it for an hour, and fetches it again straight away when a pass names a kid it hasn't
seen. The page must answer within 3 seconds and be under 1 MB. Redirects aren't followed, and the address must be
on the public internet.
Pasted keys. If you can't publish a page, a Klaris admin can paste it in. Then every key change needs them.
Only RSA keys for RS256. Never put a private key on the page: Klaris refuses one.
Changing keys¶
- Make a new key with a new
kid, and publish it beside the old one. - Start signing with the new key. Klaris picks it up the first time it sees its
kid. - Once no pass signed with the old key can still be in flight (10 minutes is enough), take it off the page. Tokens already swapped keep working: they don't depend on your key.
A sandbox beside production¶
Your app can sign passes from more than one place, for example a sandbox and production, each with its own issuer and key. A Klaris admin adds each extra place under Other Places It Signs From on your partner app.
- Every place shares the same audience, role rules and switches.
- A person arriving from either place is the same Klaris person, with the same chats, as long as you use the
same
subfor them in both. Give test people their own ids if you don't want that. - A pass is checked against the key of the place it says it's from (
iss), so a sandbox pass signed with the production key is refused. - Taking a place off refuses its passes from then on. Tokens it already got last until they run out.
The sandbox reaches the same Klaris workspace and data as production. For a separate test copy, ask for a separate test workspace.
People and roles¶
- The first pass for a
subadds the person to the workspace, by theiremail. After that, Klaris finds them bysub, even if their email changes. - Roles: each pass's
roleis matched against your role rules (by name or id, ignoring case). The first rule that matches gives the Klaris role. With no match, the person gets the workspace's "everyone else" role, or is refused if there isn't one. - With role rules, your side decides: a person's Klaris role follows the role in their latest pass. A change on your side reaches Klaris at their next swap.
- What a role can see, and what needs a yes, is set by the workspace's Klaris admins.
Keep it safe¶
- Sign passes on your server only. Never send a private key or a token to a browser or a phone app.
- Make a new pass for each swap; never store or reuse passes.
- Treat MCP tokens as secrets: they act as the person until they run out.
- Ask your Klaris admin to switch your app off if a key may have leaked, then change keys.