# legion-mcp

> legion-mcp is an open-source MCP server for databases. MCP server giving AI assistants read access to PostgreSQL, MySQL, SQL Server and other. It is available on CLI, API and Self-hosted.

- **Kind:** MCP server
- **Pricing:** Open source
- **Platforms:** CLI, API, Self-hosted
- **Website:** https://thelegionai.com
- **Repository:** https://github.com/theralabs/legion-mcp
- **GitHub stars:** 95
- **License:** GPL-3.0
- **Categories:** [databases](https://ai-powered.com/categories/databases)
- **Listing updated:** 2026-12-01

## About

Database MCP is a Python server that lets an AI assistant connect to one or several databases and work with them through a common set of tools. Each connection is defined by a database type code and a JSON configuration, so the same tools for listing tables, describing columns and running queries work across PostgreSQL, MySQL, SQL Server, Oracle, BigQuery, SQLite and others.

The server publishes schemas as MCP resources and exposes query execution in both markdown and JSON output. When several databases are configured, the assistant first lists the available connections, then searches for the table it needs and passes a database ID with each request. Connections are built on the Legion Query Runner library.

It suits developers and data teams who want an AI client to explore schemas and draft or explain SQL against live data without writing a custom integration for each database engine. The README notes that the full Legion analytics product is a separate offering.

## Features

- **Multi-database connections:** Connect several database instances at once and select the target for each query by ID.
- **Automatic schema discovery:** Table and column metadata is exposed as MCP resources without manual mapping.
- **Unified query tools:** The same tools for finding tables, describing columns and running queries work across supported engines.
- **Query and sample tools:** Run SQL returning markdown or JSON, review query history and pull sample rows from a table.
- **Flexible configuration:** Set connections through environment variables, command-line arguments or an MCP settings file.
- **Built-in SQL prompts:** Prompts for writing, explaining and optimizing queries, plus a guided database selection prompt.

## Good for

- Letting an AI assistant explore an unfamiliar database schema before writing queries
- Asking natural-language questions against a PostgreSQL or MySQL database from a desktop AI client
- Comparing or locating tables across several databases from one assistant session
- Getting SQL explanations and optimization suggestions for existing queries

## Tools

From the tool list in its README, going by the names, 2 of 10 tools change data. From the server's own tool labels and tool names; not verified by us.

- `execute_query` (name suggests: changes): Execute a SQL query and return results as a markdown table
- `execute_query_json` (name suggests: changes): Execute a SQL query and return results as JSON
- `get_table_columns` (name suggests: reads): Get column names for a specific table
- `get_table_types` (name suggests: reads): Get column types for a specific table
- `get_query_history` (name suggests: reads): Get the recent query history
- `list_databases` (name suggests: reads): List all available database connections
- `get_database_info` (name suggests: reads): Get detailed information about a database including schema
- `find_table` (name suggests: reads): Find which database contains a specific table
- `describe_table` (name suggests: reads): Get detailed description of a table including column names and types
- `get_table_sample` (name suggests: reads): Get a sample of data from a table

## FAQ

### Which databases are supported?

The README lists PostgreSQL, Redshift, CockroachDB, MySQL, RDS MySQL, Microsoft SQL Server, BigQuery, Oracle DB and SQLite.

### How is the server installed?

It can be run with uvx using the database-mcp package, or installed with pip and started as a Python module.

### Can legion-mcp connect to more than one database?

Yes. Multiple connections can be defined in a JSON array, and each tool call specifies which database to use.

### Is legion-mcp free?

Yes. legion-mcp is open source, so you can use and self-host it for free.

### What are the best alternatives to legion-mcp?

The closest alternatives to legion-mcp are sql-query-mcp, mcp-multi-db, mysql_mcp_server, db-mcp-server and postgres_mcp.

## Where this comes from

- Description: written from the project's README and the project's website.

## Alternatives

- [sql-query-mcp](https://ai-powered.com/mcp/sql-query-mcp): sql-query-mcp is an open-source MCP server for databases.
- [mcp-multi-db](https://ai-powered.com/mcp/mcp-multi-db): mcp-multi-db is an open-source MCP server for databases.
- [mysql_mcp_server](https://ai-powered.com/mcp/mysql-mcp-server-4): mysql_mcp_server is an open-source MCP server for databases.
- [db-mcp-server](https://ai-powered.com/mcp/db-mcp-server-2): db-mcp-server is an open-source MCP server for databases.
- [postgres_mcp](https://ai-powered.com/mcp/postgres-mcp-5): postgres_mcp is an open-source MCP server for databases.
- [thinair-data](https://ai-powered.com/mcp/thinair-data): thinair-data is an MCP server for databases.
- [Db Access MCP](https://ai-powered.com/mcp/db-access-mcp): Db Access MCP is an open-source MCP server for databases.
- [Database MCP](https://ai-powered.com/mcp/database-mcp): Database MCP is an open-source MCP server for databases.

---
Source: https://ai-powered.com/mcp/legion-mcp
