Legion MCP is a multi-database MCP server provided by Legion AI, designed to help users access and query data in databases in a Python environment through Legion Query Runner combined with the Model Context Protocol (MCP).
Purpose
The server is mainly used to provide AI assistants with database access capabilities, enabling AI to perform database operations through natural language. It can also serve as a unified interface, allowing developers to connect to and manage multiple types of databases at the same time, reducing the cost of learning a different client library for each database.
Main Capabilities
- Multi-database support: Can connect to multiple databases at the same time. Supported database types include PostgreSQL, Redshift, CockroachDB, MySQL, RDS MySQL, SQL Server, BigQuery, Oracle, and SQLite.
- Unified interface: Connect to different databases through a single consistent API, without needing to use a different client library for each database.
- AI-ready integration: Built specifically for interacting with AI assistants through MCP, supporting natural language database operations.
- Zero-configuration schema discovery: Automatically discovers and exposes database schemas, without manual configuration or mapping.
- Database-agnostic tools: Regardless of the underlying database technology, the same set of tools can be used to find tables, browse schemas, and execute queries.
- Secure credential management: Securely handles database authentication information, separating credentials from application code.
- Simple deployment: Can be used with modern AI development environments such as LangChain and FastAPI, with minimal setup.
- Extensible design: Custom tools and prompts can be easily added to enhance functionality for specific use cases.
- Expose database operations through MCP: Expose database operations as MCP resources, tools, and prompts.
- Multiple deployment options: Supports standalone MCP server and FastAPI integration.
- Flexible configuration: Supports configuration through environment variables, command-line arguments, or MCP settings JSON.
- User-driven database selection: In multi-database setups, users can specify which database to use.
Usage
Installation and Configuration
When using uv, no specific installation is required; database-mcp can be run directly through uvx. It can also be installed through pip.
Single-database configuration requires the following parameters:
- DB_TYPE: datDatabase type code
- DB_CONFIG: JSON configuration string for database connection
Multiple database configuration requires DB_CONFIGS: a JSON array, where each element contains db_type (database type code), configuration (database connection configuration), and description (a human-readable description of the database).
The configuration format varies by database type; refer to the API documentation for details.
Running the server
Supports running in production mode.
Multiple database support
When connecting to multiple databases, you need to specify which database to use for each query:
- Use the list_databases tool to view available databases and their IDs
- Use get_database_info to view schema details of a database
- Use find_table to locate tables across all databases
- Provide the db_id parameter for tools such as 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 a name and column information. The select_database prompt can guide users through the database selection process.
Schema representation
The database schema is represented as a list of table objects, where each table contains information about its columns. This representation makes it easy to access table and column information programmatically while maintaining a clear hierarchy.
Exposed MCP capabilities
All database-specific tools (such as execute_query, get_table_columns, etc.) require the db_id parameter to specify which database to use.
Using MCP Inspector
You can run a command to start the inspector, then set the corresponding content in the command input field.
Applicable scenarios
- Building AI agents that need database access capabilities.
- Developers who need a unified interface to access multiple databases.
- Integrating database operations in AI development environments such as LangChain and FastAPI.
- Performing database queries and exploration through natural language.
Limitations
- This tool is provided by Legion AI; the full-featured AI data analysis tool requires visiting its website.
- If support for a specific database is needed, you can contact by email.
- This repository uses the GPL license.
- The specific configuration format varies by datadatabase type, so refer to the API documentation.
- More details regarding fees, pricing, platform compatibility, etc. are not currently provided in the materials.