Local Database Analytics MCP Server
本地数据库分析 MCP 服务器
一个基于 Python 的 模型上下文协议(MCP)服务器,将本地 SQLite 电子商务数据库暴露给 Claude 等 AI 助手。使用 FastMCP、SQLAlchemy 和 Pandas 构建。
什么是 MCP? 模型上下文协议(由 Anthropic 提出)让 AI 模型能够安全地与本地工具和数据交互。该服务器让 Claude 了解你的数据库,使其能够使用自然语言查询、分析和解释数据。
功能特性
工具(共 11 个)
工具 | 描述 |
| 列出数据库中的所有表 |
| 显示指定表的模式/列结构 |
| 从表中返回 N 条样本行 |
| 统计行数,支持可选的 WHERE 过滤条件 |
| 执行任何安全的 SELECT 查询 |
| 统计信息:任意列的最小值/最大值/均值/空值/唯一值 |
| 按某列排序的前 N 行 |
| GROUP BY + SUM/AVG/COUNT/MIN/MAX |
| 查找包含缺失数据的列 |
| 两列之间的皮尔逊相关系数 |
| 按日/周/月聚合数据 |
资源
URI | 描述 |
| 完整数据库模式 |
| 指定表的模式 |
提示词
analyze_table— 对任意表进行完整统计分析business_summary— 高管级别的电子商务报告find_anomalies— 数据质量与异常值检测
Related MCP server: db-mcp
数据库模式
customers ──< orders ──< order_items >── productscustomers:15 条记录,包含姓名、邮箱、城市、注册日期
products:15 个产品,涵盖电子产品、图书、运动、家居、文具
orders:60 条订单,包含状态(已完成/待处理/已取消)和金额
order_items:将订单与产品关联的订单明细行
项目结构
MCP_Server/
├── server.py # FastMCP server entry point
├── requirements.txt # Python dependencies
├── database/
│ ├── engine.py # SQLAlchemy DB connection
│ └── seed_data.py # Seed script (creates + populates DB)
├── tools/
│ ├── query.py # Core SQL tools (Phase 2)
│ └── analytics.py # Analytics tools (Phase 3)
├── resources/
│ └── schema.py # DB schema as MCP resources
├── prompts/
│ └── templates.py # Pre-built analyst prompts
├── tests/
│ └── test_tools.py # Unit tests
└── data/
└── analytics.db # SQLite database (auto-created)快速开始
1. 克隆仓库
git clone https://github.com/manohar135/Local-Database-Analytics-MCP-Server.git
cd Local-Database-Analytics-MCP-Server2. 创建虚拟环境并安装依赖
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install -r requirements.txt3. 初始化数据库
python database/seed_data.py4. 启动 MCP Inspector(开发模式)
fastmcp dev server.py5. 运行测试
pytest tests/ -v技术栈
技术 | 角色 |
MCP 服务器框架 | |
SQLite | 零配置本地数据库 |
SQLAlchemy | 数据库引擎与 ORM |
Pandas | 数据分析与聚合 |
Pydantic | 输入验证 |
Pytest | 单元测试 |
Claude 对话示例
连接到 Claude Desktop 后,可以尝试:
"你可以访问哪些表?"
"给我一份销售数据的业务摘要"
"哪些产品卖得最好?"
"orders 表中是否存在数据质量问题?"
"展示过去一年的月度收入趋势"
This server cannot be deployed
Maintenance
Related MCP Connectors
Run your ecommerce ads from Claude & ChatGPT: Meta, Google, Amazon, Shopify (150 tools)
Ask questions across Shopify, Klaviyo, GA4 and 20+ e-commerce sources in plain English.
Ask data questions in natural language. Get SQL, insights, and charts from your databases.
Query 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables natural-language querying of an e-commerce dataset by providing a LangChain agent that uses tools to execute parameterized SQL queries on a SQLite database, with short-term memory and Streamlit or Claude Desktop interfaces.-
- AlicenseAqualityBmaintenanceEnables AI agents to safely interact with a SQLite shop database through schema discovery, read-only SQL queries, and pre-built analytics reports like top customers, top products, and revenue summaries.6142 npmMIT
- FlicenseAqualityBmaintenanceGives AI agents read-only analytical access to an e-commerce SQLite database (customers, orders, order_items, products) via SQL queries, table listing, and schema inspection.3-
- FlicenseAqualityCmaintenanceEnables AI agents to analyze an SQLite e-commerce database via secure read-only SQL queries, providing tools for table inspection and analytical requests.2-