MCP for AI Clients
Since 3.0 the server can speak the Model Context Protocol: an AI client — Claude Code, Claude Desktop, any MCP client — reads (and, if you allow it, writes) the documents with the rights of a user of the server.
Switching it on
// a Nuxt app: server/plugins/mcp.ts
import { mcp } from '@sfxcode/mongocamp-server-core'
import { definePlugin } from 'nitro'
export default definePlugin((nitroApp) => {
nitroApp.hooks.hook('mongocamp:ready', server => server.use(mcp())) // mcp({ write: true }) adds insert and update
})Standalone: await server.use(mcp()) after createMongocampServer. Without it /mcp answers 404.
Connecting a client
The endpoint is <API root>/mcp (Streamable HTTP, stateless); it authenticates like the REST API — a bearer token, an api key or Basic auth. An api key of a user with only the grants the agent needs is the usual choice:
claude mcp add --transport http mongocamp https://example.com/api/mongocamp-server/mcp --header "X-AUTH-APIKEY: <api key>"Tools
| Tool | |
|---|---|
list_collections | the collections the user may read, declared ones marked |
describe_collection | the declaration: JSON Schema, behaviours, references, indexes, and the fields hidden for this user |
find | a Lucene filter, sort, projection, expand, paged (at most MCP_MAX_ROWS) |
get, count | one document by id, the number of a filter |
aggregate | a pipeline; denied stages and operators are refused, $lookup reads with the rules of the other collection |
insert, update | only with mcp({ write: true }): validated, with the behaviours (owner, timestamps, versions, audit) |
Every tool acts as the authenticated user through the same document service as the REST API: grants, read scopes (owner, tenant, access rules, soft delete, drafts), field rules, the secrets of mc_users, the operator guard and PAGING_MAX_ROWS apply. An error is a tool result with isError (403: …, 400: … with the issues), so the agent can correct itself.
Answers are relaxed Extended JSON, at most MCP_MAX_ROWS documents (default 100) and MCP_MAX_BYTES of text (default 100 kB, then cut with a note).
