Labsco
nsxdavid logo

SurrealDB MCP Server

β˜… 38

from nsxdavid

A standardized interface for AI assistants to interact with a SurrealDB database.

πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedFreeAdvanced setup

SurrealDB MCP Server

<p align="center"> <img src="assets/images/sdblogo.png" width="256" alt="SurrealDB MCP Server Logo" /> </p> <p align="center"> <a href="https://www.npmjs.com/package/surrealdb-mcp-server"><img src="https://img.shields.io/npm/v/surrealdb-mcp-server.svg" alt="npm version"></a> <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="License: MIT"></a> <a href="https://nodejs.org/"><img src="https://img.shields.io/badge/node-%3E%3D18.0.0-brightgreen" alt="Node.js Version"></a> <a href="https://github.com/modelcontextprotocol/typescript-sdk"><img src="https://img.shields.io/badge/MCP%20SDK-%5E1.6.1-orange" alt="MCP SDK"></a> </p>

A Model Context Protocol (MCP) server that provides a standardized interface for AI assistants to interact with a SurrealDB database. This server enables AI systems to query and manipulate data within a configured SurrealDB instance.

Note for AI Assistants: If you are an AI assistant (like Claude, Cline, Copilot, etc.) reading this documentation, please refer to the llms-install.md file for detailed instructions specifically designed for you to help users install and configure this MCP server.

Key Terms

  • MCP Server: A server that implements the Model Context Protocol, allowing AI assistants to access external tools and resources
  • MCP Host: The application (like VS Code with Cline or Claude Desktop) that connects to MCP servers
  • SurrealDB: A scalable, distributed, document-graph database with real-time capabilities

Available Tools

The server exposes the following tools for interacting with SurrealDB:

  • query: Execute a raw SurrealQL query.
  • select: Select records from a table (all or by specific ID).
  • create: Create a single new record in a table.
  • update: Update a specific record, replacing its content.
  • delete: Delete a specific record by ID.
  • merge: Merge data into a specific record (partial update).
  • patch: Apply JSON Patch operations to a specific record.
  • upsert: Create a record if it doesn't exist, or update it if it does.
  • insert: Insert multiple records into a table.
  • insertRelation: Create a graph relation (edge) between two records.

(Refer to the MCP host's tool listing for detailed input schemas.)

Required Environment Variables

This server requires the following environment variables to connect to your SurrealDB instance:

  • SURREALDB_URL: The WebSocket endpoint of your SurrealDB instance (e.g., ws://localhost:8000 or wss://cloud.surrealdb.com).
  • SURREALDB_NS: The target Namespace.
  • SURREALDB_DB: The target Database.
  • SURREALDB_USER: The username for authentication (Root, NS, DB, or Scope user).
  • SURREALDB_PASS: The password for the specified user.

Development

If you want to contribute to the development of this MCP server, follow these steps:

Local Development Setup

  1. Clone the repository:

    git clone https://github.com/nsxdavid/surrealdb-mcp-server.git
    cd surrealdb-mcp-server
  2. Install dependencies:

    npm install
  3. Build the project:

    npm run build

Running Locally

# Ensure required SURREALDB_* environment variables are set
npm run dev # (Note: dev script uses ts-node to run TypeScript directly)
# Or run the built version:
npm start

Testing

npm test # (Note: Tests need to be implemented)

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

Integration with n8n

You can integrate this SurrealDB MCP Server with n8n using the n8n-nodes-mcp community node.

NOTE: Currently only the self-hosted (Docker) version of n8n supports community nodes. There is no option for MCP Servers in the n8n cloud version (yet?).

Installation

  1. Install the n8n-nodes-mcp package:

    npm install n8n-nodes-mcp
  2. Configure n8n to use the custom node:

    Add the following to your n8n configuration:

    N8N_CUSTOM_EXTENSIONS="n8n-nodes-mcp"
  3. Configure the MCP node in n8n:

    • Add the "MCP" node to your workflow
    • Configure it to connect to your SurrealDB MCP Server
    • Select the desired operation (query, select, create, etc.)
    • Configure the operation parameters

For more details, visit the n8n-nodes-mcp GitHub repository.