Skip to main content
Glama
kobramantra-debug

mcp-database-universal

MCP Database Server

A reasoning interface for databases for MCP-capable AI agents — not a thin SQL wrapper.

mcp-database-universal 为 AI 代理提供了一套 7 个推理工具,用于安全地探索和查询数据库、理解其模式和数据形态、运行自然语言问题以及可视化关系——所有这些都无需暴露原始连接内部细节。

功能特性

  • 7 个推理工具,专为 AI 代理设计:测试连接、列出表、检查表、运行参数化 SQL、用自然语言提问、分析数据以及渲染 ER 图。

  • 多引擎支持:内置 SQLite,以及可选的 PostgreSQL、MySQL 和 MSSQL。

  • 安全优先:默认只读、参数化查询、语句验证、行数/超时/输出限制。

  • 对 LLM 友好的输出:类型转换、NULL 处理、结果以带上下文的 Markdown 表格呈现。

  • 模式自省:自动发现表、列、索引、外键和关系。

  • 自然语言查询:将纯文本问题转换为 SQL 并返回结果。

Related MCP server: Universal Database MCP Server

支持的引擎

引擎

要求

安装额外依赖

SQLite

内置

PostgreSQL

psycopg

pip install "mcp-database-universal[postgres]"

MySQL

PyMySQL

pip install "mcp-database-universal[mysql]"

MSSQL

pyodbc + ODBC 驱动

pip install "mcp-database-universal[mssql]"

全部

pip install "mcp-database-universal[all]"

安装

pip install mcp-database-universal

# With optional engines:
pip install "mcp-database-universal[postgres]"
pip install "mcp-database-universal[mysql]"
pip install "mcp-database-universal[mssql]"
# or everything:
pip install "mcp-database-universal[all]"

快速开始

通过 STDIO(MCP 客户端的默认传输方式)运行服务器:

DATABASE_URL=sqlite:///app.db python -m mcp_database_universal

连接 URL:

sqlite:///path/to/db.db              SQLite (file)
sqlite:///:memory:                   SQLite (in-memory)
postgresql://user:pass@host:5432/db  PostgreSQL
mysql://user:pass@host:3306/db       MySQL
mssql://user:pass@host:1433/db       MSSQL (uses ODBC Driver 18)

Docker

docker build -t mcp-db .

# Mount a SQLite database read-only:
docker run --rm -i \
  -v /host/path/app.db:/data/app.db:ro \
  -e DATABASE_URL=sqlite:////data/app.db \
  mcp-db

# Or in-memory:
docker run --rm -i -e DATABASE_URL=sqlite:///:memory: mcp-db

配置

所有配置均通过环境变量完成。

变量

默认值

描述

DATABASE_URL

(必填)

数据库连接 URL。

DATABASE_READ_ONLY

true

强制只读模式(即使 DATABASE_WRITE_ENABLED 为真也会阻止写入)。

DATABASE_WRITE_ENABLED

false

DATABASE_READ_ONLY=false 时允许写语句。

DATABASE_MAX_ROWS

1000

每次查询返回的最大行数。

DATABASE_MAX_QUERY_TIME

30

查询超时时间(秒)。

DATABASE_MAX_OUTPUT_BYTES

50000

结果负载大小上限。

DATABASE_SAMPLE_SIZE

5

表/列统计中显示的示例行数。

DATABASE_PROFILE_TOP_N

10

分析中 Top-N 值分布条目数。

OPENAI_API_KEY

用于 LLM 支持的 natural_query 模式的 API 密钥。

ANTHROPIC_API_KEY

用于 LLM 支持的 natural_query 模式的 API 密钥。

工具

工具

描述

test_connection

测试数据库连接;报告引擎、版本、名称、大小、表数量。

list_tables

所有表的概览,包含行数、列数、外键关系。

inspect_table

单个表的完整结构:列、类型、索引、外键、示例数据。

query

运行安全、参数化的 SQL 查询并获取 Markdown 结果。

natural_query

用纯文本提问;获取生成的 SQL 和结果。

profile_database

数据剖析:分布、NULL 率、关系、大小。

schema_graph

表关系的 Mermaid ER 图。

示例:带参数的 query

{
  "sql": "SELECT * FROM users WHERE id = :id AND active = :active",
  "params": "{\"id\": 42, \"active\": true}"
}

参数使用 :name 占位符;在 params 中以 JSON 字符串形式传递值。

示例:natural_query

question: "How many users are there?"
-> SELECT COUNT(*) FROM users
question: "Show me all orders"
-> SELECT * FROM orders LIMIT 100

针对小型示例数据库的工作示例位于 examples/ 中,同时包含常见 MCP 客户端的现成配置片段。

MCP 客户端配置

Claude Desktop(claude_desktop_config.json

{
  "mcpServers": {
    "database": {
      "command": "python",
      "args": ["-m", "mcp_database_universal"],
      "env": {"DATABASE_URL": "sqlite:///C:/data/app.db"}
    }
  }
}

Cursor / 其他基于 CLI 的客户端

{
  "mcpServers": {
    "database": {
      "command": "uvx",
      "args": ["mcp-database-universal"],
      "env": {"DATABASE_URL": "sqlite:///C:/data/app.db"}
    }
  }
}

Windows 注意:异步 Postgres 驱动需要 Windows 选择器事件循环。该包在 win32 上自动设置此策略,因此无需额外配置。

开发

pip install -e ".[dev]"
pytest

PostgreSQL/MySQL 的集成测试使用 Docker Compose,如果服务器不可达则自动跳过:

docker compose -f tests/integration/docker-compose.yml up -d
pytest

安全模型

  • 服务器默认只读INSERT/UPDATE/DELETE/DROP/ALTER 等写语句会被阻止。

  • 仅当操作员明确设置 DATABASE_READ_ONLY=false DATABASE_WRITE_ENABLED=true 时才允许写入。

  • 查询结果受行数、超时和输出大小限制——可防止失控查询。

许可证

MIT

A
license - permissive license
Not graded
quality - not tested
A
maintenance

Maintenance

Maintainers
Response time
0dRelease cycle
3Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    Enables AI agents to query and explore databases including SQLite, PostgreSQL, MySQL, and SQL Server through a secure, read-only workflow. It provides tools for listing connections, inspecting table schemas, and executing SELECT statements directly within VS Code.
    1
  • A
    license
    Not graded
    quality
    A
    maintenance
    Connect AI agents to SQL databases (SQLite, PostgreSQL, MySQL) with a unified interface for querying data, exploring schemas, inserting rows, and exporting results to CSV. Includes safety features like dangerous query blocking and write guards.
    13
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables AI assistants to connect to and interact with PostgreSQL, MySQL, SQLite, and MongoDB databases through natural language, supporting schema exploration, query execution, data export, and more.
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    Enables AI agents to interact with PostgreSQL or MySQL databases using natural language. Supports SQL queries, schema discovery, and pre-built aggregations without writing SQL.
    289
    MIT

View all related MCP servers

Related MCP Connectors

  • Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.

  • Explore, query, and inspect SQLite databases with ease. List tables, preview results, and view det…

  • Give your agent live data from Twitter, Reddit, the web and GitHub. No API keys, no scraping stack.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/kobramantra-debug/mcp-database-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server