mcpField
D
Database Schema MCP Server

Database Schema MCP Server

本地服务
github.com/Adhikram数据库083 周前更新

关于 Database Schema MCP Server

Database Schema MCP Server 面向需要检查数据库结构的开发者和 AI 客户端,支持 PostgreSQL、MySQL 和 SQLite。它既可查看单表详情,也可获取包含视图和索引的完整结构。

主要功能

  1. 01连接 PostgreSQL、MySQL 和 SQLite
  2. 02列出数据库中的表
  3. 03查看单个表的结构
  4. 04获取包含表、视图和索引的结构

适用场景

  1. 01查看数据库中有哪些表
  2. 02查询前检查表结构
  3. 03审查数据库的完整结构

MCP 相关

它向 MCP 客户端提供连接数据库、列出表和读取结构信息的 MCP 工具。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

暂未收录安装方式

我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。

代码仓库

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

详细介绍

数据库架构 MCP 服务

功能强大的 MCP 服务,可读取并公开多种数据库类型(PostgreSQL、MySQL、SQLite 等)的数据库架构。

🌟 功能

  • 连接不同类型的数据库
  • 列出数据库中的所有表
  • 获取指定表的详细架构信息
  • 获取包含表、视图和索引的完整数据库架构
  • 支持多种数据库类型(PostgreSQL、MySQL、SQLite)

🚀 安装

前置条件
  1. Python 3.x
  2. 虚拟环境(推荐)
基本安装
  1. 创建并激活虚拟环境:
# Create virtual environment
python -m venv venv

# Activate virtual environment
# On Unix/macOS:
source venv/bin/activate
# On Windows:
venv\Scripts\activate
  1. 安装依赖项:
pip install -r requirements.txt
Windows MCP 安装
  1. 安装 Node.js:

    • 从 Node.js 官方网站 下载并安装
    • 在 PowerShell 中运行 node --version,验证是否安装成功
  2. 更新系统 Path:

$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
  1. 如果无法识别 Node.js,请手动将其添加到 Path:

    • 按下 Windows + R
    • 输入 sysdm.cpl 并按 Enter
    • 转到“高级”选项卡
    • 点击“环境变量”
    • 在“系统变量”下,找到并选择“Path”
    • 点击“编辑”
    • 如果尚未添加,请添加 C:\Program Files\nodejs\
    • 在所有窗口中点击“确定”
    • 重启计算机
  2. 安装 MCP:

    • 下载 mcp-install.ps1 脚本
    • 解除文件锁定(右键点击 → 属性 → 解除锁定)
    • 以管理员身份打开 PowerShell 并运行:
      Set-ExecutionPolicy unrestricted
      
    • 转到脚本所在位置并运行:
      .\mcp-install.ps1 @modelcontextprotocol/server-postgres
      
    • 完全退出 Claude Desktop(检查系统托盘)
    • 在 C:\Users\YOUR_USERNAME\AppData\Roaming\Claude\claude_desktop_config.json 中配置服务
    • 将 MCP 服务配置复制到 Cursor 中的 mcp.json
    • 重启 Cursor
MCP 配置示例

在项目根目录中创建 .cursor/mcp.json 文件,结构如下:

{
    "mcpServers": {
        "local-db": {
            "args": [
                "C:\\Users\\YOUR_USERNAME\\AppData\\Roaming\\npm\\node_modules\\@modelcontextprotocol\\server-postgres\\dist\\index.js",
                "database-url"
            ],
            "command": "node"
        },
        "staging-db": {
            "args": [
                "C:\\Users\\YOUR_USERNAME\\AppData\\Roaming\\npm\\node_modules\\@modelcontextprotocol\\server-postgres\\dist\\index.js",
                "database-url"
            ],
            "command": "node"
        },
        "production-db": {
            "args": [
                "C:\\Users\\YOUR_USERNAME\\AppData\\Roaming\\npm\\node_modules\\@modelcontextprotocol\\server-postgres\\dist\\index.js",
                "database-url"
            ],
            "command": "node"
        }
    }
}

将 YOUR_USERNAME 替换为你的 Windows 用户名,并确保路径与 Node.js 模块的安装位置相符。

💻 使用方法

启动服务
python src/server.py
可用工具
1. 连接数据库
config = {
    "type": "postgresql",  # or "mysql", "sqlite"
    "host": "localhost",
    "port": 5432,
    "database": "mydb",
    "username": "user",
    "password": "password"
}
result = await connect_database(config)
2. 列出表
tables = await list_tables("postgresql://user:password@localhost:5432/mydb")
3. 获取表架构
schema = await get_table_schema("postgresql://user:password@localhost:5432/mydb", "users")
4. 获取数据库架构
schema = await get_database_schema("postgresql://user:password@localhost:5432/mydb")

📚 Claude 使用示例

# Connect to a database
config = {
    "type": "postgresql",
    "host": "localhost",
    "port": 5432,
    "database": "mydb",
    "username": "user",
    "password": "password"
}
await connect_database(config)

# Get the complete schema
schema = await get_database_schema("postgresql://user:password@localhost:5432/mydb")

# Analyze the schema
print(f"Database has {len(schema['tables'])} tables")
for table_name, table_info in schema['tables'].items():
    print(f"\nTable: {table_name}")
    print(f"Columns: {len(table_info['columns'])}")
    print(f"Primary Keys: {table_info['primary_keys']}")
    print(f"Foreign Keys: {len(table_info['foreign_keys'])}")

🔒 安全最佳实践

  1. 切勿在客户端代码中暴露敏感的数据库凭据
  2. 使用环境变量或安全的配置管理方式存储凭据
  3. 实施适当的访问控制和身份验证
  4. 尽可能使用 SSL/TLS 建立数据库连接

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。