# HTTP API docwell-server's API is described in [`api/openapi.yaml`](https://github.com/docwell/docwell/blob/main/api/openapi.yaml) (OpenAPI 3.1). It is the source of truth: the web, desktop and mobile apps use clients generated from it. - Base path: `/api/v1`. - Authentication: for scripts and integrations, create an **API token** under *Your account → API tokens* and send it as `Authorization: Bearer dw_…`. A token acts as you, with your access; *read only* tokens can only make `GET` requests, and no token can manage tokens or two-step sign-in. Apps sign in with `POST /api/v1/auth/login` instead and send the returned session token the same way (refresh it with `POST /api/v1/auth/refresh`). Accounts with two-step sign-in answer `401 {"error":"totp_required","challenge":"…"}`; finish with `POST /api/v1/auth/totp/verify {"challenge","code"}`. - Errors are JSON: `{"error": "", "message": "...", "fields": {...}}`, where `fields` holds per-field messages for `validation` errors. - File links (`/api/v1/files/{id}`) also accept `?token=` with a short-lived token from `POST /api/v1/files/token`, because `` tags cannot send headers. Health checks for load balancers: `GET /healthz` (process up) and `GET /readyz` (database reachable). ## MCP `POST /mcp` is a [Model Context Protocol](https://modelcontextprotocol.io) server (Streamable HTTP, JSON responses). Authenticate with an API token. Tools: `list_workspaces`, `list_spaces`, `list_pages`, `search`, `read_page` (Markdown) and `ask` (the workspace's AI, with sources); write tokens also get `create_page` and `update_page` (replace or append Markdown). For example, in an MCP client's configuration: ```json { "mcpServers": { "docwell": { "type": "http", "url": "https://wiki.example.com/mcp", "headers": { "Authorization": "Bearer dw_…" } } } } ``` AI chat answers (`POST /api/v1/ai/sessions/{id}/messages`) and writing actions (`POST /api/v1/workspaces/{id}/ai/write`) stream as server-sent events; see the OpenAPI file for the events. ## Example ```bash TOKEN=$(curl -s -X POST https://wiki.example.com/api/v1/auth/login \ -H 'Content-Type: application/json' \ -d '{"email":"me@example.com","password":"..."}' | jq -r .token) curl -s https://wiki.example.com/api/v1/workspaces -H "Authorization: Bearer $TOKEN" ```