Database MCP Server
A Model Context Protocol (MCP) server that provides tools for connecting to and interacting with various database systems.
Features
- Multi-Database Support: Connect to SQLite, PostgreSQL, MySQL/MariaDB, and SQL Server databases
- Unified Interface: Common tools for database operations across all supported database types
- Database-Specific Extensions: Where needed, specific tools for database-specific features
- Schema Management: Create, alter, and drop tables and indexes
- Query Execution: Execute raw SQL queries or use structured query tools
- Transaction Support: Begin, commit, and rollback transactions
Installation
Prerequisites
- Python 3.8 or higher
- Required Python packages (installed automatically with pip):
- SQLAlchemy
- Various database drivers, depending on which databases you want to use:
- SQLite (included with Python)
- PostgreSQL:
psycopg2-binary
- MySQL/MariaDB:
mysql-connector-python
- SQL Server:
pyodbc
Installing from Source
Configuration
The server can be configured using environment variables, a configuration file, or by providing connection details at runtime.
Environment Variables
DB_CONFIG_PATH
: Path to a JSON configuration fileDB_CONNECTIONS
: A comma-separated list of connection IDs or a JSON string with connection details
Configuration File Format
Usage
Running the Server
As an MCP Server for Claude
As a Standalone Web Server (for any LLM)
Available MCP Tools
Connection Management
add_connection
: Add a new database connectiontest_connection
: Test a database connectionlist_connections
: List all database connectionsremove_connection
: Remove a database connection
Query Execution
execute_query
: Execute a SQL queryget_records
: Get records from a tableinsert_record
: Insert a record into a tableupdate_record
: Update records in a tabledelete_record
: Delete records from a table
Schema Management
list_tables
: List all tables in a databaseget_table_schema
: Get the schema for a tablecreate_table
: Create a new tabledrop_table
: Drop a tablecreate_index
: Create an index on a tabledrop_index
: Drop an indexalter_table
: Alter a table structure
Transaction Management
begin_transaction
: Begin a transactioncommit_transaction
: Commit a transactionrollback_transaction
: Rollback a transaction
Examples
Add a Connection
Execute a Query
Create a Table
Insert Records
Development
Running Tests
Connecting from Other LLMs
When running as a standalone web server, other LLMs (like Llama 3) can connect to the database MCP server via HTTP. The server exposes the following endpoints:
Endpoints
/list_tools
- GET or POST: Returns a list of all available tools with their descriptions and input schemas/call_tool
- POST: Execute a specific database tool
Example: Calling from Another LLM
To use this server with another LLM, have the LLM generate HTTP requests to the server. Here's an example of how you could structure the prompt for an LLM like Llama 3:
Sample Python Code for Client Integration
License
This server cannot be installed
A Model Context Protocol server that provides tools for connecting to and interacting with various database systems (SQLite, PostgreSQL, MySQL/MariaDB, SQL Server) through a unified interface.