Skip to main content

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 uv package 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 connection
  • remove_connection - Remove a database connection
  • list_connections - List all configured connections
  • test_connection - Test a specific connection

Schema Operations

  • get_schema_info - Get database schema information
  • get_table_info - Get detailed table information
  • list_databases - List available databases
  • list_tables - List tables in a database/schema

Data Operations

  • execute_query - Execute SQL queries or database commands
  • insert_data - Insert data into tables/collections
  • update_data - Update data in tables (SQL databases)
  • delete_data - Delete data from tables/collections

Table Management (SQL)

  • create_table - Create new tables
  • drop_table - Drop tables

Collection Management (NoSQL)

  • create_collection - Create new collections
  • find_documents - Find documents in collections
  • update_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

  1. Create a new driver in src/mcp_database_server/databases/
  2. Inherit from SQLDatabase or NoSQLDatabase base class
  3. Implement all required methods
  4. Register the driver in database_factory.py
  5. Add appropriate dependencies to pyproject.toml
  6. Write tests for the new driver

๐Ÿ“ž Support

๐Ÿ™ Acknowledgments


Made with โค๏ธ for the AI and database communities

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_universal_database_server-0.3.1.tar.gz (33.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_universal_database_server-0.3.1-py3-none-any.whl (44.1 kB view details)

Uploaded Python 3

File details

Details for the file mcp_universal_database_server-0.3.1.tar.gz.

File metadata

File hashes

Hashes for mcp_universal_database_server-0.3.1.tar.gz
Algorithm Hash digest
SHA256 e7698420ebf2abb634ca00c486065054b1c2840ff333dd1b735332338c03d023
MD5 4262106c2b2814e15bf6bb415bbcc347
BLAKE2b-256 47ef37b921d75d37d23b5bf1d17d4bcf8a43aef154a476f3fd9fd404a34ad691

See more details on using hashes here.

File details

Details for the file mcp_universal_database_server-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_universal_database_server-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b18e2b98b178485d317552c55210e96102768e6aa989819a5e8a0a6d9a72e736
MD5 86c3b166f179a695fcbd0fe90fbb42cb
BLAKE2b-256 494eeeaf7979027831fb7dda8ec4184f5aec230d4d8741943b145d89b71c150b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page