The SurrealDB MCP Server enables AI assistants to interact with SurrealDB databases through a standardized interface, providing comprehensive database operations for the graph database.
Execute Raw SurrealQL Queries: Run any valid SurrealQL query including complex SELECTs, JOINs, aggregations, graph traversals, transactions, and schema definitions
CRUD Operations: Create records with auto-generated IDs, select records by ID or entire tables, update entire records, and delete records with their associated graph edges
Advanced Update Operations: Merge specific fields without affecting others, apply JSON Patch operations (RFC 6902) for granular modifications, and upsert to create or update records with specific IDs
Bulk Operations: Efficiently insert multiple records in a single operation
Graph Database Features: Create relationships (edges) between records with optional relation data, supporting complex relationship modeling and graph traversals
Multi-Database Support: Override namespace and database per tool call to work with multiple databases in a single session
Connection Management: Efficient connection pooling with environment variable configuration for optimal performance
Enables AI assistants to interact with SurrealDB databases, supporting SurrealQL queries, CRUD operations, graph relationship management, and bulk operations while handling SurrealDB's unique features like record IDs and graph edges.
SurrealDB MCP Server
A Model Context Protocol (MCP) server that enables AI assistants to interact with SurrealDB databases
=� Overview
The SurrealDB MCP Server bridges the gap between AI assistants and SurrealDB, providing a standardized interface for database operations through the Model Context Protocol. This enables LLMs to:
Execute complex SurrealQL queries
Perform CRUD operations on records
Manage graph relationships
Handle bulk operations efficiently
Work with SurrealDB's unique features like record IDs and graph edges
Related MCP server: Snowflake Cube Server
Features
Full SurrealQL Support: Execute any SurrealQL query directly
Comprehensive CRUD Operations: Create, read, update, delete with ease
Graph Database Operations: Create and traverse relationships between records
Bulk Operations: Efficient multi-record inserts
Smart Updates: Full updates, merges, and patches
Type-Safe: Proper handling of SurrealDB's RecordIDs
Connection Pooling: Efficient database connection management
Multi-Database Support: Override namespace/database per tool call
Detailed Documentation: Extensive docstrings for AI comprehension
=� Prerequisites
Python 3.10 or higher
SurrealDB instance (local or remote)
MCP-compatible client (Claude Desktop, MCP CLI, etc.)
=� Installation
Using uvx (Simplest - No Installation Required)
Using uv (Recommended for Development)
Using pip
� Configuration
The server uses environment variables for configuration.
Required Variables (at startup)
Variable | Description | Example |
| SurrealDB connection URL |
|
| Database username |
|
| Database password |
|
Optional Variables (can be overridden per tool call)
Variable | Description | Example |
| Default SurrealDB namespace |
|
| Default SurrealDB database |
|
Note: If
SURREAL_NAMESPACEandSURREAL_DATABASEare not set as environment variables, you must providenamespaceanddatabaseparameters in each tool call.
Setting Environment Variables
You can copy .env.example to .env and update with your values:
Or set them manually:
MCP Client Configuration
Add to your MCP client settings (e.g., Claude Desktop):
Using uvx (recommended):
Using local installation:
=' Available Tools
All tools support optional namespace and database parameters to override the default values from environment variables.
1. query
Execute raw SurrealQL queries for complex operations.
2. select
Retrieve all records from a table or a specific record by ID.
3. create
Create a new record with auto-generated ID.
4. update
Replace entire record content (preserves ID and timestamps).
5. delete
Permanently remove a record from the database.
6. merge
Partially update specific fields without affecting others.
7. patch
Apply JSON Patch operations (RFC 6902) to records.
8. upsert
Create or update a record with specific ID.
9. insert
Bulk insert multiple records efficiently.
10. relate
Create graph relationships between records.
=� Examples
Basic CRUD Operations
Working with Relationships
Bulk Operations
Multi-Database Operations
You can work with multiple databases in a single session by using the namespace and database parameters:
Behavior Summary:
Scenario | Result |
Env vars set, no params | Uses pooled connection (best performance) |
Env vars set, params provided | Uses override connection with specified namespace/database |
No env vars, params provided | Uses override connection with specified namespace/database |
No env vars, no params | Fails with clear error message |
<� Architecture
The server is built with:
FastMCP: Simplified MCP server implementation
SurrealDB Python SDK: Official database client
Connection Pooling: Efficient connection management
Async/Await: Non-blocking database operations
>� Testing
The project includes a comprehensive test suite using pytest.
Prerequisites
SurrealDB instance running locally
Test database access (uses temporary test databases)
Running Tests
Test Structure
Writing Tests
The test suite includes fixtures for common test data:
clean_db- Ensures clean database statesample_user_data- Sample user datacreated_user- Pre-created user recordcreated_product- Pre-created product record
Example test:
> Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Fork the repository
Create your feature branch (
git checkout -b feature/AmazingFeature)Commit your changes (
git commit -m 'Add some AmazingFeature')Push to the branch (
git push origin feature/AmazingFeature)Open a Pull Request
=� License
This project is licensed under the MIT License - see the LICENSE file for details.
=O Acknowledgments
SurrealDB for the amazing graph database
FastMCP for simplifying MCP server development
Model Context Protocol for the standardized AI-tool interface
=� Support
=� Email: your.email@example.com
=� Discord: Join our server
= Issues: GitHub Issues