AI agents (MCP)
Kantoor runs a Model Context Protocol server so an AI assistant that a
person controls can work in Kantoor as that person. The MCP endpoint, its OAuth
authorization server, the tool catalogue, the per-call audit and the
administration pages are one feature: Kantoor.MCP.
This page is for an operator. The person's own page is in the manual: AI
agents (kantoor/ai-agents.md in the manuals repository).
What it is
- Transport. Stateless Streamable HTTP.
POST /mcpcarries one JSON-RPC 2.0 object and is answered with one JSON object (or202for a notification).GETandDELETE /mcpanswer405: the server never opens a server-initiated stream and never asks the client a question. - Protocol versions. The server understands
2025-03-26,2025-06-18,2025-11-25and2026-07-28, and answersinitializewith the client's version when it knows it, else the newest. - Methods.
initialize,notifications/initialized,ping,tools/list,tools/call;resources/listandprompts/listanswer empty lists. Anything else is JSON-RPC-32601. - Clients. Claude.ai connectors, Claude Code, ChatGPT, Cursor, VS Code and any other MCP client that supports OAuth (the specification's client registration and PKCE) connect. The server was built so that ChatGPT, which cannot send a custom key header, works through OAuth.
Authentication: design B
Kantoor is its own OAuth 2.1 authorization server for the MCP endpoint. Authentik is only the sign-in; it issues no MCP token and is not in the request path of a tool call. This binds a token to a person, to this endpoint and to the scopes the person approved, which design A (Authentik as the authorization server) cannot do for ChatGPT.
| Method | Path | What |
|---|---|---|
| GET | /.well-known/oauth-protected-resource | RFC 9728 metadata for /mcp |
| GET | /.well-known/oauth-protected-resource/mcp | the same document at the resource path |
| GET | /.well-known/oauth-authorization-server | RFC 8414 metadata |
| GET | /oauth/authorize | the consent page |
| POST | /oauth/authorize | approve or deny |
| DELETE | /oauth/authorize | deny |
| POST | /oauth/token | authorization code + PKCE; refresh |
| POST | /oauth/revoke | RFC 7009 |
| POST | /oauth/register | RFC 7591 dynamic registration |
| GET | /oauth/login | starts the Shiloh-account sign-in for a consent request |
A request without a usable token gets:
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="MCP", resource_metadata="https://<host>/.well-known/oauth-protected-resource/mcp"- Clients are public: no client secret. PKCE S256 is required.
- Registration is Client ID Metadata Documents (an
httpsclient_idwhose JSON document is fetched and validated) or dynamic registration. - The token is bound to the MCP URL (RFC 8707
resource). A token for another audience is refused. - Access tokens last one day; refresh tokens rotate. A replayed refresh token ends its whole family.
- Scopes:
read,write,admin.adminis only granted when the person is an administrator, both on the consent screen and on every request. - Tokens are opaque and stored as SHA-256 digests. Revoking ends the access and the refresh token at once.
- The person, their role, their account state and the sign-in behind the approval are re-read on every call. Disabling an account, signing out everywhere, losing the admin role and disconnecting the client all take effect on the next request.
The tool catalogue
Kantoor.MCP.Registry is the single source of truth: a name, a summary, a
JSON schema, a scope, a minimum role, a destructive flag, a pagination flag, an
optional preview and a dispatch function that calls the same context function
the web interface calls.
| Group | What |
|---|---|
account | the signed-in person, people, roles, app passwords |
mailboxes | mailboxes, quotas, members, kind |
mail-content | folders, message rows, one message, search — only in an attached mailbox |
domains | domains, aliases, catch-all, DNS publication to Salt |
calendars | calendars, events, invitations |
tasks | tasks and task lists (the board is the same tasks by status) |
contacts | contacts and address books |
bookings | the booking page, its appointments and free slots |
chat | rooms, messages, search, membership |
support | widget sites, conversations, the support team |
mail-rules | filters, away reply, forwarding, sending identities |
notifications | push rules, sharing |
admin | service state, held mail, API keys, audit, MCP settings and connections |
An operation runs as the signed-in person with the person's own permissions. Two restrictions are extra to the context functions:
- Mail content (
mail-content) is only reachable in a mailbox with a grant for that person. An administrator who is not a member of a mailbox cannot read its mail through MCP, although the administration tools still see the mailbox itself. - An
adminoperation needs both the token'sadminscope and an administrator account.
Shape and discovery
mcp_settings.tool_mode chooses what tools/list returns:
named— one tool per permitted operation;facade— onlysearch_tools,fetch_tool_definitionsandinvoke_tool;both(default) — both.
search_tools finds operations and returns their full schemas; invoke_tool
runs one by name. A named tool and invoke_tool run the same registry entry.
allowed_groups limits the registry domains a client may use; an empty list
allows all. The switch itself (enabled) is off until an administrator turns
it on; while it is off every credential is refused with 403 mcp_disabled.
Destructive operations
Deleting, sending, publishing DNS, provisioning, creating a credential and
sending an invitation are destructive: true. Without confirm: true the call
returns a normal result:
{"dry_run": true, "would": "This would delete box@example.com and its 12 messages …", "requires_confirm": true}confirm is removed before the operation runs. The preview reads the target
with the same authorization as the call, so a person who may not see it gets
the ordinary not-found answer.
Audit
mcp_tool_calls holds one row per call: person, client, operation, status
(ok, denied, dry_run, error), error sentence, redacted arguments and
duration. Secret-looking keys and credential-shaped values are hidden, long
strings are cut and the stored arguments are capped at 4 KB. An administrator
reads recent rows on Administration → AI agents (MCP) and the whole log with
the list_mcp_tool_calls operation.
Settings and connections
- Administration → AI agents (MCP) (
/admin/mcp): the installation switch, the tool shape, the allowed groups, every connection, the last tool calls. - Settings → AI agents (
/settings/ai-agents): the person's own connections and disconnecting one. - An administrator sees everyone's connections; nobody sees another installation's (there is one). Disconnecting a client revokes every token of that client for that person, or for everyone when an administrator leaves the person out.
The switch and its shape live in mcp_settings; the OAuth rows live in
oauth_clients, oauth_authorization_codes and oauth_tokens; the audit in
mcp_tool_calls.
Configuration
| Variable | Meaning | Default |
|---|---|---|
KANTOOR_OAUTH_ISSUER | the issuer clients are told; set it in production | the endpoint URL |
KANTOOR_MCP_RESOURCE_URL | the audience, exactly the MCP URL | <issuer>/mcp |
Set both in production so a proxy alias cannot change the issuer or the
audience a client was told about. The sign-in reuses the existing OIDC client
(OIDC_*); no new Authentik provider is needed. If OIDC is not configured,
/oauth/login answers 503 and no client can connect.
Limits
| Request body | 1 MiB at /mcp; 32 KiB at the OAuth endpoints |
| Calls | 120 a minute per access token (fixed window in rate_counters) |
| Dynamic registration | 20 an hour per address |
| Authorization requests | 120 a minute per address |
| Lists | limit default 50, at most 200; offset |
There is no separate statement timeout: operations are page-bounded and run against the same Repo pool as the web interface.
Testing it
# The public documents
curl -s https://<host>/.well-known/oauth-authorization-server | jq
curl -s https://<host>/.well-known/oauth-protected-resource/mcp | jq
# A refusal names the metadata
curl -si -X POST https://<host>/mcp -H 'content-type: application/json' \
-d '{"jsonrpc":"2.0","id":1,"method":"ping"}' | head
For an end-to-end check, connect a real client (Claude Code
claude mcp add --transport http kantoor https://<host>/mcp, a Claude.ai
custom connector, or ChatGPT) and approve it with a real account. The test
suite covers the protocol, the OAuth flow (registration, PKCE, consent, code
exchange, rotation, replay, revocation), the role and scope refusals, the
dry-run/confirm rule for every destructive operation and the mail-content
restriction.
Known limitations
- A token is bound to this installation and its scopes; there is no per-mailbox audience.
- The consent page is server-rendered and does not share the app's styles.
- A refresh token has no absolute lifetime; it ends when the connection is disconnected or the person's sign-in is cut off.
- The MCP endpoint has no server-initiated stream, so a client cannot be asked
a question mid-call. Every confirmation is a separate
confirm: truecall.