A powerful Model Context Protocol (MCP) server that enables AI assistants like Claude to interact with your MariaDB databases. This server provides comprehensive database access with schema exploration, query execution, and advanced features.
- 🔍 Schema Exploration: Browse databases, tables, and detailed schema information
- 📊 Query Execution: Execute both read-only and write queries (configurable)
- đź“„ Multiple Output Formats: JSON for programmatic use, Markdown for human readability
- đź“‘ Pagination Support: Handle large result sets efficiently
- đź”’ Security Features: Parameterized queries, SQL injection prevention, read-only mode
- 🏊 Connection Pooling: Efficient database connection management
- ⚡ Performance: Query timeouts, result size limits, and optimized response formatting
- Python 3.8+ installed on your system
- MariaDB Connector/C (required for the Python MariaDB connector)
On macOS:
brew install mariadb-connector-c
export MARIADB_CONFIG=$(brew --prefix mariadb-connector-c)/bin/mariadb_configOn Ubuntu/Debian:
sudo apt-get update
sudo apt-get install libmariadb-devOn RHEL/CentOS/Fedora:
sudo yum install mariadb-connector-c-develOn Windows: Download and install from MariaDB Connector/C downloads
pip install -r requirements.txtOr install packages individually:
pip install mcp mariadbConfigure the server using these environment variables:
# Required - Database Connection
export MARIADB_HOST="localhost" # Database server hostname
export MARIADB_PORT="3306" # Database server port
export MARIADB_USER="your_username" # Database username
export MARIADB_PASSWORD="your_password" # Database password
export MARIADB_DATABASE="" # Default database (optional)
# Optional - Security & Performance
export MARIADB_READ_ONLY="true" # Set to "false" to allow write queries
export MARIADB_POOL_SIZE="5" # Connection pool size (default: 5)Add this to your Claude Desktop configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
Linux: ~/.config/Claude/claude_desktop_config.json
{
"mcpServers": {
"mariadb": {
"command": "python",
"args": ["/path/to/mariadb_mcp_server.py"],
"env": {
"MARIADB_HOST": "localhost",
"MARIADB_PORT": "3306",
"MARIADB_USER": "your_username",
"MARIADB_PASSWORD": "your_password",
"MARIADB_DATABASE": "your_database",
"MARIADB_READ_ONLY": "true"
}
}
}
}If you package and publish the server to PyPI:
{
"mcpServers": {
"mariadb": {
"command": "uvx",
"args": ["mariadb-mcp-server"],
"env": {
"MARIADB_HOST": "localhost",
"MARIADB_PORT": "3306",
"MARIADB_USER": "your_username",
"MARIADB_PASSWORD": "your_password",
"MARIADB_DATABASE": "your_database"
}
}
}
}The server provides the following tools:
List all accessible databases on the MariaDB server.
Example usage in Claude:
- "What databases are available?"
- "Show me all databases"
List all tables in a specific database with metadata.
Parameters:
database_name: Name of the databaseresponse_format: "json" or "markdown" (default: "markdown")
Example usage in Claude:
- "What tables are in the sales database?"
- "List all tables in my_app database"
Get detailed schema information for a specific table.
Parameters:
database_name: Name of the databasetable_name: Name of the tableinclude_indexes: Include index information (default: true)include_foreign_keys: Include foreign key relationships (default: true)response_format: "json" or "markdown"
Example usage in Claude:
- "Show me the schema for the users table"
- "What columns does the orders table have?"
Execute SQL queries against the database.
Parameters:
database_name: Database to queryquery: SQL query to executeparameters: Query parameters for parameterized queries (optional)limit: Maximum rows to return (default: 100, max: 1000)offset: Number of rows to skip for pagination (default: 0)response_format: "json" or "markdown"
Example usage in Claude:
- "Find all users who registered in the last month"
- "Show me the top 10 selling products"
- "Update the status of order 12345 to 'shipped'"
Get statistics and metadata about a database.
Parameters:
database_name: Name of the databaseresponse_format: "json" or "markdown"
Example usage in Claude:
- "How large is the analytics database?"
- "Show me statistics for the production database"
By default, the server runs in read-only mode, allowing only SELECT, SHOW, DESCRIBE, and EXPLAIN queries. To enable write operations:
export MARIADB_READ_ONLY="false"- The server uses parameterized queries
- SQL comments are automatically stripped
- Query validation is performed before execution
- Connection pooling with automatic reconnection
- Configurable timeouts
- Secure credential handling through environment variables
Once configured, you can interact with your MariaDB database through Claude:
You: "What databases do I have access to?"
Claude: [Uses list_databases tool]
You: "Show me the tables in the ecommerce database"
Claude: [Uses list_tables tool]
You: "What's the structure of the customers table?"
Claude: [Uses get_table_schema tool]
You: "Find the top 5 customers by total purchase amount"
Claude: [Uses execute_query to run an aggregation query]
You: "Show me all orders from last month"
Claude: [Uses execute_query with date filtering]
You: "Analyze the sales trends for Q4"
Claude: [Uses multiple tools to explore schema and run analytical queries]
You: "What's the average order value by product category?"
Claude: [Uses execute_query with GROUP BY and aggregation]
- Connection Error: Verify your database credentials and that MariaDB is running
- MariaDB Connector/C Not Found: Ensure you've installed the connector and set MARIADB_CONFIG
- Permission Denied: Check that your database user has appropriate permissions
- Query Timeout: Complex queries may timeout; consider optimizing or increasing timeout
To enable detailed logging:
# In the server file, change:
logging.basicConfig(level=logging.DEBUG)- Use Indexes: Ensure your tables have appropriate indexes for common queries
- Limit Results: Always use LIMIT clauses for large tables
- Parameterized Queries: Use parameters instead of string concatenation
- Connection Pooling: Adjust MARIADB_POOL_SIZE based on your workload
- Results are automatically truncated if they exceed 25,000 characters
- Use pagination (limit/offset) for large result sets
- Choose JSON format for programmatic processing, Markdown for readability
# Test connection
python mariadb_mcp_server.py
# The server will wait for MCP commands on stdin
# Press Ctrl+C to exitTo add new tools, follow this pattern:
@mcp.tool(
name="your_tool_name",
annotations={
"title": "Human Readable Title",
"readOnlyHint": True,
"destructiveHint": False,
"idempotentHint": True,
"openWorldHint": True
}
)
async def your_tool_function(params: YourInputModel) -> str:
"""Tool documentation"""
# Implementation
passMIT License - See LICENSE file for details
For issues, questions, or contributions:
- Check the troubleshooting section
- Review environment variable configuration
- Ensure MariaDB Connector/C is properly installed
- Verify database permissions
- Initial release with core functionality
- Schema exploration tools
- Query execution with pagination
- Multiple output formats
- Security features and connection pooling
- Transaction support for complex operations
- Query history and caching
- Advanced query builder assistance
- Performance profiling tools
- Backup and restore utilities
- Vector search capabilities (MariaDB 11.7+)
Built with the MCP Python SDK (FastMCP) and MariaDB Connector/Python.