MariaDB logo

Skill

mariadb-mcp

connect AI agents to MariaDB

Published by MariaDB Updated Jul 13
Covers MariaDB Database MCP

Description

How to connect AI agents to MariaDB using the Model Context Protocol (MCP). Use when setting up MCP with MariaDB, connecting Claude Code, Cursor, or other AI tools to a MariaDB database, enabling natural language database queries, or building AI applications that need live database access. The MariaDB MCP Server lets agents query schemas, run read-only SQL, and perform semantic search against MariaDB.

SKILL.md

MariaDB MCP Server

Last updated: 2026-05-25

The Model Context Protocol (MCP) lets AI agents connect to external tools and data sources. The MariaDB MCP Server gives agents direct, controlled access to a MariaDB database — reading schemas, running queries, and optionally performing vector/semantic search — without requiring the developer to write integration code.

The server is open source (MIT), maintained by the MariaDB Foundation at github.com/MariaDB/mcp.

Requires: Python 3.11+, uv package manager, MariaDB server.

What Agents Can Do

With the MariaDB MCP Server connected, an agent can:

  • List databases and tables
  • Read table schemas including foreign key relationships
  • Run read-only SQL queries (SELECT, SHOW, DESCRIBE)
  • Create databases
  • Perform semantic/vector search on stored documents (when embedding provider is configured)

Write operations (INSERT, UPDATE, DELETE) are disabled by default.

Installation

git clone https://github.com/MariaDB/mcp
cd mcp
cp .env.example .env
# Edit .env with your database credentials

Minimum .env configuration:

DB_HOST=127.0.0.1
DB_PORT=3306
DB_USER=myuser
DB_PASSWORD=mypassword
DB_NAME=mydatabase
MCP_READ_ONLY=true

Run the server:

uv run server.py

Connecting Claude Code, Cursor, or Windsurf

Use the official server from a local clone (see Installation). Point your MCP config at uv run server.py and the .env file with database credentials.

Claude Code (project-scoped .mcp.json at the repo root):

{
  "mcpServers": {
    "mariadb": {
      "command": "uv",
      "args": [
        "--directory",
        "/absolute/path/to/mcp",
        "run",
        "server.py"
      ],
      "envFile": "/absolute/path/to/mcp/.env"
    }
  }
}

Or add via CLI (replace paths):

claude mcp add mariadb -- uv --directory /absolute/path/to/mcp run server.py

Cursor / VS Code — same mcpServers block in MCP settings; use absolute paths.

SSE or HTTP — run uv run server.py --transport sse (or http) and connect to the URL; see MariaDB/mcp README — Integration.

Not official: PyPI package mcp-server-mariadb (uvx mcp-server-mariadb) is a third-party project, not maintained by the MariaDB Foundation. Prefer github.com/MariaDB/mcp unless you have a specific reason to use the PyPI package.

Available Tools

ToolWhat it does
list_databasesLists all databases the user can access
list_tablesLists tables in a database
get_table_schemaReturns column definitions and types
get_table_schema_with_relationsIncludes foreign key relationships
execute_sqlRuns a read-only SQL query
create_databaseCreates a new database

Vector & Semantic Search (Optional)

When an embedding provider is configured, additional tools are available for building RAG pipelines directly through the MCP interface:

ToolWhat it does
create_vector_storeCreates a vector store table
insert_docs_vector_storeEmbeds and stores documents
search_vector_storeSemantic similarity search
list_vector_storesLists available vector stores
delete_vector_storeRemoves a vector store

Configure an embedding provider in .env:

EMBEDDING_PROVIDER=openai   # or gemini or huggingface
OPENAI_API_KEY=sk-...

For building pure vector search applications, using MariaDB's native VECTOR type and VEC_DISTANCE_* functions directly is more efficient. The MCP vector tools are useful for quick prototyping and when AI agents need to manage the vector store themselves. See the mariadb-vector skill for native vector SQL.

Security: Read-Only Access

The MCP_READ_ONLY=true setting enforces read-only at the application level by filtering queries. For production or shared environments, also restrict at the database level:

CREATE USER 'mcp_agent'@'localhost' IDENTIFIED BY 'password';
GRANT SELECT, SHOW DATABASES ON *.* TO 'mcp_agent'@'localhost';
-- Do NOT grant INSERT, UPDATE, DELETE, DROP

Application-level read-only alone is not sufficient — database-level privileges are the reliable guarantee.

Key Gotchas

  • uv is required: the MCP server uses uv for dependency management, not pip directly. Install: pip install uv or brew install uv.
  • Read-only is not fully enforced in software: rely on database-level privileges, not just MCP_READ_ONLY=true.
  • Vector tools are disabled until EMBEDDING_PROVIDER is set in .env.
  • Connection pooling defaults to 10 connections — tune MCP_MAX_POOL_SIZE for concurrent agent use.
  • SSL/TLS: configure DB_SSL_CA, DB_SSL_CERT, DB_SSL_KEY in .env for remote or production databases.
  • Enterprise version: MariaDB also offers a MariaDB Enterprise MCP Server with additional access control and multi-agent features. See mariadb.com/products/mcp-server.

Sources

For topics not covered here, see the official MariaDB documentation at mariadb.com/docs.

© 2026 YourAI.tools. Every skill from an identity-verified publisher.

Independent catalog. Not affiliated with, endorsed by, or sponsored by Anthropic or any listed publisher. All trademarks belong to their respective owners.