Skip to main content

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

Metadata

Release files for mcp-universal-database-server 0.3.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcp-universal-database-server 0.3.5
File Size Uploaded Provenance
mcp_universal_database_server-0.3.5.tar.gz 33.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mcp-universal-database-server 0.3.5
File Interpreter ABI Platform
mcp_universal_database_server-0.3.5-py3-none-any.whl Python 3 none any Details

Total release size: 78.4 kB

Release files / mcp_universal_database_server-0.3.5.tar.gz

Download URL mcp_universal_database_server-0.3.5.tar.gz
Size 33.7 kB
Tags Source
SHA-256 checksum
How to use checksums
8faae3a6c7a41deea5453437fac8e991a1dab8499e07dee7a5a0b1cb3268314d
BLAKE2b-256 checksum
How to use checksums
95f169e8b23910d049f58e1d39dad16d35c3a161696f9e26fee17e0a57bea691
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.4

Release files / mcp_universal_database_server-0.3.5-py3-none-any.whl

Download URL mcp_universal_database_server-0.3.5-py3-none-any.whl
Size 44.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d0cd459282be8a8fe2ea4a62d158b395213aedd7f4b14f7637b63b9feb6958fd
BLAKE2b-256 checksum
How to use checksums
1380fd1ce929da66a5131d89bdc7ffcf00866b4b1ba569ef07486d78e37fb4cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.4

Security for mcp-universal-database-server 0.3.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page