Shop Analytics MCP
Shop Analytics MCP
基于 TypeScript 的 MCP 服务器,用于安全分析在线商店的 SQLite 数据库。仅通过 stdio 工作,并提供六个专用工具;不接受任意 SQL。
要求
Node.js 24.10+;
npm;
sqlite3CLI 仅用于重新应用迁移。
Related MCP server: Shop SQLite MCP
安装与运行
npm ci
npm run build
SHOP_DB_PATH=./shop.db npm startSHOP_DB_PATH 具有优先级。如果未设置该变量,服务器将在当前工作目录中查找 shop.db。数据库路径未硬编码在源代码中。
数据
仓库中包含已迁移的现成 shop.db。它包含客户国家和 2025 年的数据。货币值视为 EUR,不进行转换。
要一次性将迁移应用到原始数据库:
npm run migrate原始模式位于 database/schema.sql,确定性迁移位于 database/001-add-analytics-data.sql。
连接到客户端
现成的配置模板位于 config/:
claude-code.mcp.json;codex.mcp.json;cursor.mcp.json.
将所选模板中的 /absolute/path/to/mcp-server 替换为此项目的路径。所有配置都通过 stdio 运行 dist/src/index.js,并通过 SHOP_DB_PATH 传递 shop.db 的路径。
工具
工具 | 用途 |
| 表、列、键和关系。 |
| 某个国家/地区的客户数量或客户最多的国家/地区。 |
| 按已售数量和收入排名的商品排行榜。 |
| 按收入排名的类别排行榜。 |
| UTC 期间 |
| 消费最多或订单数最多的客户。 |
财务和商品指标以及订单数量均排除 cancelled。金额在带有 Eur 后缀的字段中返回。排行榜接受从 1 到 100 的 limit;期间使用 YYYY-MM-DD 日期。
使用示例
下面展示了 MCP 客户端如何调用 get_database_schema 来描述表,然后调用 get_customer_metrics 来统计来自德国的客户。

安全性
SQLite 以
readOnly: true和PRAGMA query_only = ON打开。SQLite authorizer 禁止写入、DDL、
ATTACH、DETACH和事务。所有值都作为 SQL 参数绑定。
工具不接受 SQL,因此代理无法传递破坏性语句。
验证错误不会泄露 SQL、绝对路径或堆栈跟踪。
测试
npm test测试覆盖八个验收问题的参考答案、国家/地区参数中的 SQL 注入、对 DELETE 的禁止、数据库临时副本的 SHA-256 不变性,以及通过 stdio 的 MCP 交互。
验收问题
显示所有可用的表,并解释每个表包含哪些信息。
有多少客户来自德国?
哪个国家的客户最多?
哪位客户消费最多?
销量前 5 的产品有哪些?
按收入排名的前 3 个产品类别是什么?
我们在 2025 年产生了多少收入?
哪个客户下的订单最多?
Available Tools
6 toolsget_category_revenueA
Rank non-cancelled categories by EUR revenue. Optional YYYY-MM-DD from/to and integer limit 1-100.
Inputs: no named parameters.
get_customer_metricsB
Count customers in a country or find the top country. Parameters: mode=count_by_country with country, or mode=top_country without country.
Inputs: no named parameters.
get_database_schemaA
Inspect tables, columns, keys, and relationships. Parameters: none.
Inputs: no named parameters.
get_order_leadersA
Find a customer with highest spend or most non-cancelled orders. mode=highest_spend accepts optional YYYY-MM-DD from/to; mode=most_orders accepts no dates.
Inputs: no named parameters.
get_product_salesA
Rank non-cancelled products by units sold and EUR revenue. Optional YYYY-MM-DD from/to and integer limit 1-100.
Inputs: no named parameters.
get_revenue_by_periodA
Calculate non-cancelled EUR revenue. Optional YYYY-MM-DD from/to define [from, to).
Inputs: no named parameters.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Each tool targets a distinct entity or aggregation level: database schema, customer counts, product sales rankings, category revenue, total revenue, and customer leaders. Even though get_customer_metrics and get_order_leaders both involve customers, their purposes (country-level counts vs. individual customer extremes) are clearly separated. No two tools are likely to cause misselection.
All tool names follow the consistent pattern 'get_' followed by a descriptive noun phrase, using snake_case throughout. Examples: get_database_schema, get_product_sales, get_revenue_by_period. This uniform phrasing makes the set predictable and easy to navigate.
With 6 tools, the server is well-scoped for a shop analytics use case. It covers the essential query types without unnecessary proliferation, and each tool earns its place by addressing a distinct analytical question. The count is within the ideal range for a focused server.
The tool set covers key analytics workflows: schema inspection, customer metrics, product and category performance, total revenue, and top customer identification. Minor gaps include lack of time-series revenue breakdown (e.g., by day/month) and no list of customers beyond the leader, but the core analytical needs are met. These omissions are workable around.
Related MCP Connectors
Read-only analytics for all your apps: users, AI traffic, revenue, with the SQL behind every number.
Text-to-SQL for Claude & ChatGPT: OAuth sign-in, read-only Postgres/MySQL/SQL Server, free demo_shop
Cookieless web analytics an agent creates and queries: goals, funnels, revenue, SQL. Open source.
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables AI assistants like Claude to query, analyze, and summarize local SQLite e-commerce databases using natural language through 11 tools, schema resources, and pre-built analytical prompts.-
- FlicenseNot gradedqualityDmaintenanceEnables safe, read-only analysis of an online store's SQLite database, providing schema introspection, restricted SELECT queries, and specialized analytics tools through MCP.-
- FlicenseAqualityDmaintenanceEnables 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-
- FlicenseAqualityDmaintenanceEnables AI agents to answer analytical questions about an online store's SQLite database through specialized read-only tools, without any risk of modifying the underlying data.8-