AFFiNE
STDIOMCP server for AFFiNE workspace and document management with 30+ tools
MCP server for AFFiNE workspace and document management with 30+ tools
A Model Context Protocol (MCP) server that integrates with AFFiNE (self‑hosted or cloud). It exposes AFFiNE workspaces and documents to AI assistants over stdio.
New in v1.2.2: Fixed CLI binary to always run via Node (no shell mis-execution). Startup remains non-blocking for email/password login by default; set
AFFINE_LOGIN_AT_START=syncto block at startup.
# Global install (recommended) npm i -g affine-mcp-server # Or run ad‑hoc via npx (no install) npx -y -p affine-mcp-server affine-mcp -- --version
The package installs a CLI named affine-mcp that runs the MCP server over stdio.
Note: From v1.2.2 the CLI wrapper (bin/affine-mcp) ensures Node runs the ESM entrypoint, preventing shell from misinterpreting JS.
Configure via environment variables (shell or app config). .env files are no longer recommended.
AFFINE_BASE_URLAFFINE_API_TOKEN | AFFINE_COOKIE | AFFINE_EMAIL + AFFINE_PASSWORDAFFINE_GRAPHQL_PATH (default /graphql), AFFINE_WORKSPACE_ID, AFFINE_LOGIN_AT_START (async default, sync to block)Authentication priority:
AFFINE_API_TOKEN → 2) AFFINE_COOKIE → 3) AFFINE_EMAIL + AFFINE_PASSWORDAdd to your Claude Desktop configuration:
~/Library/Application Support/Claude/claude_desktop_config.json%APPDATA%\Claude\claude_desktop_config.json~/.config/Claude/claude_desktop_config.json{ "mcpServers": { "affine": { "command": "affine-mcp", "env": { "AFFINE_BASE_URL": "https://your-affine-instance.com", "AFFINE_EMAIL": "[email protected]", "AFFINE_PASSWORD": "secret!", "AFFINE_LOGIN_AT_START": "async" } } } }
Tips
AFFINE_COOKIE or AFFINE_API_TOKEN for zero‑latency startup.! (zsh history expansion), wrap it in single quotes in shells or use the JSON config above.Register the MCP server with Codex:
Global install path (fastest)
npm i -g affine-mcp-servercodex mcp add affine --env AFFINE_BASE_URL=https://your-affine-instance.com --env '[email protected]' --env 'AFFINE_PASSWORD=secret!' --env AFFINE_LOGIN_AT_START=async -- affine-mcpUse npx (no global install)
codex mcp add affine --env AFFINE_BASE_URL=https://your-affine-instance.com --env '[email protected]' --env 'AFFINE_PASSWORD=secret!' --env AFFINE_LOGIN_AT_START=async -- npx -y -p affine-mcp-server affine-mcpToken or cookie (no startup login)
codex mcp add affine --env AFFINE_BASE_URL=https://... --env AFFINE_API_TOKEN=... -- affine-mcpcodex mcp add affine --env AFFINE_BASE_URL=https://... --env "AFFINE_COOKIE=affine_session=...; affine_csrf=..." -- affine-mcpNotes
affineaffine-mcpAFFINE_BASE_URL + one auth method (AFFINE_API_TOKEN | AFFINE_COOKIE | AFFINE_EMAIL/AFFINE_PASSWORD)list_workspaces – list all workspacesget_workspace – get workspace detailscreate_workspace – create workspace with initial documentupdate_workspace – update workspace settingsdelete_workspace – delete workspace permanentlylist_docs – list documents with paginationget_doc – get document metadatasearch_docs – search documents by keywordrecent_docs – list recently updated documentspublish_doc – make document publicrevoke_doc – revoke public accesscreate_doc – create a new document (WebSocket)append_paragraph – append a paragraph block (WebSocket)delete_doc – delete a document (WebSocket)list_comments, create_comment, update_comment, delete_comment, resolve_commentlist_histories, recover_doccurrent_user, sign_in, update_profile, update_settingslist_access_tokens, generate_access_token, revoke_access_tokenlist_notifications, read_notification, read_all_notificationsupload_blob, delete_blob, cleanup_blobsapply_doc_updates – apply CRDT updates to documentsgit clone https://github.com/dawncr0w/affine-mcp-server.git cd affine-mcp-server npm install npm run build # Run directly node dist/index.js # Or expose as a global CLI for Codex/Claude without publishing npm link # Now use `affine-mcp` like a global binary
Authentication
affine_session, affine_csrf) from the browser DevTools after loginAFFINE_LOGIN_AT_START=sync only if needed.Connection
AFFINE_BASE_URL is reachable/graphql.env with secretsbin/affine-mcp), preventing shell mis-execution.env file no longer recommendedAFFINE_LOGIN_AT_START env (async default, sync to block at startup)create_doc, append_paragraph, delete_doc (create/edit/delete now supported)affine_* and non‑prefixed namesaffine-mcp for easy npm i -g usageContributions are welcome!
MIT License - see LICENSE file for details
For issues and questions:
dawncr0w - GitHub