- Home
- MCP servers
- Database
Database
- python
0
GitHub Stars
python
Language
5 months ago
First Indexed
2 months ago
Catalog Refreshed
Documentation & install
Readme and setup notes from the catalogue, plus a client-ready config you can copy for your MCP host.
Installation
Add the following to your MCP client configuration file.
Configuration
View docs{
"mcpServers": {
"vrushil1-database-mcp": {
"command": "python",
"args": [
"path/to/database-mcp/main.py"
],
"env": {
"DB_HOST": "127.0.0.1",
"DB_NAME": "YOUR_DATABASE",
"DB_PORT": "3306",
"DB_USER": "YOUR_USERNAME",
"DB_PASSWORD": "YOUR_PASSWORD"
}
}
}
}You can run a Database MCP Server to interact with your MySQL database through natural language-enabled MCP clients. It exposes introspection, CRUD operations, safe SQL execution, health checks, pagination, and fuzzy search, making it easy to manage data with AI assistants or other MCP clients.
How to use
You connect an MCP client to the Database MCP Server and issue commands using natural language or predefined tool endpoints. Use health checks to verify connectivity before performing operations. Retrieve table schemas, list records with optional search terms, and apply CRUD actions for the Users, Products, and Orders tables. When running queries, rely on the safe SQL execution features that constrain SELECT statements and enforce row limits. Use pagination for large datasets and enable fuzzy search to locate data across multiple fields.
How to install
Prerequisites: Python 3.8 or newer and a running MySQL database server. You also need an MCP-compatible client to connect to the server.
# 1) Clone the repository
git clone <repository-url>
cd database-mcp
# 2) Install dependencies
pip install -r requirements.txt
# 3) Configure database connection
# Create a .env file with the following values
DB_USER=your_username
DB_PASSWORD=your_password
DB_HOST=127.0.0.1
DB_PORT=3306
DB_NAME=your_database_name
# 4) Initialize database tables
# The server will create tables on startup via SQLAlchemy models
# 5) Run the server
python main.py
Configuration and usage notes
Configure how the server connects to your database by supplying environment variables. The server reads DB_USER, DB_PASSWORD, DB_HOST, DB_PORT, and DB_NAME from a .env file at startup. You can also run the server with these variables exported in your shell or provided in your deployment environment.
If you are using an MCP client like Claude Desktop, you can wire up the server with a local Python command that starts the server process. The example below shows how to configure a local Python process for MCP communication.
{
"mcpServers": {
"database": {
"command": "python",
"args": ["path/to/database-mcp/main.py"],
"env": {
"DB_USER": "your_username",
"DB_PASSWORD": "your_password",
"DB_HOST": "127.0.0.1",
"DB_PORT": "3306",
"DB_NAME": "your_database"
}
}
}
}
Usage notes and examples
The server exposes tools for database introspection, CRUD operations, and safe SQL execution. Use these capabilities through your MCP client to manage data without writing raw SQL unless you are performing a safe SELECT through the provided interface.
Security and error handling
The server uses parameterized queries to prevent SQL injection. Only SELECT queries are allowed through the safe SQL execution method, with automatic row limits and pagination. Input validation and structured error messages help you diagnose issues without exposing sensitive details.
Troubleshooting
If you encounter connection issues, verify that MySQL is running and that your credentials and database name are correct in the .env file. Check that the server process starts without errors and that the MCP client can reach the localhost or configured host/port.
Project structure and testing tips
The server is organized to load database models at startup and expose CRUD endpoints for Users, Products, and Orders. To test connectivity quickly, run a small health check from your development environment and confirm that the server responds with a healthy state.
Notes on production readiness
This server is intended for development and testing. For production use, implement additional authentication, secure transport, and comprehensive monitoring.
Available tools
health_check
Test database connectivity and report status.
list_tables
Return a list of all table names in the database.
describe_table
Describe the schema of a specified table.
table_count
Count rows in a given table.
sample_rows
Fetch a sample of rows from a table.
run_sql_select
Execute a safe SELECT query with automatic limits.
user_create
Create a new user with name, email, and password.
user_get
Retrieve a user by ID or email.
user_list
List users with optional search and pagination.
user_update
Update user fields by ID.
user_delete
Delete a user by ID.
product_create
Create a new product with name, price, and stock.
product_get
Retrieve a product by ID.
product_list
List products with optional search and pagination.
product_update
Update product fields by ID.
product_delete
Delete a product by ID.
order_create
Create a new order with user, product, and quantity.
order_get
Retrieve an order by ID.
order_list
List orders with optional user filtering and pagination.
order_update
Update order fields by ID.
order_delete
Delete an order by ID.