Universal MCP server for multiple database connections and operations
Project description
MCP Database Server
๐ Universal Database Connector for AI Assistants
Connect to ANY database (SQL Server, PostgreSQL, MySQL, MongoDB, Redis, SQLite) through your AI assistant with just a simple configuration!
A universal MCP (Model Context Protocol) server that provides seamless connections to multiple database types. This server enables AI assistants like Claude to interact with your databases through a unified interface.
๐ฆ Quick Install
# Install with uv (recommended)
uv add mcp-universal-database-server
# Or install with pip
pip install mcp-universal-database-server
๐ง Simple Setup
Option 1: Basic Setup
Add this to your ~/.cursor/mcp.json or .vscode/settings.json:
{
"mcpServers": {
"mcp-database-server": {
"command": "mcp-universal-database-server",
"args": ["serve"]
}
}
}
Option 2: DSN Setup (Recommended)
Use DSN strings for instant database connections:
{
"mcpServers": {
"mcp-database-server": {
"command": "mcp-universal-database-server",
"args": ["serve"],
"env": {
"DSN": "postgresql://user:pass@localhost:5432/mydb?sslmode=disable",
"SQLSERVER_DSN": "sqlserver://sa:pass@localhost:1433/MyDB?sslmode=disable"
}
}
}
}
That's it! Your AI assistant can now connect to any database. Just ask: "Connect to my database"
๐ Features
- Universal Database Support: Connect to PostgreSQL, MySQL, SQLite, MongoDB, Redis, SQL Server, and more
- DSN Support: Easy configuration with Data Source Name strings - just paste your connection string!
- MCP Integration: Seamless integration with VSCode, Cursor, and other MCP-compatible tools
- Auto-Discovery: Automatically loads database connections from environment variables
- Secure Connections: Support for SSL/TLS and connection pooling
- Rich Operations: Full CRUD operations, schema management, and query execution
- Type Safety: Built with Python type hints and Pydantic models
- Easy Installation: Install via
uvpackage manager
๐ฆ Supported Databases
SQL Databases
- PostgreSQL - Advanced open-source relational database
- MySQL - Popular open-source relational database
- SQLite - Lightweight file-based SQL database
- Microsoft SQL Server (planned)
- Oracle Database (planned)
NoSQL Databases
- MongoDB - Document-oriented database
- Redis - In-memory key-value store
- Apache Cassandra (planned)
Cloud Databases
- Google Firestore (planned)
- Amazon DynamoDB (planned)
- Azure Cosmos DB (planned)
๐ ๏ธ Installation
Using uv (Recommended)
# Install from PyPI (once published)
uv add mcp-database-server
# Or install from source
uv add git+https://github.com/yourusername/mcp-database-server.git
Using pip
pip install mcp-database-server
๐ง Configuration
1. Generate Configuration
mcp-database-server generate-config --output mcp_config.json
2. Configure VSCode/Cursor
Add to your MCP settings file (.vscode/settings.json or Cursor equivalent):
{
"mcp.servers": {
"mcp-database-server": {
"command": "mcp-database-server",
"args": ["serve"]
}
}
}
3. Add Database Connections
Use the MCP tools in your AI assistant to add connections:
Add a PostgreSQL connection:
- Name: my_postgres
- Type: postgresql
- Host: localhost
- Port: 5432
- Username: myuser
- Password: mypassword
- Database: mydatabase
๐ Usage
Starting the Server
# Start MCP server (typically called by your editor)
mcp-database-server serve
# Test a connection
mcp-database-server test-connection \
--type postgresql \
--host localhost \
--port 5432 \
my_postgres
# List supported database types
mcp-database-server list-supported
Available MCP Tools
Once configured, you can use these tools through your AI assistant:
Connection Management
add_connection- Add a new database connectionremove_connection- Remove a database connectionlist_connections- List all configured connectionstest_connection- Test a specific connection
Schema Operations
get_schema_info- Get database schema informationget_table_info- Get detailed table informationlist_databases- List available databaseslist_tables- List tables in a database/schema
Data Operations
execute_query- Execute SQL queries or database commandsinsert_data- Insert data into tables/collectionsupdate_data- Update data in tables (SQL databases)delete_data- Delete data from tables/collections
Table Management (SQL)
create_table- Create new tablesdrop_table- Drop tables
Collection Management (NoSQL)
create_collection- Create new collectionsfind_documents- Find documents in collectionsupdate_documents- Update documents in collections
๐ Examples
Example 1: PostgreSQL Connection
# Through MCP tools in your AI assistant:
# 1. Add connection
add_connection(
name="my_postgres",
type="postgresql",
host="localhost",
port=5432,
username="myuser",
password="mypassword",
database="mydb"
)
# 2. Execute query
execute_query(
connection_name="my_postgres",
query="SELECT * FROM users WHERE active = $1",
parameters={"active": true}
)
Example 2: MongoDB Connection
# 1. Add MongoDB connection
add_connection(
name="my_mongo",
type="mongodb",
host="localhost",
port=27017,
username="myuser",
password="mypassword",
database="mydb"
)
# 2. Find documents
find_documents(
connection_name="my_mongo",
collection_name="users",
filter_query={"status": "active"},
limit=10
)
Example 3: SQLite Connection
# 1. Add SQLite connection
add_connection(
name="my_sqlite",
type="sqlite",
database="/path/to/database.db"
)
# 2. Get schema info
get_schema_info(connection_name="my_sqlite")
๐ Security
- Connection Security: All connections support SSL/TLS encryption
- Credential Management: Passwords are handled securely and not logged
- Connection Pooling: Efficient connection management with automatic cleanup
- Input Validation: All inputs are validated using Pydantic models
๐งช Development
Setup Development Environment
# Clone repository
git clone https://github.com/yourusername/mcp-database-server.git
cd mcp-database-server
# Install with uv
uv sync --dev
# Run tests
uv run pytest
# Format code
uv run black src/
uv run ruff check src/
Project Structure
mcp-database-server/
โโโ src/mcp_database_server/
โ โโโ __init__.py
โ โโโ server.py # Main MCP server
โ โโโ connection_manager.py # Connection management
โ โโโ database_factory.py # Database factory
โ โโโ types.py # Type definitions
โ โโโ cli.py # CLI interface
โ โโโ databases/ # Database drivers
โ โโโ base.py # Base classes
โ โโโ postgresql.py # PostgreSQL driver
โ โโโ mysql.py # MySQL driver
โ โโโ sqlite.py # SQLite driver
โ โโโ mongodb.py # MongoDB driver
โ โโโ redis.py # Redis driver
โโโ tests/ # Test files
โโโ pyproject.toml # Project configuration
โโโ README.md
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
Adding New Database Support
- Create a new driver in
src/mcp_database_server/databases/ - Inherit from
SQLDatabaseorNoSQLDatabasebase class - Implement all required methods
- Register the driver in
database_factory.py - Add appropriate dependencies to
pyproject.toml - Write tests for the new driver
๐ Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Documentation: GitHub Wiki
๐ Acknowledgments
- Model Context Protocol (MCP) for the protocol specification
- All the amazing database driver maintainers
- The Python async ecosystem
Made with โค๏ธ for the AI and database communities
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mcp_universal_database_server-0.3.2.tar.gz.
File metadata
- Download URL: mcp_universal_database_server-0.3.2.tar.gz
- Upload date:
- Size: 33.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee6b5bf2165b0b0c3a0be342582d1278f6fa2ee2c35dbd6f46497614e7d5a49b
|
|
| MD5 |
8855b9dc340889d2a86e1bfe46bd54a4
|
|
| BLAKE2b-256 |
291729036705544f243adf347dfbacd882b01acc50c6bf881cc3e8ff4ece8b30
|
File details
Details for the file mcp_universal_database_server-0.3.2-py3-none-any.whl.
File metadata
- Download URL: mcp_universal_database_server-0.3.2-py3-none-any.whl
- Upload date:
- Size: 44.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8e3ae90754e5ce3bfa667d9b822132585d15a9aa0c8f959c537e5d1cfc5bd373
|
|
| MD5 |
3ec24da8d1cb52c2840eadbbed739b08
|
|
| BLAKE2b-256 |
05f516fedbb801ebc9186bac2b99b4476963194aef5678c2ca18faf5d5025871
|