When I first wrote about MCP in Nitrobase, the integration was minimal: a guarded proxy route to Supabase Studio's MCP endpoint that returned 403 Forbidden by default.

With Nitrobase 0.2.0, MCP is no longer just a single forwarded route. Nitrobase now ships its own built-in Model Context Protocol server at /api/mcp—exposing 65 scoped tools for deploying Git apps, provisioning and querying standalone databases, editing environment variables, managing domains, inspecting logs, and running backups straight from Claude Code, Cursor, or any Streamable HTTP MCP client.

Instead of maintaining a second, drift-prone backend just for AI agents, the entire MCP server (src/server/api/mcp.ts) is generated directly from Nitrobase's REST API v1 registry (src/server/api/v1.ts). Here is how it works and how it keeps AI agents useful without handing them root keys to your servers.

1. Zero-drift architecture: 66 REST routes -> 65 MCP tools

Writing hand-maintained MCP wrappers around an existing API guarantees that validation rules, auth checks, and response shapes will eventually diverge.

In Nitrobase, mcpTools() derives every MCP tool mechanically from apiRoutes:

  • One tool per non-streaming route: 66 REST routes in /api/v1 become 65 MCP tools (only streaming endpoints are skipped).
  • Deterministic naming & schema merging: Route IDs convert from camelCase to snake_case (listServers -> list_servers), and route.params + route.body Zod schemas are merged into a single inputSchema. If a route uses a non-object schema or shares a key name between params and body, mcpTools() throws—and CI catches it before merge.
  • MCP annotations from HTTP semantics: GET routes default to { readOnlyHint: true }; mutating routes default to { readOnlyHint: false, destructiveHint: true, idempotentHint: false } unless explicitly overridden on the route definition.
  • Shared execution & audit trail: Every tool call runs through authenticateBearer (using the same nbk_... tokens as /api/v1) and runApiRoute(..., "mcp " + tool.name), so rate limits, team isolation, and audit logs apply identically to REST and MCP.
  • Dual output + async job guidance: Each tool returns both formatted JSON text content and structuredContent (setting isError: true on failures). Server-level instructions tell the agent that async operations (deploy, restart, backup, create) return a job ID to poll via get_job, and to confirm with the user before calling non-read-only tools on production apps.

2. Stateless Streamable HTTP—and why JSON-RPC batching is rejected

/api/mcp runs WebStandardStreamableHTTPServerTransport in stateless JSON mode (sessionIdGenerator: undefined, enableJsonResponse: true):

  • Every POST /api/mcp creates a lightweight per-request server scoped to the caller's token, handles one JSON-RPC message, and closes cleanly in finally.
  • GET and DELETE return 405 Method Not Allowed (no sticky server sessions or long-lived SSE state to lose across restarts).
  • JSON-RPC batch arrays are explicitly rejected (400 -32600): One HTTP POST equals one JSON-RPC message, so a caller cannot smuggle 50 tool calls inside a single rate-limited HTTP request (and batching was removed from the MCP spec in 2025-06-18).

3. What is new in 0.2.0: 42 new tools for full lifecycle automation

Commit 8b59e40 expanded /api/v1 and /api/mcp with 42 new operations across four core workflows:

Area New tools Examples
Git apps 15 inspect_git_repo, create_git_deploy_key, preflight_git_app, create_git_app, list_git_releases, deploy_git_commit, rollback_git_release, update_git_build_secrets, set_git_webhook, rotate_git_webhook
Standalone databases & links 16 list_database_engines, create_database, upgrade_database, link_database, unlink_database, read-only query_database, write execute_database, create_managed_user, grant_database_user, drop_database_item
Env, secrets & ports 6 update_app_env (masks secret copies and credential URLs via updateAppEnvForApi), rotate_app_variable, rerun_app_rotate_hook, get_app_service_env, update_app_service_env, set_app_ports
Domains 5 list_domains, add_app_domain (auto-resolves primary service/port when omitted), remove_app_domain, set_primary_app_domain, check_app_domains

Combined with existing server, app, template, log, job, backup, and monitoring routes, an AI agent can now inspect a repository, preflight a Git app, provision a Postgres instance, link it to the app, attach a domain, deploy a commit, and poll get_job until the deployment is healthy—all through typed MCP tools.

4. Permission-filtered tool discovery and AI agent token presets

Security starts before a tool is ever called. In createMcpServer():

for (const tool of toolsOf(routes)) { if (!can(actor, tool.route.permission)) continue; server.registerTool(tool.name, ...); } 

If a token does not hold a route's permission, the tool is not even registered in tools/list. The agent never wastes context on tools it cannot run, and cannot accidentally invoke them.

In Settings -> API tokens, Nitrobase 0.2.0 ships two dedicated MCP presets (src/config/permissions.ts):

  • AI agent (read-only) (agent-read-only): Grants only server.view, app.view, database.view, backup.view, and monitoring.view. This is intentionally narrower than the human Read-only preset—it omits SSH keys, team membership, and audit logs.
  • AI agent (operator) (agent-operator): Adds app.deploy, app.env.edit, app.source.manage, domain.manage, database.manage, database.write, and backup.create.

Equally important is what both presets leave out:

  • No app.env.reveal, database.credentials.reveal, or ssh_key.reveal (agents can edit or rotate secrets without being able to dump plaintext credentials)
  • No app.delete or server.manage (no wiping production apps or servers)
  • No backup.restore or backup.delete (no overwriting live data or erasing recovery points)

5. One-click client snippets without leaking URL credentials

To connect an AI client, Nitrobase generates ready-to-copy snippets (src/features/tokens/mcp-snippets.ts) for:

  • Claude Code:
 claude mcp add --transport http nitrobase https://panel.example.com/api/mcp \ --header 'Authorization: Bearer <TOKEN>' 
  • Cursor / Claude Code .mcp.json:
 { "mcpServers": { "nitrobase": { "type": "http", "url": "https://panel.example.com/api/mcp", "headers": { "Authorization": "Bearer <TOKEN>" } } } } 

Two small hardening details (c048b5f): publicBaseUrl() strips any user:pass@, query string, or fragment before building the endpoint URL, and snippets that get saved to disk (fileHoldsToken: true) display an explicit warning that the file contains a live bearer token.

My checklist for adding an MCP server to an existing platform

  • [ ] Generate MCP tools directly from your typed REST/RPC registry so schemas, auth, and audit logs never drift
  • [ ] Filter tools/list by the token's permissions instead of exposing every tool and failing only at call time
  • [ ] Keep Streamable HTTP stateless and reject JSON-RPC batch arrays so rate limits remain 1:1 with requests
  • [ ] Ship least-privilege AI agent presets that allow deploying and rotating secrets while blocking secret-reveal and destructive wipes
  • [ ] Warn users whenever a generated MCP config snippet stores a bearer token in a local file

Giving an AI agent 65 infrastructure tools is only practical when the permission boundary is enforced by the server—not by a polite line in a system prompt.

Nitrobase source code: https://github.com/AydenGroup/nitrobase