Skip to main content
Glama
manohar135

Local Database Analytics MCP Server

by manohar135

本地数据库分析 MCP 服务器

一个基于 Python 的 模型上下文协议(MCP)服务器,将本地 SQLite 电子商务数据库暴露给 Claude 等 AI 助手。使用 FastMCP、SQLAlchemy 和 Pandas 构建。

什么是 MCP? 模型上下文协议(由 Anthropic 提出)让 AI 模型能够安全地与本地工具和数据交互。该服务器让 Claude 了解你的数据库,使其能够使用自然语言查询、分析和解释数据。


功能特性

工具(共 11 个)

工具

描述

list_tables

列出数据库中的所有表

describe_table

显示指定表的模式/列结构

get_sample_rows

从表中返回 N 条样本行

get_row_count

统计行数,支持可选的 WHERE 过滤条件

run_sql_query

执行任何安全的 SELECT 查询

summarize_column

统计信息:任意列的最小值/最大值/均值/空值/唯一值

find_top_n

按某列排序的前 N 行

group_and_aggregate

GROUP BY + SUM/AVG/COUNT/MIN/MAX

detect_nulls

查找包含缺失数据的列

compute_correlation

两列之间的皮尔逊相关系数

time_series_summary

按日/周/月聚合数据

资源

URI

描述

db://schema

完整数据库模式

db://tables/{name}

指定表的模式

提示词

  • analyze_table — 对任意表进行完整统计分析

  • business_summary — 高管级别的电子商务报告

  • find_anomalies — 数据质量与异常值检测


Related MCP server: db-mcp

数据库模式

customers ──< orders ──< order_items >── products
  • customers: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-Server

2. 创建虚拟环境并安装依赖

python -m venv .venv
source .venv/bin/activate       # On Windows: .venv\Scripts\activate
pip install -r requirements.txt

3. 初始化数据库

python database/seed_data.py

4. 启动 MCP Inspector(开发模式)

fastmcp dev server.py

5. 运行测试

pytest tests/ -v

技术栈

技术

角色

FastMCP

MCP 服务器框架

SQLite

零配置本地数据库

SQLAlchemy

数据库引擎与 ORM

Pandas

数据分析与聚合

Pydantic

输入验证

Pytest

单元测试


Claude 对话示例

连接到 Claude Desktop 后,可以尝试:

  • "你可以访问哪些表?"

  • "给我一份销售数据的业务摘要"

  • "哪些产品卖得最好?"

  • "orders 表中是否存在数据质量问题?"

  • "展示过去一年的月度收入趋势"

Related MCP Connectors

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    Enables 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.
    -
  • A
    license
    A
    quality
    B
    maintenance
    Enables 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.
    6
    142 npm
    MIT
  • F
    license
    A
    quality
    B
    maintenance
    Gives 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
    -
  • F
    license
    A
    quality
    C
    maintenance
    Enables AI agents to analyze an SQLite e-commerce database via secure read-only SQL queries, providing tools for table inspection and analytical requests.
    2
    -