• Start

MCP

Embedded MCP

Connect AI agents and editors to a SurrealDB server you run yourself, through the built-in MCP server over HTTP or stdio.

Available since: v3.1.0

SurrealDB ships a built-in Model Context Protocol server, so agents and editors can list schema, run SurrealQL, and change records through a standard set of tools. The same access control applies as on /sql and RPC: DEFINE USER permissions, table PERMISSIONS, and server capability flags all decide what a tool can do.

This page covers the server inside the SurrealDB binary, for databases you run yourself. For SurrealDB Cloud, the hosted SurrealDB MCP Server reaches the same data tools remotely and adds organisation, instance, and billing management on top.

Both publish the same data tools. What differs is how your editor connects and who shares the database.

surreal mcp (stdio)surreal start + /mcp (HTTP)
How it worksYour editor spawns SurrealDB as a child process; MCP runs over stdin and stdoutYou run a server; the editor connects to http://…/mcp
DatabaseEmbedded in the MCP process (default memory, or a local file path)The same instance your app, CLI, or Surrealist uses
AuthenticationOwner-level access on every tool call — no login stepNormal SurrealDB auth (Bearer JWT, HTTP Basic, …)
Best forLearning MCP, solo local development, quickest editor setupShared databases, teams, remote instances, production patterns
Editor configcommand and args in MCP settingsurl and auth headers

Use surreal mcp when you want the lowest-friction path on a machine you trust: paste a config, restart the editor, and experiment. Think of it as a self-contained database for your assistant.

Use surreal start and /mcp when the agent should work against a database that already exists, or one that other clients share. That is the right model for least-privilege users, TLS, audit logging, and anything beyond trusted solo development.

Tip

New to MCP? Start with surreal mcp in your coding assistant, then move to HTTP once you want the agent on the same instance as your application.

When you run surreal start, the server exposes POST /mcp on the same bind address as the REST API. Authenticate with the same headers you use elsewhere, for example Authorization: Bearer <jwt> or HTTP Basic.

surreal start --user root --pass secret --bind 127.0.0.1:8000 memory
# MCP endpoint: http://127.0.0.1:8000/mcp

For a non-loopback hostname (a public FQDN, a Kubernetes service name, or a load-balancer host), the transport rejects the request with 403 Forbidden: Host header is not allowed until you opt in. Set SURREAL_MCP_ALLOWED_HOSTS to your hostnames, or SURREAL_MCP_ALLOW_ALL_HOSTS=true behind a trusted proxy. See Configuration.

Warning

Run /mcp behind TLS in production. The session header acts like a bearer token for the life of the session: anyone who holds it can repeat tool calls as the same user until the session expires, five minutes after the last request by default.

For local editor integrations, use the dedicated subcommand. It runs the MCP server in the same process as an embedded datastore:

surreal mcp --user root --pass secret --ns main --db main memory

Every tool call over stdio runs with owner-level access. There is no network handshake to attach credentials to, so there is nothing to narrow the permissions with. Do not expose this entry point to untrusted users.

See surreal mcp for its flags and environment variables, including SURREAL_MCP_NS, SURREAL_MCP_DB, and the shared SURREAL_MCP_* limits below.

For stdio, the editor launches SurrealDB itself, so the config is a command and its arguments.

~/.cursor/mcp.json (global) or .cursor/mcp.json (project):

{
  "mcpServers": {
    "surrealdb": {
      "command": "surreal",
      "args": ["mcp", "--user", "root", "--pass", "secret",
          "--ns", "main", "--db", "main", "memory"]
    }
  }
}

Restart Cursor, then check that Settings → MCP shows surrealdb as connected.

If the editor cannot find the binary, use the full path from which surreal (macOS and Linux) or where surreal (Windows) as command.

Note

--user and --pass create the root user on a new datastore, the same as surreal start. They do not authenticate each MCP call, because stdio runs every call as owner. Prefer an env block (SURREAL_USER, SURREAL_PASS) over literals in args so credentials stay out of committed config. To keep data between sessions, replace memory with a file-backed path such as rocksdb://tmp/surreal-mcp.

For HTTP, point the editor at a server you are already running and attach credentials as headers:

{
  "mcpServers": {
    "surrealdb": {
      "url": "http://127.0.0.1:8000/mcp",
      "headers": {
        "Authorization": "Basic <base64-encoded username:password>"
      }
    }
  }
}

Once connected, ask the assistant which SurrealDB tools it has. It should list query, select, use, and the rest of the set below.

tools/list publishes these tools, and the names are stable:

ToolPurpose
queryRun SurrealQL and return serialised results
gqlRun an OpenGQL query (needs the opengql experimental capability on the server)
graphqlRun a GraphQL query against the configured schema
select, create, insert, upsert, update, delete, relateData manipulation helpers
runCall a database function with typed arguments
listList namespaces, databases, tables, indexes, users, …
useSelect the namespace and database context
infoSchema or engine information for a scope

Legacy names such as list_tables, use_database, and version are no longer published. Use list and use instead.

MCP-specific limits are read once from the environment, with the prefix SURREAL_MCP_. HTTP body size uses the server-wide cap.

VariableDefaultEffect
SURREAL_MCP_QUERY_TIMEOUT_SECS60Outer timeout on each tool execution (0 disables)
SURREAL_MCP_MAX_RESULT_BYTES256 KiBCap on serialised tool output (0 disables)
SURREAL_MCP_RUN_MAX_ARGS64Maximum arguments to run
SURREAL_MCP_PARAMS_MAX_KEYS256Maximum top-level keys in parameter objects
SURREAL_MCP_PARAMS_MAX_QL_BYTES4 KiBMaximum byte length of a $ql string inside a *_data payload
SURREAL_MCP_SCHEMA_RESOURCE_MAX_TABLES200Cap on tables enriched in the database schema resource
SURREAL_MCP_ALLOWED_HOSTS
Available since: v3.2.1
loopback onlyExact Host values accepted for HTTP /mcp (replaces the loopback default)
SURREAL_MCP_ALLOW_ALL_HOSTS
Available since: v3.2.1
falseAccept any Host (trusted-proxy escape hatch; overrides the allowlist)
SURREAL_HTTP_MAX_MCP_BODY_SIZE4 MiBMaximum HTTP body size for /mcp

Full tables live under Environment variables. Observability metrics include surrealdb.mcp.* counters and histograms from 3.1.0.

  • Prefer a least-privilege DEFINE USER (for example a custom role with table-level PERMISSIONS) over root credentials for agent clients.

  • Lock down capabilities (--deny-funcs, --allow-net, …) so a hijacked session cannot reach http::* or other high-risk functions.

  • Set --allow-origin explicitly for browser-based MCP clients, and avoid * in production.

  • On a public hostname, set SURREAL_MCP_ALLOWED_HOSTS, or SURREAL_MCP_ALLOW_ALL_HOSTS only behind a trusted proxy. The default allowlist is loopback-only.

  • Forward the surrealdb::mcp::audit tracing target to your SIEM. Audit records include the tool name, subject, namespace, database, and outcome, but never query text or row payloads.

SymptomThings to check
The editor shows the server as disconnectedIs surreal on your PATH? Use the full path as command, or run the same command in a terminal to see the error
The tools list is emptyRestart the editor after editing MCP config, and confirm the binary is 3.1 or later
403 Forbidden: Host header is not allowedHTTP /mcp accepts loopback hosts by default. Set SURREAL_MCP_ALLOWED_HOSTS to your hostname, or SURREAL_MCP_ALLOW_ALL_HOSTS=true behind a trusted proxy. Needs 3.2.1 or later
A tool call times outThe default timeout is 60 seconds (SURREAL_MCP_QUERY_TIMEOUT_SECS). Narrow the query
A result comes back truncatedOutput is capped at 256 KiB by default. Paginate or aggregate in SurrealQL
Permission errors over HTTPThe user lacks rights for the operation. Sign in with different credentials, or adjust DEFINE USER and table PERMISSIONS

Was this page helpful?