MariaDB MCP Server for SQL and Vector Search
Enable AI-driven SQL and vector search with the MCP server for MariaDB, integrating embedding-based queries and standard SQL workflows for seamless data access.
npx -y @mariadb/mcpOverview
The MariaDB MCP Server implements the Model Context Protocol (MCP) for MariaDB, exposing a standardized set of tools to manage and query relational data and optional embedding-based vector stores. It is designed to be used by AI assistants or other MCP-compatible clients so they can combine traditional SQL workflows (schema discovery, read-only queries) with semantic search powered by embeddings stored in MariaDB VECTOR columns.
By providing the same MCP interface for both SQL and vector search, the server makes it straightforward to augment existing database-driven applications with embedding search (semantic similarity, retrieval-augmented generation) without changing developer workflows or introducing separate vector databases.
Repository: https://github.com/mariadb/mcp Tags: ai-ml, database, search
Features
- List databases and tables, and inspect table schemas (including foreign-key relations).
- Execute safe, read-only SQL queries (SELECT, SHOW, DESCRIBE) with optional parameter binding.
- Create and manage vector store tables that hold embeddings alongside documents and metadata.
- Batch insert documents with embeddings and perform k-nearest-neighbor semantic search.
- Optional integration with embedding providers (OpenAI, Gemini, Hugging Face).
- Configuration via environment variables and .env files; read-only enforcement via MCP_READ_ONLY.
Installation / Configuration
Prerequisites: Python 3.8+, a MariaDB server (or compatible MySQL server), and optional API keys for embedding providers.
- Clone the repo and install dependencies:
- Example .env (create a .env file or export env vars):
DB_HOST=
DB_PORT=3306
DB_USER=mcp_user
DB_PASSWORD=secret
DB_NAME=default_db
MCP_READ_ONLY=true
EMBEDDING_PROVIDER=openai
OPENAI_API_KEY=sk-...
DEFAULT_OPENAI_MODEL=text-embedding-3-small
- Start the MCP server (example):
The server loads configuration from environment variables; embedding-related tools are enabled only when EMBEDDING_PROVIDER is set.
Configuration Reference
| Variable | Purpose | Required | Example |
|---|---|---|---|
| DB_HOST | MariaDB host | Yes | localhost |
| DB_PORT | MariaDB port | No (3306) | 3306 |
| DB_USER | MariaDB user | Yes | mcp_user |
| DB_PASSWORD | MariaDB password | Yes | secret |
| DB_NAME | Default DB (optional) | No | default_db |
| MCP_READ_ONLY | Enforce read-only SQL execution | No (false) | true |
| EMBEDDING_PROVIDER | Enable embedding tools | No | openai, gemini, huggingface |
| OPENAI_API_KEY | OpenAI API key (if provider=openai) | Cond. | sk-… |
| HF_MODEL | HuggingFace model id (if provider=huggingface) | Cond. | intfloat/multilingual-e5-large-instruct |
Available Tools / Resources
Standard relational tools:
- list_databases — enumerate accessible databases.
- list_tables(database_name) — list tables in a database.
- get_table_schema(database_name, table_name) — column definitions, types, keys.
- get_table_schema_with_relations(database_name, table_name) — schema + foreign keys.
- execute_sql(sql_query, database_name?, parameters?) — read-only SQL execution.
- create_database(database_name) — create database if not present.
Vector store / embedding tools (enabled only with EMBEDDING_PROVIDER):
- create_vector_store(database_name, vector_store_name, model_name?, distance_function?)
- delete_vector_store(database_name, vector_store_name)
- list_vector_stores(database_name)
- insert_docs_vector_store(database_name, vector_store_name, documents[], metadata[]?)
- search_vector_store(database_name, vector_store_name, user_query, k=7)
Vector store schema (typical):
- id: AUTO_INCREMENT PRIMARY KEY
- document: TEXT
- embedding: VECTOR (indexed for similarity search)
- metadata: JSON (optional)
Example tool payload (MCP-style JSON, transport depends on your MCP client):
Use Cases
- Semantic augmentation of search: create a vector store for article content, index embeddings, and combine structured SQL filters with semantic vector rankings to present relevant results.
- Read-only analytics and schema inspection: use list_tables and get_table_schema_with_relations for automated agent planning, UI generation, or migration analysis.
- Retrieval-augmented generation (RAG): store document passages and metadata in a vector table, retrieve top-k semantically similar passages, and feed them to an LLM along with SQL query results.
- Safe data access for assistants: enforce MCP_READ_ONLY to prevent accidental data mutations while enabling rich data exploration.
Best Practices & Security
- Use MCP_READ_ONLY=true for production deployments where agents should not modify data.
- Restrict database credentials and rotate API keys for embedding providers.
- Enable TLS/SSL for MariaDB (DB_SSL and DB_SSL_CA) when connecting across untrusted networks.
- Limit allowed embedding models and rate-limit embedding requests to control costs.
For implementation details, examples, and tests, see the repository: https://github.com/mariadb/mcp.