Legion

v1.0.0Databasesstable

A server that helps people access and query data in databases using the Legion Query Runner with Model Context Protocol (MCP) in Python.

databaselegion-aimcpmcp-serverquery-builder
Share:
91
Stars
0
Downloads
0
Weekly
0/5

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

Database query execution with AI
Multi-database support and query building
TheRaLabs

Maintainer

LicenseGPL-3.0
Languagepython
Versionv1.0.0
UpdatedMay 6, 2026
Statushealthy
Maintenanceactive

Works with

ClaudeOpenAIwindowsmacoslinux

Installation

Manual Installation

npx legion

Configuration

Configuration Details

Config File

claude_desktop_config.json

Performance

Response Metrics

Response Time< 200ms
ThroughputMedium

Resource Usage

Memory UsageLow
CPU UsageLow

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
1

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-mcp
2

Set 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"}'
3

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"}
]'
4

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\"}"
      }
    }
  }
}
5

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.

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.

Quick Config Preview

{ "mcpServers": { "legion": { "command": "npx", "args": ["-y", "legion"] } } }

Add this to your claude_desktop_config.json or .cursor/mcp.json

Read the full setup guide →

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.

33,000+ ServersFree & Open SourceStep-by-Step Guides