legion-mcp

by TheRaLabs
Verified

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

Integrations

  • Supports integration with FastAPI for running the MCP server, providing both standalone and integrated deployment options

  • Provides database access capabilities for MySQL, supporting query execution and schema exploration

  • Enables querying and interacting with PostgreSQL databases through SQL execution tools and schema resources

数据库 MCP 服务器(由 Legion AI 提供)

该服务器使用集成了模型上下文协议 (MCP) Python SDK 的 Legion Query Runner 帮助人们访问和查询数据库中的数据。

特征

  • 通过 Legion Query Runner 访问数据库
  • 人工智能助手的模型上下文协议 (MCP) 支持
  • 将数据库操作公开为 MCP 资源、工具和提示
  • 多种部署选项(独立 MCP 服务器、FastAPI 集成)
  • 查询执行和结果处理
  • 通过环境变量、命令行参数或 MCP 设置 JSON 进行灵活配置

支持的数据库

数据库DB_TYPE代码
PostgreSQL前列腺素
红移红移
蟑螂数据库蟑螂
MySQLmysql
RDS MySQLrds_mysql
微软 SQL 服务器mssql
大查询大查询
Oracle 数据库神谕
SQLiteSQLite

我们使用 Legion Query Runner 库作为连接器。您可以在其API 文档中找到更多信息。

什么是 MCP?

模型上下文协议 (MCP) 是用于维护 AI 应用程序中上下文的规范。此服务器使用MCP Python SDK来执行以下操作:

  • 将数据库操作公开为人工智能助手的工具
  • 提供数据库模式和元数据作为资源
  • 生成有用的数据库操作提示
  • 启用与数据库的状态交互

安装和配置

必需参数

所有安装方法都需要两个参数:

  • DB_TYPE :数据库类型代码(见上表)
  • DB_CONFIG :数据库连接的 JSON 配置字符串

DB_CONFIG 的格式因数据库类型而异。有关特定数据库的配置详细信息,请参阅API 文档

安装方法

选项 1:使用 UV(推荐)

使用uv时无需特殊安装。我们将使用uvx直接运行database-mcp

UV配置示例:

REPLACE DB_TYPE and DB_CONFIG with your connection info. { "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": [] } } }

选项 2:使用 PIP

通过 pip 安装:

pip install database-mcp

PIP配置示例:

{ "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\"}" } } } }

运行服务器

开发模式

mcp dev mcp_server.py

生产模式

python mcp_server.py

配置方法

环境变量

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

命令行参数

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

或者使用紫外线:

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

公开的 MCP 功能

资源

资源描述
schema://all获取完整的数据库架构

工具

工具描述
execute_query执行 SQL 查询并以 markdown 表形式返回结果
execute_query_json执行 SQL 查询并以 JSON 格式返回结果
get_table_columns获取特定表的列名
get_table_types获取特定表的列类型
get_query_history获取最近的查询历史记录

提示

迅速的描述
sql_query针对数据库创建 SQL 查询
explain_query解释 SQL 查询的作用
optimize_query优化 SQL 查询以获得更好的性能

发展

测试

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

出版

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

执照

此存储库采用 GPL 许可

-
security - not tested
F
license - not found
-
quality - not tested

一个服务器,帮助用户使用集成了模型上下文协议 (MCP) Python SDK 的查询运行器访问和查询数据库中的数据。支持的数据库包括:PostgreSQL、Redshift、MySQL、Microsoft SQL Server、Google API、Amazon Web Services(通过 boto3)、CockroachDB、SQLite

  1. Features
    1. Supported Databases
      1. What is MCP?
        1. Installation & Configuration
          1. Required Parameters
          2. Installation Methods
        2. Running the Server
          1. Development Mode
          2. Production Mode
          3. Configuration Methods
        3. Exposed MCP Capabilities
          1. Resources
          2. Tools
          3. Prompts
        4. Development
          1. Testing
          2. Publishing
        5. License
          ID: eznxyvc6od