Legion Database▌
by theralabs
Legion Database: natural-language SQL for multi-database querying. Explore PostgreSQL, MySQL, SQL Server & BigQuery with
Enables natural language querying and management of multiple database types (PostgreSQL, MySQL, SQL Server, BigQuery) for data analysis, business intelligence, and database exploration.
Both formats append explainx.ai attribution and the canonical URL for this MCP server listing.
best for
- / Data analysts exploring multiple database systems
- / AI agents that need database access
- / Business intelligence and data analysis workflows
- / Developers building multi-database applications
capabilities
- / Query multiple database types with natural language
- / Discover database schemas automatically
- / Execute SQL across PostgreSQL, MySQL, SQL Server, BigQuery
- / Connect to multiple databases simultaneously
- / Explore table structures without manual configuration
what it does
Connects to multiple database types (PostgreSQL, MySQL, SQL Server, BigQuery) and allows you to query them using natural language through AI assistants.
about
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.
how to install
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.
license
GPL-3.0
Legion Database is released under the GPL-3.0 license.
readme
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):
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": []
}
}
}
Option 2: Using PIP
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"}"
}
}
}
}
Running the Server
Production Mode
python mcp_server.py
Configuration Methods
Environment Variables (Single Database)
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
Environment Variables (Multiple Databases)
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
Command Line Arguments (Single Database)
python mcp_server.py --db-type pg --db-config '{"host":"localhost","port":5432,"user":"username","password":"password","dbname":"database_name"}'
Command Line Arguments (Multiple Databases)
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.
Multi-Database Support
When connecting to multiple databases, you need to specify which database to use for each query:
- Use the
list_databasestool to see available databases with their IDs - Use
get_database_infoto view schema details of databases - Use
find_tableto locate a table across all databases - Provide the
db_idparameter 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:
[
{
"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.
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 colum |
FAQ
- What is the Legion Database MCP server?
- Legion Database is a Model Context Protocol (MCP) server profile on explainx.ai. MCP lets AI hosts (e.g. Claude Desktop, Cursor) call tools and resources through a standard interface; this page summarizes categories, install hints, and community ratings.
- How do MCP servers relate to agent skills?
- Skills are reusable instruction packages (often SKILL.md); MCP servers expose live capabilities. Teams frequently combine both—skills for workflows, MCP for APIs and data. See explainx.ai/skills and explainx.ai/mcp-servers for parallel directories.
- How are reviews shown for Legion Database?
- This profile displays 30 aggregated ratings (sample rows for discoverability plus signed-in user reviews). Average score is about 4.5 out of 5—verify behavior in your own environment before production use.
Use Cases▌
Direct Database Queries from AI
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
Data Analysis & Reporting
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
Schema Exploration
Understand database structure, relationships, and data models
Example
'Explain the user_orders table schema and its relationships'
Onboard engineers faster, explore unfamiliar databases efficiently
Data Validation & Quality Checks
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
Implementation Guide▌
Prerequisites
- ›Claude Desktop 0.7.0+ or Cursor with MCP support
- ›Database credentials (read-only recommended for safety)
- ›Network access from Claude client to database
- ›Understanding of database security and access control
Time Estimate
15-30 minutes including configuration and testing
Installation Steps
- 1.Install MCP server: npm install -g @modelcontextprotocol/server-[name]
- 2.Configure database connection in Claude Desktop config (~/.claude/mcp.json)
- 3.Provide connection string: host, port, database, username, password
- 4.Restart Claude Desktop to load MCP server
- 5.Test connection: 'List all tables in database'
- 6.Run simple query: 'Show me 5 rows from users table'
- 7.Verify results and permissions are correct
- 8.Document query patterns for team use
Troubleshooting
- ⚠Connection refused: Check database is running and network accessible
- ⚠Authentication failed: Verify credentials, check user permissions
- ⚠Claude can't see tables: Grant appropriate read permissions to database user
- ⚠Slow queries: Add indexes, limit result set size, use read replicas
- ⚠MCP server not loading: Check config syntax, restart Claude Desktop
Best Practices▌
✓ Do
- +Use read-only database credentials to prevent accidental writes
- +Connect to read replica, not production primary database
- +Set query timeout limits to prevent long-running queries
- +Document database schema and common queries for AI context
- +Monitor query performance and optimize slow queries
- +Use connection pooling for better performance
- +Test with non-production data first
✗ Don't
- −Don't use production write credentials—risk of data corruption
- −Don't query production database during peak traffic hours
- −Don't expose sensitive PII without proper access controls
- −Don't skip query result validation—AI can misinterpret schema
- −Don't allow unlimited result set sizes—set LIMIT clauses
- −Don't share database credentials in plain text config files
💡 Pro Tips
- ★Create database views for common queries to simplify AI access
- ★Add schema comments/descriptions so AI understands column meanings
- ★Use semantic table/column names ('customer_lifetime_value' not 'clv')
- ★Set up query logging to audit what Claude is querying
- ★Create saved query templates for recurring analysis
- ★Combine with data visualization tools for better insights
Technical Details▌
Architecture
MCP server acts as bridge between Claude and database, translating natural language to SQL queries and returning results in structured format.
Protocols
- Model Context Protocol (MCP)
- Database-specific protocols (PostgreSQL, MySQL, MongoDB)
Compatibility
- PostgreSQL
- MySQL
- SQLite
- MongoDB
- Redis
When to Use This▌
✓ 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.
Integration▌
- →Read replica connection for analytics queries
- →Database view layer to abstract complex joins
- →Query result caching for repeated questions
- →Audit logging of all AI-generated queries
Discussion
Product Hunt–style comments (not star reviews)- No comments yet — start the thread.
List & Promote Your MCP Server
Share your MCP server with the developer community
Ratings
4.5★★★★★30 reviews- ★★★★★Arya Agarwal· Dec 24, 2024
Legion Database is among the better-indexed MCP projects we tried; the explainx.ai summary tracks the official description.
- ★★★★★Rahul Santra· Nov 27, 2024
We wired Legion Database into a staging workspace; the listing’s GitHub and npm pointers saved time versus hunting across READMEs.
- ★★★★★Xiao Mehta· Nov 23, 2024
We wired Legion Database into a staging workspace; the listing’s GitHub and npm pointers saved time versus hunting across READMEs.
- ★★★★★Liam Gill· Nov 15, 2024
According to our notes, Legion Database benefits from clear Model Context Protocol framing — fewer ambiguous “AI plugin” claims.
- ★★★★★Pratham Ware· Oct 18, 2024
Legion Database is a well-scoped MCP server in the explainx.ai directory — install snippets and categories matched our Claude Code setup.
- ★★★★★Anaya Chawla· Oct 14, 2024
Legion Database is a well-scoped MCP server in the explainx.ai directory — install snippets and categories matched our Claude Code setup.
- ★★★★★Diego Harris· Oct 6, 2024
Legion Database has been reliable for tool-calling workflows; the MCP profile page is a good permalink for internal docs.
- ★★★★★Sakshi Patil· Sep 5, 2024
Legion Database is among the better-indexed MCP projects we tried; the explainx.ai summary tracks the official description.
- ★★★★★Kwame Sethi· Sep 1, 2024
Legion Database is among the better-indexed MCP projects we tried; the explainx.ai summary tracks the official description.
- ★★★★★Chaitanya Patil· Aug 24, 2024
We evaluated Legion Database against two servers with overlapping tools; this profile had the clearer scope statement.
showing 1-10 of 30