DatabaseMCP
MCP 数据库智能服务器架构
系统概述
该系统使用 模型上下文协议 (MCP) 向 AI 智能体公开数据库功能。
MCP 服务器充当以下组件之间的桥梁:
AI 助手
数据库元数据
存储过程
数据库探索工具
高层架构
AI 智能体 / MCP 客户端 │ ▼ MCP 服务器 (FastMCP) │ ├── 发现工具 │ (数据库探索) │ ├── 动态过程工具 │ (从数据库过程生成) │ ▼ 智能引擎 (过程元数据 + 分类) │ ▼ 数据库访问层 │ ▼ MySQL 数据库
核心组件
Related MCP server: MySQL MCP Server
1. MCP 服务器 (main.py)
MCP 服务器使用 FastMCP 创建。
职责:
初始化 MCP 服务器
注册发现工具
注册动态过程工具
2. 数据库访问层 (db.py)
该模块管理所有数据库通信。
职责:
数据库连接管理
存储过程执行
元数据检索
强制执行结果限制
所有数据库交互都通过此层进行。
3. 工具生成器 (tool_generator.py)
该模块将数据库存储过程动态转换为 MCP 工具。
执行步骤:
从数据库加载过程元数据
检测过程参数
动态生成 MCP 工具函数
向 MCP 服务器注册工具
这使得系统能够自动支持 添加到数据库的新过程。
4. 智能引擎 (intelligence_engine.py)
智能引擎分析存储过程以生成元数据。
功能包括:
过程分类
描述生成
参数分析
示例类别:
过程模式 | 类别 |
GetLinkCount | 网络分析 |
GetWeekData | 时间分析 |
InterfaceLinkType | 接口分析 |
此元数据有助于 AI 智能体理解每个工具的用途。
5. 发现工具 (discovery_tools.py)
发现工具允许 AI 智能体探索数据库结构。
已实现的工具:
list_databases list_tables describe_table
这些工具依赖于来自以下位置的数据库元数据:
INFORMATION_SCHEMA
安全架构
实施了多项保障措施以确保安全的数据库交互。
关键字限制
包含危险关键字的过程将被阻止。
示例:
DELETE DROP TRUNCATE UPDATE INSERT ALTER
查询结果限制
系统使用可配置的值限制结果大小:
MAX_QUERY_ROWS
这可以防止大规模数据提取。
速率限制
MCP 服务器强制执行请求速率限制,以防止过度使用。
受限数据库用户
MCP 服务器使用的数据库用户应仅具有以下权限:
SELECT EXECUTE
这可以防止修改生产数据。
元数据来源
系统从 MySQL 系统表中检索元数据。
示例:
INFORMATION_SCHEMA.ROUTINES INFORMATION_SCHEMA.PARAMETERS INFORMATION_SCHEMA.TABLES INFORMATION_SCHEMA.COLUMNS
这些表允许 MCP 服务器自动理解数据库结构。
AI 交互流程示例
AI 智能体与数据库之间的交互示例:
list_databases() ↓ list_tables() ↓ describe_table("interface_stats") ↓ GetLinkCount("NodeA")
这允许 AI 在执行分析过程之前探索数据库结构。
可扩展性
该系统旨在支持额外的数据库对象。
未来的扩展可能包括:
list_views list_functions list_triggers search_tables explain_query
模块化架构允许轻松添加新工具。
结论
该架构展示了 MCP 服务器如何安全地向 AI 系统公开数据库功能。
关键设计原则:
• 模块化架构 • 动态工具生成 • 元数据驱动的发现 • 安全的数据库访问
这种方法实现了安全且可扩展的 AI-数据库集成。
详细的系统图表可在 docs/ 目录中找到。
This server cannot be deployed
Maintenance
Related MCP Connectors
- dataOAuthco.thinair
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
MCP server for building and testing AI agents with multi-model experimentation and insights.
- mcpOAuthcom.gibsonai
GibsonAI MCP server: manage your databases with natural language
The Remote MCP server acts as a standardized bridge between LLM applications (like Claude, ChatGPT, and Cursor) and external services, enabling AI agents to access external tools and resources. Its primary capability is providing a centralized search tool to discover other MCP servers and their respective tools. Unlike local implementations, it runs remotely with OAuth authentication and permission controls for security.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceA high-performance MCP server that enables AI assistants to safely interact with MySQL databases through secure CRUD operations, schema inspection, and parameterized queries with built-in SQL injection prevention.1-
- AlicenseNot gradedqualityDmaintenanceA MySQL MCP server for secure database interaction, enabling schema inspection, query execution, and RBAC via AI coding assistants.1,352 npm5MIT
- AlicenseNot gradedqualityDmaintenanceMCP server that connects AI agents to MySQL databases for schema exploration, data querying, and SQL execution via natural language.2MIT
- AlicenseNot gradedqualityDmaintenanceA production-ready MCP server for MySQL database integration with AI agents, enabling database exploration, CRUD operations, schema management, and performance monitoring through natural language.744 npmMIT