home / mcp / database mcp server
A server that helps people access and query data in databases using the Legion Query Runner with Model Context Protocol (MCP) in Python.
Configuration
View docs{
"mcpServers": {
"theralabs-legion-mcp": {
"command": "uvx",
"args": [
"database-mcp"
],
"env": {
"DB_TYPE": "pg",
"DB_CONFIG": "{\"host\":\"localhost\",\"port\":5432,\"user\":\"user\",\"password\":\"pw\",\"dbname\":\"dbname\"}",
"DB_CONFIGS": "[{\"id\":\"pg_main\",\"db_type\":\"pg\",\"configuration\":{...},\"description\":\"PostgreSQL Database\"}]"
}
}
}
}You can access and query multiple databases through a single MCP server that exposes database operations to AI assistants. This server uses the Model Context Protocol (MCP) SDK to present schemas, data, and query capabilities as MCP resources, tools, and prompts you can invoke from your AI workflow. It supports connecting to several database engines, handles credentials securely, and works with common AI development environments with minimal setup.
You use an MCP client to connect to the MCP server and perform operations like listing available databases, inspecting schemas, finding specific tables, and running SQL queries. For multi-database setups, you select the target database for each action using dedicated commands in your MCP client, and the server handles routing the request to the correct database.
Prerequisites: you need Python, and you may also use a Python MCP client or an MCP-compatible interface. You can run the server locally or through a package manager as shown.
- The server supports multiple databases at once. You specify a database identity for each operation so you target the right data source.
Credential management is handled securely, with credentials separated from application code. When deploying, choose the environment and tooling you already use (for example, MCP-enabled FastAPI projects or other AI toolchains) and configure the database connections through environment variables or an MCP settings JSON.
You access database schemas, run queries, and retrieve results through MCP resources and tools such as listing databases, getting table schemas, describing tables, and executing SQL queries. These tools are designed to work uniformly across all connected databases.
If you encounter connection issues, verify your DB_TYPE and connection configuration, ensure your network allows access to the database endpoints, and check that the MCP server has the correct environment variables set for each database.
Execute a SQL query and return results as a markdown table
Execute a SQL query and return results as JSON
Get column names for a specific table
Get column types for a specific table
Get the recent query history
List all available database connections
Get detailed information about a database including schema
Find which database contains a specific table
Get detailed description of a table including column names and types
Get a sample of data from a table