AFFiNE MCP Server provides seamless integration with AFFiNE workspaces and documents through the Model Context Protocol. This server enables AI assistants to interact with self-hosted or cloud AFFiNE instances, offering comprehensive workspace and document management capabilities.
# Clone the repository
git clone https://github.com/dawncr0w/affine-mcp-server.git
cd affine-mcp-server
# Install dependencies
npm install
# Build the TypeScript code
npm run build
Create a .env
file in the project root:
# AFFiNE server URL (required)
AFFINE_BASE_URL=https://your-affine-instance.com
# Authentication (choose one method):
# Option 1: Bearer Token (highest priority)
AFFINE_API_TOKEN=your_personal_access_token
# Option 2: Session Cookie
AFFINE_COOKIE=affine_session=xxx; affine_csrf=yyy
# Option 3: Email/Password (fallback)
[email protected]
AFFINE_PASSWORD=your_password
# Optional settings
AFFINE_GRAPHQL_PATH=/graphql # Default: /graphql
AFFINE_WORKSPACE_ID=workspace-uuid # Default workspace for operations
The server checks for authentication in this order:
AFFINE_API_TOKEN
) - Highest priorityAFFINE_COOKIE
)AFFINE_EMAIL
+ AFFINE_PASSWORD
) - FallbackAdd to your Claude Desktop configuration:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
Linux: ~/.config/Claude/claude_desktop_config.json
{
"mcpServers": {
"affine": {
"command": "node",
"args": ["/path/to/affine-mcp-server/dist/index.js"],
"env": {
"AFFINE_BASE_URL": "https://your-affine-instance.com",
"AFFINE_EMAIL": "[email protected]",
"AFFINE_PASSWORD": "your_password"
}
}
}
}
Add to your Codebase CLI configuration:
{
"affine": {
"command": "node",
"args": ["/path/to/affine-mcp-server/dist/index.js"],
"env": {
"AFFINE_BASE_URL": "https://your-affine-instance.com",
"AFFINE_EMAIL": "[email protected]",
"AFFINE_PASSWORD": "your_password"
}
}
}
list_workspaces
- List all accessible 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 accesslist_comments
- List document commentscreate_comment
- Create new commentupdate_comment
- Update comment contentdelete_comment
- Delete a commentresolve_comment
- Resolve/unresolve commentlist_histories
- View document historyrecover_doc
- Restore to previous versioncurrent_user
- Get current user informationsign_in
- Sign in with email/passwordupdate_profile
- Update user profileupdate_settings
- Update user settingslist_access_tokens
- List personal access tokensgenerate_access_token
- Create new access tokenrevoke_access_token
- Revoke access tokenlist_notifications
- Get notificationsread_notification
- Mark notification readread_all_notifications
- Mark all notifications readupload_blob
- Upload file/blobdelete_blob
- Delete blobcleanup_blobs
- Cleanup deleted blobsapply_doc_updates
- Apply CRDT updates to documents# Run comprehensive tests
node test-comprehensive.mjs
# Test workspace creation
node test-fixed-workspace.mjs
Email/Password fails:
Cookie authentication:
affine_session
cookie after logging inAFFINE_COOKIE
Token authentication:
AFFINE_API_TOKEN
AFFINE_BASE_URL
is accessible/graphql
(default).env
files containing credentialsTo add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "affine" '{"command":"node","args":["/path/to/affine-mcp-server/dist/index.js"],"env":{"AFFINE_BASE_URL":"https://your-affine-instance.com","AFFINE_EMAIL":"[email protected]","AFFINE_PASSWORD":"your_password"}}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"affine": {
"command": "node",
"args": [
"/path/to/affine-mcp-server/dist/index.js"
],
"env": {
"AFFINE_BASE_URL": "https://your-affine-instance.com",
"AFFINE_EMAIL": "[email protected]",
"AFFINE_PASSWORD": "your_password"
}
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"affine": {
"command": "node",
"args": [
"/path/to/affine-mcp-server/dist/index.js"
],
"env": {
"AFFINE_BASE_URL": "https://your-affine-instance.com",
"AFFINE_EMAIL": "[email protected]",
"AFFINE_PASSWORD": "your_password"
}
}
}
}
3. Restart Claude Desktop for the changes to take effect