Skip to content

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.

  • A server configured to start, see Getting started. The token commands read the same configuration as sklad serve, so set the same SKLAD_* variables or sklad.toml.
  1. Create a token with a name and its scopes:

    Terminal window
    sklad token create --name laptop --scopes kb:read,kb:write

    The 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 at auth_db_path (default state/auth.sqlite, relative to the working directory).

  2. List tokens. Secrets are never shown:

    Terminal window
    sklad token list
    ID NAME SCOPES CREATED LAST USED STATUS
    37ar9dao ro kb:read 2026-12-04 14:01 never active
  3. 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

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"}

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.

  1. 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 scopes kb:read, kb:write, and kb:admin.

  2. Configure sklad with the issuer and that audience:

    Terminal window
    SKLAD_OAUTH__ENABLED=true
    SKLAD_OAUTH__ISSUER=https://auth.example.com/oidc
    SKLAD_OAUTH__AUDIENCE=https://kb.example.com/mcp

    The rest is derived. jwks_uri defaults to <issuer>/.well-known/jwks.json, resource_url to the audience, resource_metadata_url to https://kb.example.com/.well-known/oauth-protected-resource/mcp, and documentation_url to <resource_url>/docs/auth. With OAuth enabled, the server refuses to start while any of these is empty and names the missing fields.

  3. Restart the server and check discovery:

    Terminal window
    curl -s https://kb.example.com/.well-known/oauth-protected-resource/mcp

    The 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.

  4. Add the connector in the client, pointing at https://kb.example.com/mcp. The client completes the OAuth flow in the browser.

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 kid in the cached JWKS, refreshing the cache when the key is unknown (with a cooldown between attempts) and in the background every jwks_refresh_seconds (default 900, allowed 60 to 86400);
  • accepts only the asymmetric algorithms RS256, RS384, RS512, PS256, PS384, PS512, ES256, ES384, and EdDSA;
  • requires iss to equal the issuer, aud to contain the audience, and exp and nbf to hold within 10 seconds of leeway;
  • reads the space-separated scope claim 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.

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.

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.