MCP server
Connect Claude, Cursor, VS Code and other AI agents to a Spica instance with @spica/mcp, so they can manage buckets, data, functions, access and storage.
@spica/mcp is a Model Context Protocol server for Spica. It gives an AI agent tools to work with your instance: design buckets, query and import data, write and deploy functions, read logs, manage API keys and policies, and organize storage.
The server runs on your machine and talks to the Spica API with an API key, so the agent can do exactly what that key's policies allow.
Requirements
- Node.js 22 or newer.
- A Spica instance (MongoDB or PostgreSQL) and its API URL, including
/api. - An API key with the policies the agent needs.
Create an API key for the agent
Create a dedicated key so you can limit and revoke the agent's access independently of everything else. In the panel, open Access → API Keys, create a key named after the agent, and attach policies. Or use the API:
curl -X POST https://api.example.com/api/passport/apikey \
-H "Authorization: IDENTITY <token>" -H "Content-Type: application/json" \
-d '{"name": "ai-agent", "description": "MCP server for Claude Code", "active": true}'
curl -X PUT https://api.example.com/api/passport/apikey/<apikeyId>/policy/BucketReadOnlyAccess \
-H "Authorization: IDENTITY <token>"Start with read-only policies and add write access when you need it:
| Tools | Policies |
|---|---|
list_buckets, list_bucket_data, export_bucket_data | BucketReadOnlyAccess |
insert_bucket, update_bucket, save_bucket_data, import_bucket_data, list_bucket_data_profile | BucketFullAccess |
list_functions, get_function_index, get_function_dependencies | FunctionReadOnlyAccess |
insert_function, update_function, save_function_index, save_function_dependencies | FunctionFullAccess |
list_env_vars | EnvVarReadOnlyAccess (included in FunctionReadOnlyAccess) |
list_secrets | SecretReadOnlyAccess |
insert_env_var, update_env_var, insert_secret, update_secret | EnvVarFullAccess, SecretFullAccess (both included in FunctionFullAccess) |
list_storage_objects | StorageReadOnlyAccess |
insert_storage_object, update_storage_object, rename_storage_object | StorageFullAccess |
list_apikeys, list_identities, list_policies, list_users | The matching …ReadOnlyAccess policies |
insert_apikey, update_apikey, insert_identity, update_identity, insert_policy, update_policy | The matching …FullAccess policies |
list_user_profile | UserFullAccess |
list_activities | ActivityReadOnlyAccess |
list_function_logs | Any valid key |
A tool whose action the key doesn't allow returns the API's error to the agent, such as Spica API 403: You do not have sufficient permissions to do passport:user:index on resource, and the other tools keep working.
Connect your agent
The server reads two environment variables:
| Variable | Value |
|---|---|
SPICA_URL | The API URL, for example https://api.example.com/api |
SPICA_APIKEY | The key you created |
claude mcp add spica \
--env SPICA_URL=https://api.example.com/api \
--env SPICA_APIKEY=<key> \
-- npx -y @spica/mcpThe server is added to the current project. Add --scope user to use it in all your projects, or --scope project to write it to a .mcp.json file you can commit. Check the connection with claude mcp list, or /mcp in a session.
To work with several instances, add one server per instance with its own name and key, for example spica-staging and spica-production.
On startup the server loads the instance's function trigger options from GET /function/information and its database engine from GET /status/engine. The tool schemas follow that information, so the agent sees the trigger types, options and collections your instance supports. If SPICA_URL or SPICA_APIKEY is missing, the URL can't be reached, or the key is not valid (Spica API 401: Unauthorized), the server exits and your agent reports that it couldn't connect.
Tools
Database
| Tool | Does |
|---|---|
list_buckets | List bucket schemas. |
insert_bucket | Create a bucket from a schema. |
update_bucket | Replace a bucket schema. |
list_bucket_data | Query documents with filter, sort, limit, skip, relation resolving and a language. |
save_bucket_data | Insert a document, or replace it when it contains its key. |
export_bucket_data | Write documents to a JSON or CSV file on your machine. |
import_bucket_data | Insert documents from a local JSON or CSV file, in parallel batches (concurrency, default 50). Reports each failure. |
Development
| Tool | Does |
|---|---|
list_functions | List functions with their triggers. |
insert_function, update_function | Create or replace a function, its triggers and its env var and secret links. |
get_function_index, save_function_index | Read or replace a function's code. TypeScript is compiled on save, and type or syntax errors come back as diagnostics with line and column. JavaScript is saved without checks. |
get_function_dependencies, save_function_dependencies | Read or install npm packages. |
list_env_vars, insert_env_var, update_env_var | Manage environment variables. |
list_secrets, insert_secret, update_secret | Manage secrets. |
Authentication
| Tool | Does |
|---|---|
list_apikeys, insert_apikey, update_apikey | Manage API keys and the policies attached to them. |
list_identities, insert_identity, update_identity | Manage identities and their policies. |
list_policies, insert_policy, update_policy | Manage policies. |
list_users | List users with filters, sort and paging. |
Storage, debugging and auditing
| Tool | Does |
|---|---|
list_storage_objects | List storage objects with filters and paging. |
insert_storage_object, update_storage_object, rename_storage_object | Upload base64 content, replace it, or rename an object. |
list_function_logs | Read function logs by date range, function, level or text. |
list_bucket_data_profile, list_user_profile | Read the query profiler, to find slow queries and missing indexes. |
list_activities | Read the activity log by identifier, action, resource and date. |
The server has 38 tools, and none of them delete anything. Deleting buckets, documents, functions or files stays a deliberate step in the panel, the CLI or the API.
A few behaviors worth knowing:
save_bucket_datavalidates against the bucket schema like the API does.import_bucket_datakeeps going when a row fails and returns each failure, for exampleSpica API 400: .price must be number,null.export_bucket_dataandimport_bucket_dataread and write files on the machine that runs the MCP server. Export only uses the base name offileName, so it can't write outsidedirectory.list_secretsreturns secret names with a salt and hash, never the values.insert_apikeyreturns the new key once, in the tool result. Treat the agent's transcript as sensitive when it creates keys.
MongoDB and PostgreSQL
The server adapts to the instance's database:
| MongoDB | PostgreSQL | |
|---|---|---|
| Record key | _id | id |
| Document key | _id | The bucket's primary property |
| Bucket filters | Expression or JSON | Expression only, such as document.age > 18 |
Tools accept either _id or id and return records with the engine's key. On PostgreSQL, insert_bucket requires primary, the property that becomes the primary key, usually a uuid with options.generated: true. JSON filters are rejected before they reach the API, with JSON filters are not supported on PostgreSQL. Use an expression filter, e.g. document.age > 1.
What you can ask
Once connected, describe the outcome and let the agent pick the tools:
- "Create a
productsbucket with a title, a price, a cover image and a category relation, then add five sample products." - "Write an HTTP function
GET /orders/summarythat returns today's order count and total, and use theSTRIPE_KEYsecret." - "Why is the
onOrderPaidfunction failing? Check its logs from the last hour and fix the code." - "Export all users who signed up this month to a CSV file."
- "Which queries on the
ordersbucket are slow, and which indexes would help?" - "Create a read-only policy for the
articlesbucket and an API key that uses it."
Best practices
- Point agents at staging first. Let the agent build on a local or staging instance, then move the result to production with resources as code and a reviewed
spica plan. - One key per agent and environment. Name keys after what uses them, give them only the policies they need, and deactivate them when you're done.
- Keep keys out of shared files.
.mcp.jsonand.vscode/mcp.jsonare often committed. Commit the server entry and pass the key through your shell environment or your client's secret settings instead. - Review what the agent changes. Write tools take effect immediately. Check the activity log or ask the agent to summarize what it changed.
- Give the agent the docs too. Pair the MCP server with Spica docs for agents so it uses the right schema fields, filters and trigger options.