shop
商店的只读 MCP 服务器
用于现有在线商店 SQLite 数据库(data/shop.db)的 Python MCP 服务器,通过 stdio 运行。该文件仅以只读方式打开;任何修改类 SQL 都会被拒绝且不会执行。
安装
Python 3.11+:
python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"Related MCP server: Shop SQLite MCP
运行
从项目根目录运行(默认数据库路径为 ./data/shop.db):
python -m shop_mcp
# или
shop-mcp使用其他数据库路径:
SHOP_DB_PATH=~/my/test-mcp-db/data/shop.db python -m shop_mcp进程通过 MCP 经由 stdin/stdout 通信。在 MCP 客户端连接到此终端之前,请不要在该终端中输入命令。
在 Cursor 中配置 MCP
添加 mcpServers 条目(Cursor Settings → MCP 或项目中的 .cursor/mcp.json)。传输方式为 stdio。
示例中的路径 ~/my/test-mcp-db 就是此仓库。SHOP_DB_PATH 服务器会自行展开(~ → 主目录)。如果 Cursor 在 command / cwd 中没有展开 ~,请在那里填写 /Users/<你>/my/test-mcp-db/...。
本地(venv)
{
"mcpServers": {
"shop": {
"command": "~/my/test-mcp-db/.venv/bin/python",
"args": ["-m", "shop_mcp"],
"cwd": "~/my/test-mcp-db",
"env": {
"SHOP_DB_PATH": "~/my/test-mcp-db/data/shop.db"
}
}
}
}如果在 pip install -e . 之后更喜欢使用控制台脚本:
{
"mcpServers": {
"shop": {
"command": "~/my/test-mcp-db/.venv/bin/shop-mcp",
"cwd": "~/my/test-mcp-db",
"env": {
"SHOP_DB_PATH": "~/my/test-mcp-db/data/shop.db"
}
}
}
}Docker
构建一次镜像:
docker build -t shop-mcp .{
"mcpServers": {
"shop": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-v",
"~/my/test-mcp-db/data/shop.db:/data/shop.db:ro",
"-e",
"SHOP_DB_PATH=/data/shop.db",
"shop-mcp"
]
}
}
}-i 标志是必需的,以便保持 stdio 连接。请只挂载 shop.db;容器不应覆盖主机上的文件。
工具
Tool | 作用 |
| 用户表及其角色的简要说明(不显示 |
| 实际列、类型、PK/FK |
| 单个 |
| 无需手写 SQL 即可获得年度评分和收入 |
金额、件数和收入按 order_items.quantity * order_items.unit_price 计算;状态为 cancelled 的订单会被排除。日历年取自 strftime('%Y', orders.order_date)。
安全性
SQLite URI
file:<abs>?mode=ro注释会被去除;查询串(
SELECT 1; DELETE ...)会被拒绝INSERT / UPDATE / DELETE / DROP / ALTER / CREATE / ATTACH / PRAGMA / … → 明确错误「不允许」
SQLite 语法错误和未知列会以结构化方式返回;进程不会退出
评估注意事项
customers没有country列。 这可以通过describe_table看到;不能虚构地理位置。SELECT country FROM customers会返回 SQLite 错误。当前数据转储中的订单日期是 2026 年。 2025 年的收入可能为 0。这是正确结果,不是过滤条件失效。
测试
pytest测试会将 data/shop.db 复制到临时文件,并验证在拒绝写入后副本的哈希没有变化。
已处理请求示例

Available Tools
4 toolsdescribe_tableA
Describe columns, types, primary keys, and foreign keys for one table.
Use before writing joins. Returns actual SQLite metadata only — never fabricates fields such as country. Parameters: table (name from list_tables). Returns {table, columns: [{name, type, primary_key, ...}], foreign_keys}.
Inputs: table (required). Returns: object
execute_readonly_sqlA
Run a single read-only SQL statement against shop.db.
Allowed: one SELECT, WITH (CTE), or EXPLAIN. Writes and DDL (INSERT, UPDATE, DELETE, REPLACE, DROP, ALTER, CREATE, TRUNCATE, ATTACH, VACUUM, REINDEX, PRAGMA) are rejected with an explicit not-allowed error. Stacked statements (semicolons) are rejected. Prefer shop_analytics for rankings and yearly revenue.
Pagination: default limit 100, maximum 1000 (error if exceeded), offset default 0. Returns {columns, rows, truncated, row_count, next_offset} or {error, sqlite_error?}. The database is opened read-only; refused mutations leave the file unchanged.
Inputs: sql (required), limit, offset. Returns: object
list_tablesA
List user tables in shop.db with a one-line purpose for each.
Use this first to discover the real schema. Internal SQLite tables such as sqlite_sequence are omitted. Does not invent columns (customers has no country). Returns {tables: [{name, purpose}, ...]}.
Inputs: no named parameters. Returns: object
shop_analyticsA
Shop aggregations without hand-written SQL.
Operations: top_customers_by_spend (name, email, total_amount; default limit 5), customer_most_orders (name, email, order_count), top_products (product_name, units_sold, revenue; default limit 5), top_categories (category, revenue; default limit 3), revenue_by_year (requires year). Spend/units/revenue use quantity * unit_price and exclude cancelled orders. Year is taken from order_date.
Inputs: operation (required), year, limit. Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 4 tools
The schema-discovery tools are clearly separated from the querying/analytics tools. There is some overlap between execute_readonly_sql and shop_analytics, but the descriptions explicitly steer agents toward shop_analytics for rankings and revenue, reducing confusion.
Three tools follow a clear verb-first snake_case pattern: list_tables, describe_table, execute_readonly_sql. shop_analytics breaks that pattern as a nouny resource name, though it is still understandable and not chaotic.
Four tools is a well-scoped set for a read-only shop database. Each tool fills a distinct role: schema discovery, table metadata, raw SQL execution, and prebuilt analytics, with no redundancy.
For a read-only database exploration server, the workflow is complete: list the tables, describe one, run arbitrary safe SQL, and get common analytics. There are no missing mutations or write operations because the server is explicitly read-only.
Maintenance
Related MCP Connectors
Query your org's data in natural language — read-only MCP access to SQL, NoSQL, files & warehouses.
PostgreSQL, MySQL, and SQL Server in one session. 26 read-only MCP tools for AI agents.
Read databases and usage, run read-only SQL, and create databases and tokens in Turso.
Read authorized Loam tables and supported external databases through a bounded MCP connection.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables natural-language sales queries against a SQLite database, generating and executing read-only SQL through a secure MCP server with table listing, schema description, and query execution.-
- 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.-
- FlicenseNot gradedqualityDmaintenanceThis MCP server lets an AI agent securely connect to a read-only SQLite store database, inspect its tables and schema, and run analytical SQL queries without modifying any data.-
- FlicenseNot gradedqualityDmaintenanceEnables AI agents to read-only analyze a SQLite e-commerce database, exploring schema and running analytical SQL queries over stdio.-