MCP MariaDB Server
About
Manage and query MariaDB databases using the Model Context Protocol (MCP), with support for SQL and vector search.
Details
- Author
- mariadb
- Categories
- Database, Other
- Tags
- #sql, #vector-search
Jump to
Configuration & Environment Variables
All configuration is via environment variables (typically set in a.envfile):
Note that if using 'http' or 'sse' as the transport, configuring authentication is important for security if you allow connections outside of localhost. Because different organizations use different authentication methods, the server does not provide a default authentication method. You will need to configure your own authentication method. Thankfully FastMCP provides a simple way to do this starting with version 2.12.1. See the](#testing)[FastMCP documentationfor more information. We have provided an example configuration below.
DB_HOST=localhost DB_USER=your_db_user DB_PASSWORD=your_db_password DB_PORT=3306 DB_NAME=your_default_database MCP_READ_ONLY=true MCP_MAX_POOL_SIZE=10 EMBEDDING_PROVIDER=openai OPENAI_API_KEY=sk-... GEMINI_API_KEY=AI... HF_MODEL="BAAI/bge-m3"
DB_HOST=localhost DB_USER=your_db_user DB_PASSWORD=your_db_password DB_PORT=3306 DB_NAME=your_default_database MCP_READ_ONLY=true MCP_MAX_POOL_SIZE=10
DB_HOST=your-remote-host.com DB_USER=your_db_user DB_PASSWORD=your_db_password DB_PORT=3306 DB_NAME=your_default_database # Enable SSL DB_SSL=true DB_SSL_CA=~/.mysql/ca-cert.pem DB_SSL_CERT=~/.mysql/client-cert.pem DB_SSL_KEY=~/.mysql/client-key.pem DB_SSL_VERIFY_CERT=true DB_SSL_VERIFY_IDENTITY=false MCP_READ_ONLY=true MCP_MAX_POOL_SIZE=10
- All SSL certificate paths support~for home directory expansion
- DB_SSL_CAis used to verify the server's certificate
- DB_SSL_CERTandDB_SSL_KEYare used for client certificate authentication (mutual TLS)
- SetDB_SSL_VERIFY_CERT=falseonly for testing with self-signed certificates
- SetDB_SSL_VERIFY_IDENTITY=trueto enable strict hostname verification
Example Authentication Configuration:This configuration uses external web authentication via GitHub or Google. If you have internal JWT authentication (desired for organizations who manage their own services), you can use the JWT provider instead.
# GitHub OAuth export FASTMCP_SERVER_AUTH=fastmcp.server.auth.providers.github.GitHubProvider export FASTMCP_SERVER_AUTH_GITHUB_CLIENT_ID="Ov23li..." export FASTMCP_SERVER_AUTH_GITHUB_CLIENT_SECRET="github_pat_..." # Google OAuth export FASTMCP_SERVER_AUTH=fastmcp.server.auth.providers.google.GoogleProvider export FASTMCP_SERVER_AUTH_GOOGLE_CLIENT_ID="123456.apps.googleusercontent.com" export FASTMCP_SERVER_AUTH_GOOGLE_CLIENT_SECRET="GOCSPX-..."
⚠️ The only way to guarantee 100% read-only access with absolute certainty is to configure the MariaDB user with appropriate privileges.The READ_ONLY flag is a best effort attempt to prevent write operations, but it is based upon a whitelist of allowed queries and against a truly adversarial user it is not a substitute for proper database user privileges.
The MCP MariaDB Server provides a Model Context Protocol (MCP) interface for managing and querying MariaDB databases, supporting both standard SQL operations and advanced vector/embedding-based search. Designed for use with AI assistants, it enables seamless integration of AI-driven data workflows with relational and vector databases.
- Overview
- Core Components
- Available Tools
- Embeddings & Vector Store
- Configuration & Environment Variables
- Security Considerations
- Installation & Setup
- Usage Examples
- Integration - Claude desktop/Cursor/Windsurf
- Logging
- Testing
The MCP MariaDB Server exposes a set of tools for interacting with MariaDB databases and vector stores via a standardized protocol. It supports:
- Listing databases and tables
- Retrieving table schemas
- Executing safe, read-only SQL queries
- Creating and managing vector stores for embedding-based search
- Integrating with embedding providers (currently OpenAI, Gemini, and HuggingFace) (optional)
- server.py: Main MCP server logic and tool definitions.
- config.py: Loads configuration from environment and.envfiles.
- embeddings.py: Handles embedding service integration (OpenAI).
- tests/: Manual and automated test documentation and scripts.
- Lists all accessible databases.
- Parameters:None
- Lists all tables in a specified database.
- Parameters:database_name(string, required)
- Retrieves schema for a table (columns, types, keys, etc.).
- Parameters:database_name(string, required),table_name(string, required)
- Retrieves schema with foreign key relations for a table.
- Parameters:database_name(string, required),table_name(string, required)
- Executes a read-only SQL query (SELECT,SHOW,DESCRIBE).
- Parameters:sql_query(string, required),database_name(string, optional),parameters(list, optional)
- Note: Enforces read-only mode ifMCP_READ_ONLYis enabled.
- Creates a new database if it doesn't exist.
- Parameters:database_name(string, required)
Vector Store & Embedding Tools (optional)
Note: These tools are only available whenEMBEDDING_PROVIDERis configured. If no embedding provider is set, these tools will be disabled.
- Creates a new vector store (table) for embeddings.
- Parameters:database_name,vector_store_name,model_name(optional),distance_function(optional, default: cosine)
- Deletes a vector store (table).
- Parameters:database_name,vector_store_name
- Lists all vector stores in a database.
- Parameters:database_name
- Batch inserts documents (and optional metadata) into a vector store.
- Parameters:database_name,vector_store_name,documents(list of strings),metadata(optional list of dicts)
- Performs semantic search for similar documents using embeddings.
- Parameters:database_name,vector_store_name,user_query(string),k(optional, default: 7)
The MCP MariaDB Server providesoptionalembedding and vector store capabilities. These features can be enabled by configuring an embedding provider, or completely disabled if you only need standard database operations.
- OpenAI
- Gemini
- Open models from Huggingface
- EMBEDDING_PROVIDER: Set toopenai,gemini,huggingface, or leave unset to disable
- OPENAI_API_KEY: Required if using OpenAI embeddings
- GEMINI_API_KEY: Required if using Gemini embeddings
- HF_MODEL: Required if using HuggingFace embeddings (e.g., "intfloat/multilingual-e5-large-instruct" or "BAAI/bge-m3")
- Default and allowed models are configurable in code (DEFAULT_OPENAI_MODEL,ALLOWED_OPENAI_MODELS)
- Model can be selected per request or defaults to the configured model
A vector store table has the following columns:
- id: Auto-increment primary key
- document: Text of the document
- embedding: VECTOR type (indexed for similarity search)
- metadata: JSON (optional metadata)
Configuration & Environment Variables
All configuration is via environment variables (typically set in a.envfile):
Note that if using 'http' or 'sse' as the transport, configuring authentication is important for security if you allow connections outside of localhost. Because different organizations use different authentication methods, the server does not provide a default authentication method. You will need to configure your own authentication method. Thankfully FastMCP provides a simple way to do this starting with version 2.12.1. See theFastMCP documentationfor more information. We have provided an example configuration below.
DB_HOST=localhost DB_USER=your_db_user DB_PASSWORD=your_db_password DB_PORT=3306 DB_NAME=your_default_database MCP_READ_ONLY=true MCP_MAX_POOL_SIZE=10 EMBEDDING_PROVIDER=openai OPENAI_API_KEY=sk-... GEMINI_API_KEY=AI... HF_MODEL="BAAI/bge-m3"
DB_HOST=localhost DB_USER=your_db_user DB_PASSWORD=your_db_password DB_PORT=3306 DB_NAME=your_default_database MCP_READ_ONLY=true MCP_MAX_POOL_SIZE=10
DB_HOST=your-remote-host.com DB_USER=your_db_user DB_PASSWORD=your_db_password DB_PORT=3306 DB_NAME=your_default_database # Enable SSL DB_SSL=true DB_SSL_CA=~/.mysql/ca-cert.pem DB_SSL_CERT=~/.mysql/client-cert.pem DB_SSL_KEY=~/.mysql/client-key.pem DB_SSL_VERIFY_CERT=true DB_SSL_VERIFY_IDENTITY=false MCP_READ_ONLY=true MCP_MAX_POOL_SIZE=10
- All SSL certificate paths support~for home directory expansion
- DB_SSL_CAis used to verify the server's certificate
- DB_SSL_CERTandDB_SSL_KEYare used for client certificate authentication (mutual TLS)
- SetDB_SSL_VERIFY_CERT=falseonly for testing with self-signed certificates
- SetDB_SSL_VERIFY_IDENTITY=trueto enable strict hostname verification
Example Authentication Configuration:This configuration uses external web authentication via GitHub or Google. If you have internal JWT authentication (desired for organizations who manage their own services), you can use the JWT provider instead.
# GitHub OAuth export FASTMCP_SERVER_AUTH=fastmcp.server.auth.providers.github.GitHubProvider export FASTMCP_SERVER_AUTH_GITHUB_CLIENT_ID="Ov23li..." export FASTMCP_SERVER_AUTH_GITHUB_CLIENT_SECRET="github_pat_..." # Google OAuth export FASTMCP_SERVER_AUTH=fastmcp.server.auth.providers.google.GoogleProvider export FASTMCP_SERVER_AUTH_GOOGLE_CLIENT_ID="123456.apps.googleusercontent.com" export FASTMCP_SERVER_AUTH_GOOGLE_CLIENT_SECRET="GOCSPX-..."
⚠️ The only way to guarantee 100% read-only access with absolute certainty is to configure the MariaDB user with appropriate privileges.The READ_ONLY flag is a best effort attempt to prevent write operations, but it is based upon a whitelist of allowed queries and against a truly adversarial user it is not a substitute for proper database user privileges.
For production use, you should create a dedicated database user with minimal privileges. This is also recommended to show the LLM only the data it may need to perform its task even outside of read-only mode.
- Python 3.11(see.python-version)
- uv(dependency manager;install instructions)
- MariaDB server (local or remote)
Create.envin the project root (seeConfiguration)
uv run server.py --transport sse --host 127.0.0.1 --port 9001
uv run server.py --transport http --host 127.0.0.1 --port 9001 --path /mcp
{ "tool": "execute_sql", "parameters": { "database_name": "test_db", "sql_query": "SELECT * FROM users WHERE id = %s", "parameters": [123] } }
{ "tool": "create_vector_store", "parameters": { "database_name": "test_db", "vector_store_name": "my_vectors", "model_name": "text-embedding-3-small", "distance_function": "cosine" } }
{ "tool": "insert_docs_vector_store", "parameters": { "database_name": "test_db", "vector_store_name": "my_vectors", "documents": ["Sample text 1", "Sample text 2"], "metadata": [{"source": "doc1"}, {"source": "doc2"}] } }
{ "tool": "search_vector_store", "parameters": { "database_name": "test_db", "vector_store_name": "my_vectors", "user_query": "What is the capital of France?", "k": 5 } }
Integration - Claude desktop/Cursor/Windsurf/VSCode
{ "mcpServers": { "MariaDB_Server": { "command": "uv", "args": [ "--directory", "path/to/mariadb-mcp-server/", "run", "server.py" ], "envFile": "path/to/mcp-server-mariadb-vector/.env" } } }
{ "servers": { "mariadb-mcp-server": { "url": "http://{host}:9001/sse", "type": "sse" } } }
{ "servers": { "mariadb-mcp-server": { "url": "http://{host}:9001/mcp", "type": "streamable-http" } } }
{ "servers": { "mariadb-mcp-server": { "command": "docker", "args": [ "run", "-i", "--rm", "-p", "9001:9001", "-e", "DB_HOST=", "-e", "DB_PORT=", "-e", "DB_USER=", "-e", "DB_PASSWORD=", "-e", "DB_NAME=", "mariadb-mcp-server", "python", "src/server.py", "--host", "0.0.0.0", "--transport", "stdio" ] } } }
- Logs are written tologs/mcp_server.logby default.
- Log messages include tool calls, configuration issues, embedding errors, and client requests.
- Log level and output can be adjusted in the code (seeconfig.pyand logger setup).
- Tests are located in thesrc/tests/directory.
- Seesrc/tests/README.mdfor an overview.
- Tests cover both standard SQL and vector/embedding tool operations.
Official MCP server for dbt (data build tool) providing integration with dbt Core/Cloud CLI, project metadata discovery, model information, and semantic layer querying capabilities.
Open source MCP server specializing in easy, fast, and secure tools for Databases.
Query and analyze data with MotherDuck and local DuckDB
Query Streams securely connects MCP clients to live databases through the Query Streams Cloud Network, with no VPNs, inbound ports, or complex setup.
Interact with the SingleStore database platform
Official Supabase MCP server for managing Supabase projects, databases, auth, storage, edge functions, and SQL workflows from AI agents.
A collection of tools for managing the platform, addressing data quality and reading and writing to Teradata Database.
Multi-database agent access (PostgreSQL, SQLite, MySQL, Oracle, SQL Server) with batch queries, pre-configured connections, and SQLGlot-enforced read-only safety
Sign in to leave a review
Use Google, GitHub, or an email account so ratings stay tied to real people.
No reviews posted yet.





