MySQL Schema MCP Server
A server for retrieving MySQL database schema information using the FastMCP framework.
MySQL Schema MCP Server
A Metadata Change Proposal (MCP) server for retrieving MySQL database schema information using the FastMCP framework.
Features
- Retrieve database list
- Retrieve table list from databases
- Get table schema (columns) information
- Get table indexes information
- Get table foreign key information
Setup
Local Setup with uv
- Clone this repository
- Install uv if you don't have it already:
pip install uv - Create a virtual environment and install dependencies:
uv venv uv pip install -r requirements.txt - Create a
.envfile based on.env.examplewith your MySQL connection details:MYSQL_HOST=localhost MYSQL_PORT=3306 MYSQL_USER=your_username MYSQL_PASSWORD=your_password MYSQL_DATABASE=information_schema
Local Setup with pip
- Clone this repository
- Install dependencies:
pip install -r requirements.txt - Create a
.envfile based on.env.examplewith your MySQL connection details:MYSQL_HOST=localhost MYSQL_PORT=3306 MYSQL_USER=your_username MYSQL_PASSWORD=your_password MYSQL_DATABASE=information_schema
Docker Setup
Building and Running the Docker Image
-
Clone this repository
-
Build the Docker image:
docker build -t mysql-mcp-server . -
Run the Docker container with environment variables for MySQL connection:
docker run -p 8000:8000 \ -e MYSQL_HOST=host.docker.internal \ -e MYSQL_PORT=3306 \ -e MYSQL_USER=your_username \ -e MYSQL_PASSWORD=your_password \ -e MYSQL_DATABASE=information_schema \ mysql-mcp-serverNote:
host.docker.internalis used to connect to the MySQL instance running on your host machine from inside the Docker container. -
For Mac and Windows,
host.docker.internalresolves to the host machine. For Linux, you may need to use:docker run -p 8000:8000 \ --add-host=host.docker.internal:host-gateway \ -e MYSQL_HOST=host.docker.internal \ -e MYSQL_USER=your_username \ -e MYSQL_PASSWORD=your_password \ mysql-mcp-server
Usage
Local Usage
Start the server:
python main.py
Docker Usage
Run the Docker container (as shown in the setup section):
docker run -p 8000:8000 \
-e MYSQL_HOST=host.docker.internal \
-e MYSQL_USER=your_username \
-e MYSQL_PASSWORD=your_password \
mysql-mcp-server
You can also create a .env file and mount it to the container:
docker run -p 8000:8000 \
-v $(pwd)/.env:/app/.env \
mysql-mcp-server
MCP JSON Configuration
To use this MCP server with MCP-compatible clients, you'll need to configure the client with the appropriate JSON configuration. Here are examples for both local and Docker setups:
Local MCP Configuration
{
"mcpServers": {
"mysql-schema": {
"command": "python",
"args": [
"main.py"
],
"cwd": "/path/to/mcp-first",
"alwaysAllow": [
"databases",
"tables",
"schema",
"indexes",
"foreign_keys"
]
}
}
}
Docker MCP Configuration
{
"mcpServers": {
"mysql-schema": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"MYSQL_HOST=host.docker.internal",
"-e",
"MYSQL_USER=your_username",
"-e",
"MYSQL_PASSWORD=your_password",
"mysql-mcp-server"
],
"alwaysAllow": [
"databases",
"tables",
"schema",
"indexes",
"foreign_keys"
]
}
}
}
Available Tools
The server provides the following tools:
databases: List all databasestables: List all tables in a databaseschema: Get the schema (columns, indexes, and foreign keys) for one or more tables.indexes: Get the indexes for a specific tableforeign_keys: Get the foreign keys for a specific table
Example
from fastmcp.client import Client
# Connect to the MCP server
client = Client("http://localhost:8000")
# List all databases
databases = client.databases()
# List tables in a specific database
tables = client.tables(database="your_database")
# Get schema for a specific table
schema = client.schema(tables=["your_table"], database="your_database")
# Get schema for multiple tables
schemas = client.schema(tables=["table1", "table2"], database="your_database")
# Get indexes for a specific table
indexes = client.indexes(table="your_table", database="your_database")
# Get foreign keys for a specific table
foreign_keys = client.foreign_keys(table="your_table", database="your_database")
Related Servers
CData EnterpriseDB MCP Server
A read-only MCP server by CData that enables LLMs to query live data from EnterpriseDB databases.
MySQL MCP Server
A MySQL server that connects to a database using environment variables for configuration.
Apache Gravitino
Access Apache Gravitino, a high-performance, federated metadata lake for data and AI.
Unofficial STRING MCP Server
Access the STRING protein interaction database for network analysis, functional enrichment, and comparative genomics.
Avro MCP Server by CData
A read-only MCP server for Avro data sources, powered by the CData JDBC Driver.
DynamoDB Read-Only MCP
A read-only server to query AWS DynamoDB databases using the Model Context Protocol (MCP).
MCP KQL Server
Execute KQL queries using Azure authentication. Requires Azure CLI login.
MCP Football Server
Provides football (soccer) data using the API-Football service.
Quick Data for Windows MCP
A Windows-optimized server for performing data analytics on JSON and CSV files, designed for Claude Desktop integration.
Postgres MCP Pro
An MCP server for PostgreSQL providing index tuning, explain plans, health checks, and safe SQL execution.