DatabaseMCP

DatabaseMCP

An MCP server that enables AI agents to safely explore and interact with MySQL databases through dynamic tool generation from stored procedures. It provides database discovery capabilities and intelligent procedure categorization while enforcing security restrictions to prevent data modification.

Category
访问服务器

README

MCP Database Intelligence Server Architecture

System Overview

The system exposes database capabilities to AI agents using the Model Context Protocol (MCP).

The MCP server acts as a bridge between:

  • AI assistants
  • database metadata
  • stored procedures
  • database exploration tools

High Level Architecture

AI Agent / MCP Client │ ▼ MCP Server (FastMCP) │ ├── Discovery Tools │ (database exploration) │ ├── Dynamic Procedure Tools │ (generated from database procedures) │ ▼ Intelligence Engine (procedure metadata + categorization) │ ▼ Database Access Layer │ ▼ MySQL Database

Core Components

1. MCP Server (main.py)

The MCP server is created using FastMCP.

Responsibilities:

  • initialize the MCP server
  • register discovery tools
  • register dynamic procedure tools

2. Database Access Layer (db.py)

This module manages all database communication.

Responsibilities:

  • database connection management
  • stored procedure execution
  • metadata retrieval
  • enforcing result limits

All database interactions pass through this layer.

3. Tool Generator (tool_generator.py)

This module dynamically converts database stored procedures into MCP tools.

Steps performed:

  1. load procedure metadata from database
  2. detect procedure parameters
  3. generate MCP tool functions dynamically
  4. register tools with the MCP server

This allows the system to automatically support new procedures added to the database.

4. Intelligence Engine (intelligence_engine.py)

The intelligence engine analyzes stored procedures to generate metadata.

Capabilities include:

  • procedure categorization
  • description generation
  • parameter analysis

Example categories:

Procedure Pattern Category
GetLinkCount Network Analytics
GetWeekData Time Analytics
InterfaceLinkType Interface Analytics

This metadata helps AI agents understand the purpose of each tool.

5. Discovery Tools (discovery_tools.py)

Discovery tools allow AI agents to explore database structure.

Implemented tools:

list_databases list_tables describe_table

These tools rely on database metadata from:

INFORMATION_SCHEMA

Security Architecture

Several safeguards are implemented to ensure safe database interaction.

Keyword Restrictions

Procedures containing dangerous keywords are blocked.

Examples:

DELETE DROP TRUNCATE UPDATE INSERT ALTER

Query Result Limits

The system limits result size using a configurable value:

MAX_QUERY_ROWS

This prevents large data extraction.

Rate Limiting

The MCP server enforces request rate limits to prevent excessive usage.

Restricted Database User

The database user used by the MCP server should only have:

SELECT EXECUTE

permissions.

This prevents modification of production data.

Metadata Sources

The system retrieves metadata from MySQL system tables.

Examples:

INFORMATION_SCHEMA.ROUTINES INFORMATION_SCHEMA.PARAMETERS INFORMATION_SCHEMA.TABLES INFORMATION_SCHEMA.COLUMNS

These tables allow the MCP server to automatically understand database structure.

Example AI Interaction Flow

Example interaction between an AI agent and the database:

list_databases() ↓ list_tables() ↓ describe_table("interface_stats") ↓ GetLinkCount("NodeA")

This allows the AI to explore database structure before executing analytical procedures.

Extensibility

The system is designed to support additional database objects.

Future extensions may include:

list_views list_functions list_triggers search_tables explain_query

The modular architecture allows new tools to be added easily.

Conclusion

This architecture demonstrates how MCP servers can safely expose database capabilities to AI systems.

Key design principles:

• modular architecture • dynamic tool generation • metadata driven discovery • secure database access

This approach enables safe and scalable AI-database integration.

Detailed system diagrams are available in the docs/ directory.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选