Supports integration with FastAPI for running the MCP server, providing both standalone and integrated deployment options
Provides database access capabilities for MySQL, supporting query execution and schema exploration
Enables querying and interacting with PostgreSQL databases through SQL execution tools and schema resources
Multi-Database MCP Server (by Legion AI)
A server that helps people access and query data in databases using the Legion Query Runner with integration of the Model Context Protocol (MCP) Python SDK.
Start Generation Here
This tool is provided by Legion AI. To use the full-fledged and fully powered AI data analytics tool, please visit the site. Email us if there is one database you want us to support.
End Generation Here
Why Choose Database MCP
Database MCP stands out from other database access solutions for several compelling reasons:
- Unified Multi-Database Interface: Connect to PostgreSQL, MySQL, SQL Server, and other databases through a single consistent API - no need to learn different client libraries for each database type.
- AI-Ready Integration: Built specifically for AI assistant interactions through the Model Context Protocol (MCP), enabling natural language database operations.
- Zero-Configuration Schema Discovery: Automatically discovers and exposes database schemas without manual configuration or mapping.
- Database-Agnostic Tools: Find tables, explore schemas, and execute queries with the same set of tools regardless of the underlying database technology.
- Secure Credential Management: Handles database authentication details securely, separating credentials from application code.
- Simple Deployment: Works with modern AI development environments like LangChain, FastAPI, and others with minimal setup.
- Extensible Design: Easily add custom tools and prompts to enhance functionality for specific use cases.
Whether you're building AI agents that need database access or simply want a unified interface to multiple databases, Database MCP provides a streamlined solution that dramatically reduces development time and complexity.
Features
- Multi-database support - connect to multiple databases simultaneously
- Database access via Legion Query Runner
- Model Context Protocol (MCP) support for AI assistants
- Expose database operations as MCP resources, tools, and prompts
- Multiple deployment options (standalone MCP server, FastAPI integration)
- Query execution and result handling
- Flexible configuration via environment variables, command-line arguments, or MCP settings JSON
- User-driven database selection for multi-database setups
Supported Databases
Database | DB_TYPE code |
---|---|
PostgreSQL | pg |
Redshift | redshift |
CockroachDB | cockroach |
MySQL | mysql |
RDS MySQL | rds_mysql |
Microsoft SQL Server | mssql |
Big Query | bigquery |
Oracle DB | oracle |
SQLite | sqlite |
We use Legion Query Runner library as connectors. You can find more info on their api doc.
What is MCP?
The Model Context Protocol (MCP) is a specification for maintaining context in AI applications. This server uses the MCP Python SDK to:
- Expose database operations as tools for AI assistants
- Provide database schemas and metadata as resources
- Generate useful prompts for database operations
- Enable stateful interactions with databases
Installation & Configuration
Required Parameters
For single database configuration:
- DB_TYPE: The database type code (see table above)
- DB_CONFIG: A JSON configuration string for database connection
For multi-database configuration:
- DB_CONFIGS: A JSON array of database configurations, each containing:
- db_type: The database type code
- configuration: Database connection configuration
- description: A human-readable description of the database
The configuration format varies by database type. See the API documentation for database-specific configuration details.
Installation Methods
Option 1: Using UV (Recommended)
When using uv
, no specific installation is needed. We will use uvx
to directly run database-mcp.
UV Configuration Example (Single Database):
UV Configuration Example (Multiple Databases):
Option 2: Using PIP
Install via pip:
PIP Configuration Example (Single Database):
Running the Server
Production Mode
Configuration Methods
Environment Variables (Single Database)
Environment Variables (Multiple Databases)
If you don't specify an ID, the system will generate one automatically based on the database type and description:
Command Line Arguments (Single Database)
Command Line Arguments (Multiple Databases)
Note that you can specify custom IDs for each database using the id
field, or let the system generate them based on database type and description.
Multi-Database Support
When connecting to multiple databases, you need to specify which database to use for each query:
- Use the
list_databases
tool to see available databases with their IDs - Use
get_database_info
to view schema details of databases - Use
find_table
to locate a table across all databases - Provide the
db_id
parameter to tools likeexecute_query
,get_table_columns
, etc.
Database connections are managed internally as a dictionary of DbConfig
objects, with each database having a unique ID. Schema information is represented as a list of table objects, where each table contains its name and column information.
The select_database
prompt guides users through the database selection process.
Schema Representation
Database schemas are represented as a list of table objects, with each table containing information about its columns:
This representation makes it easy to programmatically access table and column information while keeping a clean hierarchical structure.
Exposed MCP Capabilities
Resources
Resource | Description |
---|---|
resource://schema/{database_id} | Get the schemas for one or all configured databases |
Tools
Tool | Description |
---|---|
execute_query | Execute a SQL query and return results as a markdown table |
execute_query_json | Execute a SQL query and return results as JSON |
get_table_columns | Get column names for a specific table |
get_table_types | Get column types for a specific table |
get_query_history | Get the recent query history |
list_databases | List all available database connections |
get_database_info | Get detailed information about a database including schema |
find_table | Find which database contains a specific table |
describe_table | Get detailed description of a table including column names and types |
get_table_sample | Get a sample of data from a table |
All database-specific tools (like execute_query
, get_table_columns
, etc.) require a db_id
parameter to specify which database to use.
Prompts
Prompt | Description |
---|---|
sql_query | Create an SQL query against the database |
explain_query | Explain what a SQL query does |
optimize_query | Optimize a SQL query for better performance |
select_database | Help user select which database to use |
Development
Using MCP Inspector
run this to start the inspector
then in the command input field, set something like
Testing
Publishing
License
This repository is licensed under GPL
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
A server that helps people access and query data in databases using the Query Runner with integration of the Model Context Protocol (MCP) Python SDK. Supported by Legion AI team (thelegionai.com)
Support databases including PostgreSQL Redshift MySQL Microsoft SQL Server Google APIs Amazon Web Services (via boto3) CockroachDB SQLite
Related MCP Servers
- -securityFlicense-qualityA server that enables interaction with PostgreSQL, MySQL, MariaDB, or SQLite databases through Claude Desktop using natural language queries.Last updated -Python
- -securityAlicense-qualityThis is a Model Context Protocol (MCP) server for executing SQL queries against Databricks using the Statement Execution API. It enables AI assistants to directly query Databricks data warehouses, analyze database schemas, and retrieve query results in a structured formatLast updated -8PythonMIT License
- -securityAlicense-qualityA Model Context Protocol server that provides Claude access to Turso-hosted LibSQL databases, enabling database table listing, schema retrieval, and SELECT query execution.Last updated -685TypeScriptMIT License
- -securityAlicense-qualityAn MCP server that enables MySQL database integration with Claude. You can execute SQL queries and manage database connections.Last updated -1PythonMIT License