by theralabs
Legion Database: natural-language SQL for multi-database querying. Explore PostgreSQL, MySQL, SQL Server & BigQuery with
Connects to multiple database types (PostgreSQL, MySQL, SQL Server, BigQuery) and allows you to query them using natural language through AI assistants.
Legion Database is a community-built MCP server published by theralabs that provides AI assistants with tools and capabilities via the Model Context Protocol. Legion Database: natural-language SQL for multi-database querying. Explore PostgreSQL, MySQL, SQL Server & BigQuery with It is categorized under databases, ai ml.
You can install Legion Database in your AI client of choice. Use the install panel on this page to get one-click setup for Cursor, Claude Desktop, VS Code, and other MCP-compatible clients. This server runs locally on your machine via the stdio transport.
GPL-3.0
Legion Database is released under the GPL-3.0 license.
Enable Claude to query your database directly using natural language
Example
Ask 'Show me top 10 customers by revenue this month' and get SQL results instantly
Eliminate manual SQL writing for ad-hoc queries, get insights 10x faster
Generate complex reports and analytics without leaving conversation
Example
Analyze sales trends, cohort retention, user behavior patterns conversationally
Democratize data access—non-technical team members can query databases
Understand database structure, relationships, and data models
Example
'Explain the user_orders table schema and its relationships'
Onboard engineers faster, explore unfamiliar databases efficiently
Share your MCP server with the developer community
Legion Database is among the better-indexed MCP projects we tried; the explainx.ai summary tracks the official description.
We wired Legion Database into a staging workspace; the listing’s GitHub and npm pointers saved time versus hunting across READMEs.
We wired Legion Database into a staging workspace; the listing’s GitHub and npm pointers saved time versus hunting across READMEs.
According to our notes, Legion Database benefits from clear Model Context Protocol framing — fewer ambiguous “AI plugin” claims.
Legion Database is a well-scoped MCP server in the explainx.ai directory — install snippets and categories matched our Claude Code setup.
Legion Database is a well-scoped MCP server in the explainx.ai directory — install snippets and categories matched our Claude Code setup.
Legion Database has been reliable for tool-calling workflows; the MCP profile page is a good permalink for internal docs.
Legion Database is among the better-indexed MCP projects we tried; the explainx.ai summary tracks the official description.
Legion Database is among the better-indexed MCP projects we tried; the explainx.ai summary tracks the official description.
We evaluated Legion Database against two servers with overlapping tools; this profile had the clearer scope statement.
showing 1-10 of 30
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.
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.
Database MCP stands out from other database access solutions for several compelling reasons:
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.
| 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.
The Model Context Protocol (MCP) is a specification for maintaining context in AI applications. This server uses the MCP Python SDK to:
For single database configuration:
For multi-database configuration:
The configuration format varies by database type. See the API documentation for database-specific configuration details.
When using uv, no specific installation is needed. We will use uvx to directly run database-mcp.
UV Configuration Example (Single Database):
REPLACE DB_TYPE and DB_CONFIG with your connection info.
{
"mcpServers": {
"database-mcp": {
"command": "uvx",
"args": [
"database-mcp"
],
"env": {
"DB_TYPE": "pg",
"DB_CONFIG": "{"host":"localhost","port":5432,"user":"user","password":"pw","dbname":"dbname"}"
},
"disabled": true,
"autoApprove": []
}
}
}
UV Configuration Example (Multiple Databases):
{
"mcpServers": {
"database-mcp": {
"command": "uvx",
"args": [
"database-mcp"
],
"env": {
"DB_CONFIGS": "[{"id":"pg_main","db_type":"pg","configuration":{"host":"localhost","port":5432,"user":"user","password":"pw","dbname":"postgres"},"description":"PostgreSQL Database"},{"id":"mysql_data","db_type":"mysql","configuration":{"host":"localhost","port":3306,"user":"root","password":"pass","database":"mysql"},"description":"MySQL Database"}]"
},
"disabled": true,
"autoApprove": []
}
}
}
Install via pip:
pip install database-mcp
PIP Configuration Example (Single Database):
{
"mcpServers": {
"database": {
"command": "python",
"args": [
"-m", "database_mcp",
"--repository", "path/to/git/repo"
],
"env": {
"DB_TYPE": "pg",
"DB_CONFIG": "{"host":"localhost","port":5432,"user":"user","password":"pw","dbname":"dbname"}"
}
}
}
}
python mcp_server.py
export DB_TYPE="pg" # or mysql, postgresql, etc.
export DB_CONFIG='{"host":"localhost","port":5432,"user":"username","password":"password","dbname":"database_name"}'
uv run src/database_mcp/mcp_server.py
export DB_CONFIGS='[{"id":"pg_main","db_type":"pg","configuration":{"host":"localhost","port":5432,"user":"username","password":"password","dbname":"database_name"},"description":"PostgreSQL Database"},{"id":"mysql_users","db_type":"mysql","configuration":{"host":"localhost","port":3306,"user":"root","password":"pass","database":"mysql"},"description":"MySQL Database"}]'
uv run src/database_mcp/mcp_server.py
If you don't specify an ID, the system will generate one automatically based on the database type and description:
export DB_CONFIGS='[{"db_type":"pg","configuration":{"host":"localhost","port":5432,"user":"username","password":"password","dbname":"database_name"},"description":"PostgreSQL Database"},{"db_type":"mysql","configuration":{"host":"localhost","port":3306,"user":"root","password":"pass","database":"mysql"},"description":"MySQL Database"}]'
# IDs will be generated as something like "pg_postgres_0" and "my_mysqldb_1"
uv run src/database_mcp/mcp_server.py
python mcp_server.py --db-type pg --db-config '{"host":"localhost","port":5432,"user":"username","password":"password","dbname":"database_name"}'
python mcp_server.py --db-configs '[{"id":"pg_main","db_type":"pg","configuration":{"host":"localhost","port":5432,"user":"username","password":"password","dbname":"database_name"},"description":"PostgreSQL Database"},{"id":"mysql_users","db_type":"mysql","configuration":{"host":"localhost","port":3306,"user":"root","password":"pass","database":"mysql"},"description":"MySQL Database"}]'
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.
When connecting to multiple databases, you need to specify which database to use for each query:
list_databases tool to see available databases with their IDsget_database_info to view schema details of databasesfind_table to locate a table across all databasesdb_id parameter to tools like execute_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.
Database schemas are represented as a list of table objects, with each table containing information about its columns:
[
{
"name": "users",
"columns": [
{"name": "id", "type": "integer"},
{"name": "username", "type": "varchar"},
{"name": "email", "type": "varchar"}
]
},
{
"name": "orders",
"columns": [
{"name": "id", "type": "integer"},
{"name": "user_id", "type": "integer"},
{"name": "product_id", "type": "integer"},
{"name": "quantity", "type": "integer"}
]
}
]
This representation makes it easy to programmatically access table and column information while keeping a clean hierarchical structure.
| Resource | Description |
|---|---|
resource://schema/{database_id} | Get the schemas for one or all configured databases |
| 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 colum |
Run data quality queries to catch anomalies and inconsistencies
Example
Find duplicate records, missing values, orphaned foreign keys automatically
Maintain data integrity with less manual SQL work
Prerequisites
Time Estimate
15-30 minutes including configuration and testing
Steps
Troubleshooting
✓ Do
✗ Don't
💡 Pro Tips
Architecture
MCP server acts as bridge between Claude and database, translating natural language to SQL queries and returning results in structured format.
Protocols
Compatibility
✓ Use when
Use for ad-hoc data queries, exploratory analysis, report generation, schema exploration, and democratizing data access. Best for read-heavy analytics workloads.
✗ Avoid when
Avoid for production write operations, mission-critical transactions, real-time OLTP workloads, or when database contains sensitive PII without proper access controls. Use read replicas, not primary.