Shop Analytics MCP Server
Enables 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.
README
Shop Analytics MCP Server
A read-only MCP server, over stdio, that lets an AI
agent answer analytical questions about an online store's SQLite database
(customers, products, orders, order_items) — without ever being able to
modify it.
See SPEC.md for the full design rationale (decisions log, schema, security model, testing strategy).
Requirements
- Node.js >= 24.10.0 (needed for
node:sqlite'ssetAuthorizer, used by the read-only guarantee below). Check withnode --version. - No other runtime dependencies beyond what
npm ciinstalls.
Install → configure → run → connect
npm ci
npm run build
SHOP_DB_PATH=./shop.db npm start
shop.dbships in this repository, ready to use. If you ever need to regenerate it deterministically from the schema, runnpm run seed(see Database below).SHOP_DB_PATHis optional; it defaults toshop.dbin the current working directory. No absolute path is hard-coded anywhere in the source.- The server speaks MCP over stdio only — there is no HTTP server and nothing else to run.
Connect an AI agent
Config examples for two clients are in config/:
config/claude-code.mcp.json— copy into a project's.mcp.json, or runclaude mcp add-jsonwith itsshop-analyticsentry. Fill in absolute paths forargs/envfirst.config/codex.mcp.toml— copy the[mcp_servers.shop-analytics]table into~/.codex/config.toml(or a project-scoped.codex/config.toml), or use thecodex mcp addcommand in the file's header comment.
To poke at the server manually without any specific agent, use the tool-agnostic MCP Inspector:
SHOP_DB_PATH=$(pwd)/shop.db npx @modelcontextprotocol/inspector node dist/src/index.js
Tools
The server exposes exactly 8 specialized, read-only tools — no tool accepts or
executes arbitrary SQL. Every successful response is { "data": [...], "meta": {...} };
every error is a plain, safe, human-readable message (no SQL, file paths, or
stack traces), flagged with isError: true.
| Tool | Answers | Key parameters |
|---|---|---|
get_database_schema |
"Show me all tables and what they contain." | (none) |
get_customers_by_country |
"How many customers are from Germany?" | country (required) |
get_top_countries_by_customers |
"Which country has the most customers?" | limit (default 1) |
get_top_customers_by_spend |
"Who spent the most money?" | limit, from, to |
get_top_selling_products |
"What are the top 5 best-selling products?" | limit (default 5), from, to |
get_top_categories_by_revenue |
"What are the top 3 categories by revenue?" | limit (default 3), from, to |
get_revenue_for_period |
"How much revenue did we generate in 2025?" | from, to |
get_top_customers_by_orders |
"Which customer placed the most orders?" | limit, from, to |
from/to are YYYY-MM-DD and define a half-open UTC interval [from, to);
from must be strictly earlier than to. All financial and count metrics
exclude orders with status cancelled. Full per-tool contracts (exact response
shapes, tie-break rules) are in SPEC.md §4.
Safety
Three independent, defense-in-depth layers guarantee the database is never modified, even by an adversarial prompt like "Delete all cancelled orders":
- The SQLite connection is opened with
readOnly: true. PRAGMA query_only = ONis set immediately after opening.- A SQLite
authorizerexplicitly denies every write/DDL action (INSERT,UPDATE,DELETE,DROP,ALTER,CREATE,ATTACH,DETACH, transactions, ...).
On top of that, no tool accepts raw SQL, table names, or column names — every
query is a fixed prepared statement, and every input is validated with zod
and passed as a bound parameter, never string-interpolated.
Database
shop.db is generated from database/schema.sql by a
deterministic seed script — re-running it produces byte-identical data
every time (fixed PRNG seed, no wall-clock dependency):
npm run seed # builds, then (re)writes ./shop.db from schema.sql + the seed script
The seed script also asserts, at generation time, that the dataset has no ambiguous leaderboards (e.g. a unique top country, a unique top spender) and non-zero 2025 revenue — see SPEC.md §3.
Development
npm run build # tsc + copy database/schema.sql into dist/
npm run test:unit # business logic, in isolation, against fixture databases
npm run test:integration # spawns the built server over stdio via the MCP SDK client
npm test # both
This project was built with TDD: for every module, a failing test was written first, then the implementation, tool by tool. The integration suite covers all 8 acceptance scenarios end-to-end, SQL-injection-shaped inputs, invalid parameter combinations, and asserts the database file's SHA-256 hash is unchanged after every run.
Project structure
database/ schema.sql + the deterministic seed generator
src/
db.ts read-only SQLite connection (see Safety above)
errors.ts error taxonomy, safe error formatting
validation.ts zod schemas shared across tools (dates, limits, periods)
period.ts half-open period SQL clause builder
tools/ one module per tool: pure query function + types
server.ts registers all 8 tools on the MCP server
index.ts stdio entrypoint
test/
unit/ one file per module/tool, fixture-based
integration/ spawns dist/src/index.js over stdio via the MCP SDK client
config/ example client configuration (Claude Code, Codex CLI)
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。