Authenticate MCP clients
Every request to /mcp needs an Authorization: Bearer … header. sklad accepts two kinds of bearer: tokens it mints itself (kbsk_…), for clients you configure by hand such as Claude Code, and OAuth 2.1 access tokens (JWTs) issued by an external identity provider, for hosted connectors such as Claude.ai. Both work at the same time.
Prerequisites
Section titled “Prerequisites”- A server configured to start, see Getting started. The token commands read the same configuration as
sklad serve, so set the sameSKLAD_*variables orsklad.toml.
Manage bearer tokens
Section titled “Manage bearer tokens”-
Create a token with a name and its scopes:
Terminal window sklad token create --name laptop --scopes kb:read,kb:writeThe secret is printed once, in the form
kbsk_<8-character id>_<secret>. Only an Argon2id hash of the secret is stored, in the token database atauth_db_path(defaultstate/auth.sqlite, relative to the working directory). -
List tokens. Secrets are never shown:
Terminal window sklad token listID NAME SCOPES CREATED LAST USED STATUS37ar9dao ro kb:read 2026-12-04 14:01 never active -
Revoke a token by its 8-character ID. Every request checks the store, so the next request with that token gets HTTP 401:
Terminal window sklad token revoke 37ar9dao
Choose scopes
Section titled “Choose scopes”Each MCP tool needs exactly one scope, and scopes do not imply each other: a token with only kb:write cannot read. Grant kb:read,kb:write for a client that reads and writes.
| Scope | Tools |
|---|---|
kb:read |
kb_ping, kb_search, kb_read, kb_grep, kb_list, kb_kinds, kb_next, kb_backlinks, kb_related, kb_git_log |
kb:write |
kb_create, kb_edit, inbox_capture, journal_append, share_create, share_list, share_revoke |
kb:admin |
kb_health, archive_move, archive_restore |
A request without a valid token gets HTTP 401 with WWW-Authenticate: Bearer realm="sklad". A valid token without the tool’s scope gets JSON-RPC error -32001:
{"code":-32001,"message":"forbidden: tool inbox_capture requires scope kb:write"}Enable OAuth 2.1
Section titled “Enable OAuth 2.1”Hosted connectors such as Claude.ai need OAuth: they discover an authorization server, register a client, and present the access token they get. sklad is only the resource server here. It validates JWTs and never issues them, so you need an identity provider that supports OAuth 2.1 with PKCE and Dynamic Client Registration. The reference deployment in deploy/docker/ runs Logto.
-
In the identity provider, create an API resource whose identifier is the public URL of the MCP endpoint, such as
https://kb.example.com/mcp, with the scopeskb:read,kb:write, andkb:admin. -
Configure sklad with the issuer and that audience:
Terminal window SKLAD_OAUTH__ENABLED=trueSKLAD_OAUTH__ISSUER=https://auth.example.com/oidcSKLAD_OAUTH__AUDIENCE=https://kb.example.com/mcpThe rest is derived.
jwks_uridefaults to<issuer>/.well-known/jwks.json,resource_urlto the audience,resource_metadata_urltohttps://kb.example.com/.well-known/oauth-protected-resource/mcp, anddocumentation_urlto<resource_url>/docs/auth. With OAuth enabled, the server refuses to start while any of these is empty and names the missing fields. -
Restart the server and check discovery:
Terminal window curl -s https://kb.example.com/.well-known/oauth-protected-resource/mcpThe response lists the resource, the issuer under
authorization_servers, and the three scopes. The same document is also served at/.well-known/oauth-protected-resource. -
Add the connector in the client, pointing at
https://kb.example.com/mcp. The client completes the OAuth flow in the browser.
How sklad validates a JWT
Section titled “How sklad validates a JWT”A bearer that starts with kbsk_ goes to the token store; anything else is treated as a JWT. sklad then:
- looks up the token’s
kidin the cached JWKS, refreshing the cache when the key is unknown (with a cooldown between attempts) and in the background everyjwks_refresh_seconds(default 900, allowed 60 to 86400); - accepts only the asymmetric algorithms RS256, RS384, RS512, PS256, PS384, PS512, ES256, ES384, and EdDSA;
- requires
issto equal the issuer,audto contain the audience, andexpandnbfto hold within 10 seconds of leeway; - reads the space-separated
scopeclaim into the same scopes bearer tokens use.
A 401 from the OAuth path also carries resource_metadata="<resource_metadata_url>" in WWW-Authenticate, so a client without configuration can find the authorization server.
Revoking OAuth access
Section titled “Revoking OAuth access”sklad does not ask the identity provider whether a JWT is still valid, so a JWT stays usable until it expires. Keep access tokens short-lived in the identity provider, and to cut off a user, disable them there and wait out the token lifetime. Bearer tokens, by contrast, are revoked immediately.
Troubleshooting
Section titled “Troubleshooting”| Symptom | Likely cause |
|---|---|
| A fresh JWT gets 401 | Its kid is not in the JWKS, or the signature is invalid. Check whether the identity provider rotated its keys. |
| JWTs fail after an identity provider change | iss or aud no longer matches the configuration. |
The 401 has no resource_metadata |
OAuth is disabled: oauth.enabled is false. |
See also the sklad token reference.