theralabs_legion_mcp

theralabs_legion_mcp

by TheRaLabs
A server enabling database access and querying via the Legion Query Runner and Model Context Protocol (MCP).

Legion Database MCP Server

Overview

The Legion Database MCP Server is a powerful tool designed to facilitate access and querying of databases using the Legion Query Runner. It integrates with the Model Context Protocol (MCP) Python SDK, enabling AI assistants to interact with databases seamlessly. This server exposes database operations as MCP resources, tools, and prompts, providing a flexible and efficient way to manage database interactions.

Features

  • Database Access via Legion Query Runner: Execute queries and manage database operations efficiently.
  • Model Context Protocol (MCP) Support: Integrate AI assistants with database operations.
  • Multiple Deployment Options: Deploy as a standalone MCP server or integrate with FastAPI.
  • Query Execution and Result Handling: Execute queries and handle results with ease.
  • Flexible Configuration: Configure via environment variables, command-line arguments, or MCP settings JSON.

Supported Databases

  • PostgreSQL
  • Redshift
  • CockroachDB
  • MySQL
  • RDS MySQL
  • Microsoft SQL Server
  • Big Query
  • Oracle DB
  • SQLite

What is MCP?

The Model Context Protocol (MCP) is a specification for maintaining context in AI applications. The Legion Database MCP 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.

Installation

Using UV (Recommended)

When using uv, no specific installation is needed. Use uvx to directly run database-mcp.

Using PIP

Alternatively, install database-mcp via pip:

pip install database-mcp

UV Configuration

{
    "mcpServers": {
      "database-mcp": {
        "command": "uvx",
        "args": [\
          "database-mcp"\
        ],
        "env": {
          "DB_TYPE": "pg",
          "DB_CONFIG": "{\"host\":\"localhost\",\"port\":5432,\"user\":\"user\",\"password\":\"pw\",\"dbname\":\"dbname\"}"
        },
        "disabled": true,
        "autoApprove": []
      }
    }
}

Pip Configuration

{
"mcpServers": {
  "database": {
    "command": "python",
    "args": [\
      "-m", "database_mcp", \
      "--repository", "path/to/git/repo"\
    ],
    "env": {
        "DB_TYPE": "pg",
        "DB_CONFIG": "{\"host\":\"localhost\",\"port\":5432,\"user\":\"user\",\"password\":\"pw\",\"dbname\":\"dbname\"}"
    },
  }
}

Development

To run the server in development mode:

mcp dev mcp_server.py

For production mode:

python mcp_server.py

Testing

Run tests with:

uv pip install -e ".[dev]"
pytest

Publish

rm -rf dist/ build/ *.egg-info/ && python -m build
python -m build
python -m twine upload dist/*

MCP Configuration

Environment Variables

Configure the database connection using environment variables:

export DB_TYPE="pg"  # or mysql, postgresql, etc.
export DB_CONFIG='{"host":"localhost","port":5432,"user":"username","password":"password","dbname":"database_name"}'
mcp dev mcp_server.py

Command Line Arguments

For direct execution, use command line arguments:

python mcp_server.py --db-type pg --db-config '{"host":"localhost","port":5432,"user":"username","password":"password","dbname":"database_name"}'

or

uv mcp_server.py --db-type pg --db-config '{"host":"localhost","port":5432,"user":"username","password":"password","dbname":"database_name"}'

Exposed MCP Capabilities

Resources

  • schema://all - Get the complete database schema

Tools

  • execute_query - Execute a SQL query and return results as a markdown table
  • execute_query_json - Execute a SQL query and return results as JSON
  • get_table_columns - Get column names for a specific table
  • get_table_types - Get column types for a specific table
  • get_query_history - Get the recent query history

Prompts

  • sql_query - Create an SQL query against the database
  • explain_query - Explain what a SQL query does
  • optimize_query - Optimize a SQL query for better performance

Development

Run tests:

pytest

License

This repository is licensed under GPL.

About

No description, website, or topics provided.

Resources

Readme

License

GPL-3.0 license

Activity

Stars

4 stars

Watchers

1 watching

Forks

0 forks

Report repository

Releases 1


0.1.3 Latest\
\
Mar 28, 2025

Packages 0


No packages published

Languages

Features & Capabilities

Categories
mcp_server model_context_protocol python database ai_assistant fastapi sql query_execution

Implementation Details

Stats

0 Views
4 GitHub Stars

Repository Info

TheRaLabs Organization

Similar MCP Servers

continuedev_continue by continuedev
25049
21423
9300