home / mcp / mcp db python mcp server
A lightweight Python implementation of the Model Context Protocol (MCP) server for AI and LLM integrations. | 轻量级 Python 实现的 Model Context Protocol (MCP) 服务端,用于 AI 与大语言模型集成。
Configuration
View docs{
"mcpServers": {
"191341025-mcp-db-python": {
"command": "python",
"args": [
"server.py"
],
"env": {
"DB_HOST": "localhost",
"DB_NAME": "your_database",
"DB_PASS": "your_password",
"DB_PORT": "3306",
"DB_TYPE": "mysql",
"DB_USER": "your_user"
}
}
}
}You can run a Python-based MCP server that lets you safely inspect and read data from a MySQL source via JSON-RPC over standard input and output. This server focuses on exposing database schema metadata and read-only query results, making it a secure, easy-to-use tool for integrated workflows and large language model agents.
Connect to the server with an MCP client or your own script. You will be able to invoke a set of read-only operations to explore the MySQL schema, fetch table metadata, list databases and views, run safe read-only queries, and analyze execution plans. The available endpoints enable you to inspect tables, procedures, triggers, indexes, foreign keys, and more, all while enforcing strict read-only behavior to protect your production data.
Prerequisites: Install Python 3.10 or newer and ensure you can reach your MySQL instance.
Step-by-step commands to set up and run the MCP server locally:
git clone https://github.com/your-account/mcp-db-python.git
cd mcp-db-python
python -m venv venv
# Windows
.\venv\Scripts\activate
# macOS / Linux
source venv/bin/activate
pip install -r requirements.txt
# Configure database credentials in a .env file or environment before starting
# Example environment values are provided in the configuration section
```
```
# Start the MCP server (reads configuration from the environment or .env file)
python server.pyThe server reads configuration from a .env file or runtime environment. You should specify the MySQL connection details so the server can surface schema metadata and perform read-only queries safely.
- The server is designed for safe, read-only access to the database in production environments. Ensure network security and access controls are correctly applied to limit who can issue read-only queries.
List every table in the configured database.
Fetch column metadata for a given table.
Execute read-only SQL and return columns with rows.
Retrieve the CREATE statement of a stored procedure.
List accessible databases/schemas.
Enumerate views with definition snippets.
Return row counts and size statistics for tables.
Inspect indexes for columns, kinds, and uniqueness.
List foreign-key constraints and relationships.
Fetch trigger listings and definitions.
Sample a few rows from a table.
Search column names or comments by keyword.
Provide type, defaults, and constraint details for a column.
Run EXPLAIN on read-only SQL to inspect plans.
List stored procedures and functions.
Summarize users and privileges where permitted.
Return server status such as version and connections.
Compare schema structures between databases/tables.
Generate full CREATE TABLE DDL.