SP Database MCP Server
一个用于实时获取数据库表结构信息的 Model Context Protocol (MCP) 服务器。通过 MCP 协议,可以让 AI 助手实时获取数据库的表结构信息,解决信息不及时更新的问题。
功能特性
- 智能表结构查询:支持两种查询模式
- 低代码系统 Schema 查询:通过
da_logic_entity和da_entity_attribute表获取详细的业务字段信息 - 传统数据库元数据查询:直接从数据库系统表获取技术字段信息
- 低代码系统 Schema 查询:通过
- 🔄 实时获取数据库表结构信息
- 📊 支持多种数据库类型 (MySQL, PostgreSQL)
- 🚀 通过 API 接口动态获取最新的表字段信息
- 🔍 支持表信息查询和字段详情获取
- 📝 自动生成表结构文档
安装
cd ~/Project/sp-database-mcp
uv sync
配置
创建 .env 文件:
# 数据库连接配置
DATABASE_URL=mysql://username:password@localhost:3306/database_name
# 或者 PostgreSQL
# DATABASE_URL=postgresql://username:password@localhost:5432/database_name
# API 接口配置(如果通过 API 获取)
API_BASE_URL=https://your-api-server.com
API_TOKEN=your-api-token
使用方式
启动 MCP 服务器
uv run sp-database-mcp
在 Claude Desktop 中配置
在 Claude Desktop 的配置文件中添加:
{
"mcpServers": {
"sp-database": {
"command": "uv",
"args": ["run", "sp-database-mcp"],
"cwd": "/Users/alexliu/Project/sp-database-mcp"
}
}
}
使用示例
- "介绍一下活动表有哪些字段"
- "获取 activity_node 表的结构信息"
- "查看用户表的字段定义"
使用示例
查询表结构信息
现在支持两种查询模式,系统会自动优先使用低代码系统的 schema 查询:
# 通过 MCP 工具查询表信息
# 输入:请获取 activity_node 表的详细信息
# 输出示例(低代码系统 schema 查询结果):
# activity_node 表结构信息
#
# **表说明**: 活动
#
# ## 字段信息
#
# | 字段名 | 类型 | 可空 | 默认值 | 主键 | 说明 |
# |--------|------|------|--------|------|---------|
# | id | BIGINT | 否 | - | 是 | 主键ID |
# | name | VARCHAR(1000) | 是 | - | 否 | 活动名称 |
# | activity_code | VARCHAR(64) | 是 | - | 否 | 活动编码 |
# | business_object_id | BIGINT | 是 | - | 否 | 业务对象id |
# | ... | ... | ... | ... | ... | ... |
查询模式说明
-
低代码系统 Schema 查询(优先)
- 查询
da_logic_entity表获取实体基本信息 - 查询
da_entity_attribute表获取字段详细信息 - 提供中文字段名、业务描述、数据类型等丰富信息
- 支持外键关系解析
- 查询
-
传统数据库元数据查询(回退)
- 当低代码系统查询失败时自动回退
- 直接从数据库系统表获取技术字段信息
- 提供基础的字段类型、约束等信息
项目结构
sp-database-mcp/
├── src/
│ └── sp_database_mcp/
│ ├── __init__.py
│ ├── server.py # MCP 服务器主文件
│ ├── database.py # 数据库连接和查询
│ ├── api_client.py # API 客户端
│ └── models.py # 数据模型
├── tests/
├── .env.example
├── pyproject.toml
└── README.md
开发
# 安装开发依赖
uv sync --dev
# 运行测试
uv run pytest
# 代码格式化
uv run black .
uv run isort .
# 类型检查
uv run mypy .
Metadata
Release files for sp-database-mcp 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| sp_database_mcp-0.1.2.tar.gz | 12.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sp_database_mcp-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 29.3 kB
Release files / sp_database_mcp-0.1.2.tar.gz
| Download URL | sp_database_mcp-0.1.2.tar.gz |
|---|---|
| Size | 12.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5569be3903cdca52a2c56cbdccc138379748692a5b5b8e921f3d2d601045273e
|
|
BLAKE2b-256 checksum How to use checksums |
1a5c714c459f846bec2769871f5b9a07b4fc46cf36836e317ff755fa2e03d252
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Release files / sp_database_mcp-0.1.2-py3-none-any.whl
| Download URL | sp_database_mcp-0.1.2-py3-none-any.whl |
|---|---|
| Size | 17.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
58abc4cf901e27dbeff5dbad4273435eef749f7e5f77ed8c7f69338c81c63689
|
|
BLAKE2b-256 checksum How to use checksums |
15c473fb6f542895a728d2bb52c209b93a5f49f5e341a06e95c9724b1b69597c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Security for sp-database-mcp 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.