Legion
A server that helps people access and query data in databases using the Legion Query Runner with Model Context Protocol (MCP) in Python.
What is Legion?
Legion is a Model Context Protocol (MCP) server that allows AI assistants like Claude, Cursor, and VS Code to server that helps people access and query data in databases using the legion query runner with model context protocol (mcp) in python.
A server that helps people access and query data in databases using the Legion Query Runner with Model Context Protocol (MCP) in Python.
This server falls under the Databases category on MCPgee, the world's largest MCP server directory with 33,000+ servers.
Features
- A server that helps people access and query data in database
Use Cases
Maintainer
Works with
Installation
Manual Installation
npx legionConfiguration
Configuration Details
claude_desktop_config.json
Performance
Response Metrics
Resource Usage
How to Set Up and Use Legion
Legion MCP (also published as database-mcp) is a Python-based Model Context Protocol server that enables AI assistants to query and explore databases through the Legion Query Runner. It supports PostgreSQL, MySQL, Microsoft SQL Server, BigQuery, Oracle, SQLite, and more, exposing nine tools for executing queries, exploring schema, listing databases, and retrieving table samples. Data analysts and developers use it to let Claude run SQL queries, explain query plans, and browse database structure through natural language without writing raw SQL themselves.
Prerequisites
- Python 3.9+ with pip or uv package manager installed
- An MCP-compatible client such as Claude Desktop, Cursor, or VS Code
- Valid database credentials (host, port, user, password, database name) for your target database
- Network access from the MCP server host to your database server
Install database-mcp via uvx or pip
Install the Legion MCP server package. uvx is the recommended approach as it handles environment isolation automatically.
# Recommended:
uvx database-mcp
# Alternative:
pip install database-mcpSet environment variables for your database
Configure DB_TYPE and DB_CONFIG environment variables with your database type code and connection details. For a single database, use these two variables.
export DB_TYPE="pg"
export DB_CONFIG='{"host":"localhost","port":5432,"user":"myuser","password":"mypassword","dbname":"mydb"}'Configure multiple databases (optional)
To connect to multiple databases, use the DB_CONFIGS environment variable with a JSON array. Each entry needs an id, db_type, configuration object, and description.
export DB_CONFIGS='[
{"id":"prod","db_type":"pg","configuration":{"host":"prod-db","port":5432,"user":"user","password":"pass","dbname":"production"},"description":"Production PostgreSQL"},
{"id":"analytics","db_type":"bigquery","configuration":{"project":"my-project"},"description":"BigQuery analytics"}
]'Add to your MCP client configuration
Register the Legion MCP server in your client configuration, passing the database environment variables in the env block.
{
"mcpServers": {
"legion": {
"command": "uvx",
"args": ["database-mcp"],
"env": {
"DB_TYPE": "pg",
"DB_CONFIG": "{\"host\":\"localhost\",\"port\":5432,\"user\":\"myuser\",\"password\":\"mypassword\",\"dbname\":\"mydb\"}"
}
}
}
}Restart your MCP client and verify
Restart Claude Desktop or your client. Ask Claude to list available databases or describe a table to confirm the connection is working.
Legion Examples
Client configuration
Full Claude Desktop configuration for connecting Legion MCP to a local PostgreSQL database.
{
"mcpServers": {
"legion": {
"command": "uvx",
"args": ["database-mcp"],
"env": {
"DB_TYPE": "pg",
"DB_CONFIG": "{\"host\":\"localhost\",\"port\":5432,\"user\":\"myuser\",\"password\":\"mypassword\",\"dbname\":\"mydb\"}"
}
}
}
}Prompts to try
Use natural language to query databases, explore schemas, and analyze data.
- "List all tables in the database and describe their columns"
- "Find the top 10 customers by total order value in the last 90 days"
- "Explain the query plan for this slow query and suggest optimizations"
- "Show me a sample of 5 rows from the orders table"
- "Which tables have a foreign key relationship with the users table?"Troubleshooting Legion
Connection refused or database not reachable
Verify the host, port, and credentials in DB_CONFIG are correct. Ensure the database server is accepting connections from the host where the MCP server runs, and check firewall rules if connecting to a remote server.
DB_TYPE value not recognized
Use the correct type codes: 'pg' for PostgreSQL, 'mysql' for MySQL, 'mssql' for SQL Server, 'bigquery' for BigQuery, 'oracle' for Oracle, 'sqlite' for SQLite. Check the database-mcp documentation for the full list.
Multi-database queries fail to specify the right database
When using DB_CONFIGS with multiple databases, always call list_databases first to get the database IDs, then include the db_id parameter when calling execute_query or other tools.
Frequently Asked Questions about Legion
What is Legion?
Legion is a Model Context Protocol (MCP) server that server that helps people access and query data in databases using the legion query runner with model context protocol (mcp) in python. It connects AI assistants to external tools and data sources through a standardized interface.
How do I install Legion?
Follow the installation instructions on the Legion GitHub repository. Clone the repo, install dependencies, and add the server config to your AI client.
Which AI clients work with Legion?
Legion works with all major MCP-compatible AI clients including Claude Desktop, Claude Code, Cursor, VS Code (GitHub Copilot), Windsurf, and Cline.
Is Legion free to use?
Yes, Legion is open source and available under the GPL-3.0 license. You can use it freely in both personal and commercial projects.
Legion Alternatives — Similar Databases Servers
Looking for alternatives to Legion? Here are other popular databases servers you can use with Claude, Cursor, and VS Code.
Excelize
★ 20.6kGo language library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets
MCP Toolbox for Databases
★ 15.3kOpen source MCP server specializing in easy, fast, and secure tools for Databases.
DBHub
★ 2.8kA universal database gateway MCP server that enables AI assistants to connect to and query multiple databases (PostgreSQL, MySQL, MariaDB, SQL Server, SQLite) with support for schema exploration, SQL execution, and secure connections via SSH tunnels.
Tabularis
★ 2.1kA lightweight, cross-platform database client for developers. Supports MySQL, PostgreSQL and SQLite. Hackable with plugins. Built for speed, security, and aesthetics.
Postgres AI Guide
★ 1.7kMCP server and Claude plugin for Postgres skills and documentation. Helps AI coding tools generate better PostgreSQL code.
Anyquery
★ 1.7k🏎️ 🏠 ☁️ - Query more than 40 apps with one binary using SQL. It can also connect to your PostgreSQL, MySQL, or SQLite compatible database. Local-first and private by design.
Browse More Databases MCP Servers
Explore all databases servers available in the MCPgee directory. Each server includes setup guides for Claude, Cursor, and VS Code.
Set Up Legion in Your Editor
Choose your AI client for step-by-step setup instructions.
Quick Config Preview
Add this to your claude_desktop_config.json or .cursor/mcp.json
Ready to use Legion?
Browse our complete directory of 33,000+ MCP servers, read setup guides for your editor, and start building with the Model Context Protocol.