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

Add this to your ~/.cursor/mcp.json or .vscode/settings.json:

{
  "mcpServers": {
    "mcp-database-server": {
      "command": "mcp-universal-database-server",
      "args": ["serve"]
    }
  }
}

That's it! Your AI assistant can now connect to any database. Just ask: "Connect to my SQL Server database"

๐Ÿš€ Features

  • Universal Database Support: Connect to PostgreSQL, MySQL, SQLite, MongoDB, Redis, and more
  • MCP Integration: Seamless integration with VSCode, Cursor, and other MCP-compatible tools
  • 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.2.0.tar.gz (32.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.2.0-py3-none-any.whl (43.0 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for mcp_universal_database_server-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f56a881f7516bc73f31fc97153b3fb439434a84ec28b9c474b1b918b40763345
MD5 6acca333a34817f5e394eede1929791f
BLAKE2b-256 b4dc4d5ede78ab6adfa29eab0d8cf2f10fc9f69ef14a80c30c2ab47d5506fe53

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mcp_universal_database_server-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed06a630e9bebdba577f445219dc14f9c2f8e90d65fd9d8a412b4a110ed896b0
MD5 04809606542a468a49cd6ef7a46b8e79
BLAKE2b-256 194c7fbc0bbabc658f8368b111c0609047e383cd15da7d39f167d28500d1d693

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