MCP server
Connect AI agents to NextCRM over the Model Context Protocol, with bearer tokens, a tool catalogue and known limits.
NextCRM has a built-in Model Context Protocol server. AI clients such as Claude Code, Claude Desktop or Cursor can list, read and change CRM data through it, with the permissions of the user who owns the token.
Endpoints
The server is one route handler, app/api/mcp/[transport]/route.ts, built with mcp-handler and base path /api/mcp.
| Transport | URL | Notes |
|---|---|---|
| Streamable HTTP | https://<your-host>/api/mcp/mcp | Recommended. Current MCP spec default. |
The server exposes tools only. It has no MCP resources or prompts.
Authentication
Every request needs a personal API token in the Authorization header:
Authorization: Bearer nxtc__<48 hex characters>Create a token in Profile → Developer (/profile?tab=developer). The raw token is shown once. See API tokens for format, limits and revocation.
For each call, getMcpUser() in lib/mcp/auth.ts validates the token, loads the user and their role, and passes both to the tool. Tools apply the same scope rules as the web app. A user token sees only that user's records; a manager or admin token sees everything their role allows.
When NODE_ENV is development and there is no nxtc__ bearer token, the server falls back to the Better Auth session cookie. This makes local testing from a browser session easy. Production always requires a token.
Connect a client
claude mcp add --transport http nextcrm https://<your-host>/api/mcp/mcp \
--header "Authorization: Bearer nxtc__your_token"The Developer tab also offers a SKILL.md download (served from /SKILL.md). Put it in .claude/skills/ to give Claude Code a description of the tools.
Tool catalogue
The tools are registered from lib/mcp/tools/index.ts. The MCP tools reference lists every one with its input fields; it is generated from the code.
Your client lists each tool's input schema (from its zod definition) when it connects.
Conventions
- Pagination: paginated list tools take
limit(1 to 100, default 20) andoffset(default 0) and return{ data, total, offset }. - Single items return
{ data }. - Deletes are mostly soft deletes. CRM records, campaigns, documents and boards get
deletedAtanddeletedBy.projects_delete_taskdeletes the task and its comments, as the UI does, and needs write access to the task's board (being the assignee is not enough).projects_delete_sectionhard-deletes, and only an empty section. - Enrichment tools queue Inngest jobs and return before the enrichment finishes.
crm_add_to_target_listadds only targets the caller can access, like the web app, and reports that number inadded.- Sending campaigns:
campaigns_sendandcampaigns_resumeneed themanageroradminrole, like sending from the web app. Ausertoken getsFORBIDDEN, whether or not the campaign exists.campaigns_pausestays open to auseron their own campaign, so a manager has to resume it. - Documents:
crm_create_documentandcrm_get_upload_urlreturn a presigned URL. The client uploads the file to object storage itself.
Errors
Failed calls return isError: true and a JSON body { "error": "...", "code": "..." }:
| Code | Meaning |
|---|---|
UNAUTHORIZED | Missing, invalid, expired or revoked token, or the token's owner is not ACTIVE |
FORBIDDEN | The user's role may not use this tool, or the record exists but the user may not access it |
NOT_FOUND | No such record (or soft-deleted) |
INVALID_PARAMS | Validation failed |
INVALID_REQUEST | Conflict with existing data |
RULE_REJECTED | A plugin rule rejected the write. The message is translated to English. |
INTERNAL_ERROR | Anything else, including failures of external services |
Add a tool
- Add an object to the array in the right
lib/mcp/tools/*.tsfile:name,description,schema(az.object) andhandler(args, userId, user). - In the handler, check access with the
@/lib/authzhelpers or a…ReadScopeWhere(user)filter, exactly like the matching server action. This covers every id the tool takes, not only the main record: a linked account, template, target list or a list of target ids needs the same check the web app makes. A denied id returnsNOT_FOUND. Tools that take an id are listed in__tests__/mcp/tool-id-inventory.test.ts, which fails until a new one is added with a note on how its ids are checked. - Throw with the helpers in
lib/mcp/helpers.ts(notFound,forbidden,conflict,validationError) so the error maps to the right code. - For a new file, export its array from
lib/mcp/tools/index.tsand add it toallTools. - Add a test under
lib/mcp/__tests__/or__tests__/mcp/. Existing suites test scope for theuserrole.
Tool calls run inside runAsActor({ type: "token", ... }), so plugin rules see the token user as the actor.
Limitations
- No SSE transport. The legacy SSE endpoints
/api/mcp/sseand/api/mcp/messageanswer501with a JSON error that points to/api/mcp/mcp. Use Streamable HTTP. - No per-token scopes. A token can do everything its user can.
- Tools only. No MCP resources, prompts or notifications.
- Plugins cannot add tools in the current plugin SDK.
- No uploads through MCP. File content goes to object storage through the presigned URL, not through the tool call.