Labsco
TheRaLabs logo

Database

β˜… 94

from TheRaLabs

Universal database MCP server supporting multiple database types including PostgreSQL, Redshift, CockroachDB, MySQL, RDS MySQL, Microsoft SQL Server, BigQuery, Oracle DB, and SQLite

πŸ”₯πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedFreeQuick setup

Multi-Database MCP Server (by Legion AI)

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

Start Generation Here

This tool is provided by Legion AI. To use the full-fledged and fully powered AI data analytics tool, please visit the site. Email us if there is one database you want us to support.

End Generation Here

Why Choose Database MCP

Database MCP stands out from other database access solutions for several compelling reasons:

  • Unified Multi-Database Interface: Connect to PostgreSQL, MySQL, SQL Server, and other databases through a single consistent API - no need to learn different client libraries for each database type.
  • AI-Ready Integration: Built specifically for AI assistant interactions through the Model Context Protocol (MCP), enabling natural language database operations.
  • Zero-Configuration Schema Discovery: Automatically discovers and exposes database schemas without manual configuration or mapping.
  • Database-Agnostic Tools: Find tables, explore schemas, and execute queries with the same set of tools regardless of the underlying database technology.
  • Secure Credential Management: Handles database authentication details securely, separating credentials from application code.
  • Simple Deployment: Works with modern AI development environments like LangChain, FastAPI, and others with minimal setup.
  • Extensible Design: Easily add custom tools and prompts to enhance functionality for specific use cases.

Whether you're building AI agents that need database access or simply want a unified interface to multiple databases, Database MCP provides a streamlined solution that dramatically reduces development time and complexity.

Features

  • Multi-database support - connect to multiple databases simultaneously
  • Database access via Legion Query Runner
  • Model Context Protocol (MCP) support for AI assistants
  • Expose database operations as MCP resources, tools, and prompts
  • Multiple deployment options (standalone MCP server, FastAPI integration)
  • Query execution and result handling
  • Flexible configuration via environment variables, command-line arguments, or MCP settings JSON
  • User-driven database selection for multi-database setups

Supported Databases

DatabaseDB_TYPE code
PostgreSQLpg
Redshiftredshift
CockroachDBcockroach
MySQLmysql
RDS MySQLrds_mysql
Microsoft SQL Servermssql
Big Querybigquery
Oracle DBoracle
SQLitesqlite

We use Legion Query Runner library as connectors. You can find more info on their api doc.

What is MCP?

The Model Context Protocol (MCP) is a specification for maintaining context in AI applications. This server uses the MCP Python SDK to:

  • Expose database operations as tools for AI assistants
  • Provide database schemas and metadata as resources
  • Generate useful prompts for database operations
  • Enable stateful interactions with databases

Multi-Database Support

When connecting to multiple databases, you need to specify which database to use for each query:

  1. Use the list_databases tool to see available databases with their IDs
  2. Use get_database_info to view schema details of databases
  3. Use find_table to locate a table across all databases
  4. Provide the db_id parameter to tools like 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 its name and column information.

The select_database prompt guides users through the database selection process.

Schema Representation

Database schemas are represented as a list of table objects, with each table containing information about its columns:

Copy & paste β€” that's it
[
  {
    "name": "users",
    "columns": [
      {"name": "id", "type": "integer"},
      {"name": "username", "type": "varchar"},
      {"name": "email", "type": "varchar"}
    ]
  },
  {
    "name": "orders",
    "columns": [
      {"name": "id", "type": "integer"},
      {"name": "user_id", "type": "integer"},
      {"name": "product_id", "type": "integer"},
      {"name": "quantity", "type": "integer"}
    ]
  }
]

This representation makes it easy to programmatically access table and column information while keeping a clean hierarchical structure.

Exposed MCP Capabilities

Resources

ResourceDescription
resource://schema/{database_id}Get the schemas for one or all configured databases

Tools

ToolDescription
execute_queryExecute a SQL query and return results as a markdown table
execute_query_jsonExecute a SQL query and return results as JSON
get_table_columnsGet column names for a specific table
get_table_typesGet column types for a specific table
get_query_historyGet the recent query history
list_databasesList all available database connections
get_database_infoGet detailed information about a database including schema
find_tableFind which database contains a specific table
describe_tableGet detailed description of a table including column names and types
get_table_sampleGet a sample of data from a table

All database-specific tools (like execute_query, get_table_columns, etc.) require a db_id parameter to specify which database to use.

Prompts

PromptDescription
sql_queryCreate an SQL query against the database
explain_queryExplain what a SQL query does
optimize_queryOptimize a SQL query for better performance
select_databaseHelp user select which database to use

Development

Using MCP Inspector

run this to start the inspector

Copy & paste β€” that's it
npx @modelcontextprotocol/inspector uv run src/database_mcp/mcp_server.py

then in the command input field, set something like

Copy & paste β€” that's it
run src/database_mcp/mcp_server.py --db-type pg --db-config '{"host":"localhost","port":5432,"user":"username","password":"password","dbname":"database_name"}'

Testing

Copy & paste β€” that's it
uv pip install -e ".[dev]"
pytest

Publishing

Copy & paste β€” that's it
# Clean up build artifacts
rm -rf dist/ build/ 
# Remove any .egg-info directories if they exist
find . -name "*.egg-info" -type d -exec rm -rf {} + 2>/dev/null || true
# Build the package
uv run python -m build
# Upload to PyPI
uv run python -m twine upload dist/*

License

This repository is licensed under GPL