database-mcp-server
Provides tools for MongoDB operations including find, insert, update, delete, aggregate, and count on collections.
Provides tools to execute SQL queries, list databases, list tables, and describe table schemas in MySQL databases.
Provides tools to execute SQL queries, list databases, list tables, and describe table schemas in PostgreSQL databases.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@database-mcp-servershow me the users table schema"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Database-MCP-Server
A Model Context Protocol (MCP) server that provides database operations as tools for LLM-powered applications. Supports PostgreSQL, MySQL, and MongoDB databases with connection pooling and flexible result formatting.
Features
Multi-database support: PostgreSQL, MySQL, and MongoDB
Connection pooling: Efficient database connection management
Multiple result formats: JSON and Markdown table output
Streamable HTTP: Modern MCP transport via HTTP
Async operations: Full async/await support for non-blocking database queries
Related MCP server: Database MCP Server
Tools
Tool | Description |
| Execute arbitrary SQL queries against the database |
| List all available databases |
| List all tables in a database (defaults to configured database) |
| Get schema information for a specific table |
Requirements
Python 3.11+
PostgreSQL 12+, MySQL 8.0+, or MongoDB 4.0+
Installation
# Clone the repository
git clone <repository-url>
cd database-mcp-server
# Install dependencies using uv (recommended)
uv pip install -e .
# Or using pip
pip install -e .Configuration
Copy .env.example to .env and configure the environment variables:
cp .env.example .envThen edit .env with your database credentials and settings:
# Database Configuration
DATABASE_PROVIDER=postgres # or mysql, mongodb
DATABASE_HOST=localhost
DATABASE_PORT=5432 # 3306 for MySQL, 27017 for MongoDB
DATABASE_USER=your_username
DATABASE_PASSWORD=your_password
DATABASE_NAME=your_database
DATABASE_MIN_POOL_SIZE=1
DATABASE_MAX_POOL_SIZE=10
# Server Configuration (optional)
HTTP_HOST=0.0.0.0 # Bind address (defaults to all interfaces)
HTTP_PORT=8080Configuration Options
Variable | Required | Default | Description |
| Yes | - | Database provider: |
| Yes | - | Database server hostname or IP |
| Yes | - | Database server port (5432 for PostgreSQL, 3306 for MySQL, 27017 for MongoDB) |
| Yes | - | Database username |
| No | - | Database password |
| Yes | - | Default database to connect to |
| Yes | - | Minimum pool size for connections |
| Yes | - | Maximum pool size for connections |
| No |
| HTTP server bind address |
| No | 8080 | HTTP server port for MCP |
| No |
| Enable read-only mode (blocks write operations) |
Read-Only Mode
By default, the server runs in read-only mode to prevent accidental data modifications. When enabled:
PostgreSQL/MySQL: Only
SELECT,SHOW, andDESCRIBEqueries are allowedMongoDB: Only read operations (
find,find_one,aggregate,count) are allowed
Write operations like INSERT, UPDATE, DELETE, DROP, CREATE, ALTER are blocked.
To disable read-only mode (allow all operations):
READ_ONLY_MODE=falseUsage
Running the Server
# Using uv (recommended)
uv run python main.py
# Using Python directly
python main.pyMCP Client Configuration
Add the server to your MCP client configuration:
Using uv (recommended for dependency isolation):
{
"mcpServers": {
"sql": {
"command": "uv",
"args": [
"--directory",
"/path/to/database-mcp-server",
"run",
"python",
"main.py"
]
}
}
}Using Python directly:
{
"mcpServers": {
"sql": {
"command": "python",
"args": ["/path/to/database-mcp-server/main.py"]
}
}
}Direct HTTP Connection:
The server exposes a Streamable HTTP endpoint. Configure your MCP client to connect directly:
{
"mcpServers": {
"sql": {
"url": "http://localhost:8080/mcp"
}
}
}Note: For direct HTTP connections, ensure the server is running and accessible at the specified URL.
Example Tool Calls
Common Examples (All Providers)
# List all databases
list_databases()
# List tables/collections in the configured database
list_tables()
# List tables/collections in a specific database
list_tables(database="another_db")
# Describe a table/collection schema
describe_table("users")PostgreSQL / MySQL Examples (SQL)
For PostgreSQL and MySQL, use standard SQL syntax:
# Execute a SELECT query
execute_query("SELECT * FROM users WHERE active = true LIMIT 10")
# Execute with specific columns
execute_query("SELECT name, email FROM users WHERE age > 18")
# Get results in Markdown format
execute_query("SELECT name, email FROM users", format_type="markdown")
# INSERT, UPDATE, DELETE queries
execute_query("INSERT INTO users (name, email) VALUES ('John', 'john@example.com')")
execute_query("UPDATE users SET status = 'active' WHERE status = 'pending'")
execute_query("DELETE FROM users WHERE inactive = true")
# Join queries
execute_query("""
SELECT u.name, o.order_id
FROM users u
JOIN orders o ON u.id = o.user_id
WHERE u.active = true
""")MongoDB Examples (JSON)
For MongoDB, queries use JSON format with operation type:
# Find documents
execute_query('{"collection": "users", "operation": "find", "filter": {"active": true}, "limit": 10}')
# Find with projection (select specific fields)
execute_query('{"collection": "users", "operation": "find", "projection": {"name": 1, "email": 1}}')
# Find with sorting and pagination
execute_query('{"collection": "users", "operation": "find", "filter": {"active": true}, "sort": {"created_at": -1}, "skip": 0, "limit": 20}')
# Find one document
execute_query('{"collection": "users", "operation": "find_one", "filter": {"_id": "64f8a2b1c9d8e7f6a5b4c3d2"}}')
# Insert a document
execute_query('{"collection": "users", "operation": "insert_one", "document": {"name": "John", "email": "john@example.com", "created_at": "2024-01-15T10:30:00"}}')
# Insert multiple documents
execute_query('{"collection": "users", "operation": "insert_many", "documents": [{"name": "John"}, {"name": "Jane"}]}')
# Update documents
execute_query('{"collection": "users", "operation": "update_one", "filter": {"email": "john@example.com"}, "update": {"$set": {"status": "active"}}}')
execute_query('{"collection": "users", "operation": "update_many", "filter": {"status": "pending"}, "update": {"$set": {"status": "active"}}}')
# Delete documents
execute_query('{"collection": "users", "operation": "delete_one", "filter": {"email": "john@example.com"}}')
execute_query('{"collection": "users", "operation": "delete_many", "filter": {"inactive": true}}')
# Aggregation pipeline
execute_query('{"collection": "orders", "operation": "aggregate", "pipeline": [{"$group": {"_id": "$status", "count": {"$sum": 1}}}]}')
# Count documents
execute_query('{"collection": "users", "operation": "count", "filter": {"active": true}}')Supported MongoDB Operations:
Operation | Description |
| Query documents with optional filter, projection, sort, skip, limit |
| Query a single document by filter |
| Insert a single document |
| Insert multiple documents |
| Update a single document matching filter |
| Update multiple documents matching filter |
| Delete a single document matching filter |
| Delete multiple documents matching filter |
| Run aggregation pipeline |
| Count documents matching filter |
Query Format Reference:
{
"collection": "collection_name", // Required: Collection to query
"operation": "find", // Required: Operation type (see above)
"filter": {}, // Optional: Query filter (MongoDB query syntax)
"projection": {}, // Optional: Fields to include/exclude
"sort": {"field": 1}, // Optional: Sort order (1=asc, -1=desc)
"skip": 0, // Optional: Number of documents to skip
"limit": 10, // Optional: Maximum documents to return
"document": {}, // For insert_one: Document to insert
"documents": [{}, {}], // For insert_many: Array of documents
"update": {"$set": {}}, // For update operations: Update operators
"pipeline": [{}, {}] // For aggregate: Aggregation pipeline stages
}Project Structure
database-mcp-server/
├── main.py # Entry point
├── pyproject.toml # Project configuration
├── .env # Environment variables (create this)
└── src/
├── server.py # MCP server and tool definitions
├── lib/
│ ├── config.py # Configuration management
│ ├── utils.py # Utility functions
│ ├── middleware.py # Middleware for MCP server
│ └── mcp.py # MCP-specific utilities
└── database/
├── manager.py # Database connection pool manager
├── formatter.py # Result formatting (JSON/Markdown)
├── postgres_client.py # PostgreSQL-specific operations
├── mysql_client.py # MySQL-specific operations
└── mongodb_client.py # MongoDB-specific operationsDevelopment
# Run in development mode with auto-reload (requires watching tool)
uv run watch -c "python main.py" .Dependencies
Package | Purpose |
| Model Context Protocol framework |
| PostgreSQL async driver |
| MySQL async driver |
| MongoDB async driver |
| Environment variable management |
Running Tests
Tests are not yet implemented.
License
MIT
Changelog
v1.2.0 (2026-02-19)
Added MCP middleware support (
src/lib/middleware.py)Added MCP utilities module (
src/lib/mcp.py)Added ruff code formatter and linter configuration
v1.1.0 (2026-02-14)
Added MongoDB support with PyMongo async driver
New
mongodb_client.pywith full CRUD operations (find, insert, update, delete, aggregate, count)Schema inference for
describe_tablevia document samplingConnection pooling support for MongoDB
Updated documentation with provider-specific examples
v1.0.0 (2026-02-05)
Initial release
Added Streamable HTTP transport support for MCP
Separated HTTP host configuration into dedicated environment variable
Added comprehensive README documentation
Improved server module organization (moved server.py to src/server.py)
Added example .env configuration file
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/echatzief/database-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server