Read-Only SQLite Shop Database MCP Server
Enables AI agents to safely inspect and query an SQLite e-commerce database with tools for listing tables, describing schemas, and running read-only SQL queries while blocking destructive operations.
README
Read-Only SQLite Shop Database MCP Server
An official Model Context Protocol (MCP) server providing secure, read-only database access to an SQLite e-commerce store (shop.db) for AI agents.
🌟 Key Features
- Standard
stdioTransport: Works seamlessly with any MCP client (Claude Desktop, Cursor, Gemini CLI, Antigravity, etc.). - Multi-layered Read-Only Security:
- SQLite URI read-only mode (
?mode=ro). - Strict runtime
PRAGMA query_only = ON;. - Pre-flight SQL parser rejecting all DDL/DML mutation statements (
INSERT,UPDATE,DELETE,DROP,ALTER,CREATE, etc.). - Blocks SQL injection chains and multi-statement execution.
- SQLite URI read-only mode (
- LLM-Optimized Tools: Clear descriptions, robust error handling without raw stack traces, and automatic pagination (
limit/offset). - Flexible Path Resolution: Works out of the box with relative paths,
DB_PATHenvironment variable, or--db-pathCLI flag.
🗄️ Database Schema
The SQLite database (shop.db) contains the following entities:
customers
│
└──< orders
│
└──< order_items >── products
customers:id,first_name,last_name,email,phone,created_atproducts:id,name,category,price,stock_quantity,created_atorders:id,customer_id,order_date,status(new,processing,shipped,completed,cancelled),total_amountorder_items:id,order_id,product_id,quantity,unit_price
🛠️ MCP Tools
| Tool | Parameters | Description |
|---|---|---|
list_tables |
None | Lists all user tables with column count and row count summary. |
describe_table |
table_name (string, required) |
Returns column definitions, data types, primary keys, foreign keys, row count, and sample rows. |
get_database_schema |
None | Returns the complete schema and relationship graph of all tables in one call. |
read_query |
query (string, required), limit (int, default: 100), offset (int, default: 0) |
Executes read-only queries (SELECT, WITH, EXPLAIN) with pagination. |
🚀 Getting Started
1. Installation
Create a virtual environment and install the required dependencies:
# Create virtual environment
python3 -m venv .venv
source .venv/bin/activate
# Install dependencies
pip install -r requirements.txt
2. Running Locally
Run the MCP server over standard input/output:
python server.py
Or specify a custom database path:
# Using CLI argument
python server.py --db-path /path/to/shop.db
# Or using Environment Variable
DB_PATH=/path/to/shop.db python server.py
3. Running Tests
Run the test suite to verify tool functionality and safety constraints:
python -m unittest discover -s tests -v
🔌 Connecting to AI Agents
Claude Desktop
Add this server to your claude_desktop_config.json (~/Library/Application Support/Claude/claude_desktop_config.json on macOS or %APPDATA%\Claude\claude_desktop_config.json on Windows):
{
"mcpServers": {
"shop-database": {
"command": "/absolute/path/to/.venv/bin/python",
"args": ["/absolute/path/to/server.py"],
"env": {
"DB_PATH": "/absolute/path/to/shop.db"
}
}
}
}
Cursor IDE
In Cursor Settings → Features → MCP:
- Type:
command - Command:
/absolute/path/to/.venv/bin/python /absolute/path/to/server.py
Antigravity / Gemini CLI
Add to your MCP configuration file:
{
"mcpServers": {
"shop-database": {
"command": "python",
"args": ["server.py"]
}
}
}
🔒 Safety & Validation Examples
If an AI agent or prompt attempts a destructive operation, the server immediately rejects the query gracefully:
- Prompt: "Delete all cancelled orders."
- Server Response:
{ "error": "Operation rejected: Statement type 'DELETE' is not allowed. Only read-only queries (SELECT, WITH ... SELECT, EXPLAIN) are permitted." }
📊 Verification Queries
The server enables AI agents to resolve analytical queries such as:
- Table Discovery:
list_tables()anddescribe_table(table_name="customers") - Customer Demographics:
SELECT count(*) FROM customers WHERE phone LIKE '+7%'; - Customer Who Spent the Most Money:
SELECT c.first_name, c.last_name, c.email, SUM(o.total_amount) AS total_spent FROM customers c JOIN orders o ON c.id = o.customer_id WHERE o.status != 'cancelled' GROUP BY c.id ORDER BY total_spent DESC LIMIT 1; - Top 5 Best-Selling Products:
SELECT p.name, SUM(oi.quantity) AS units_sold, SUM(oi.quantity * oi.unit_price) AS revenue FROM products p JOIN order_items oi ON p.id = oi.product_id JOIN orders o ON oi.order_id = o.id WHERE o.status != 'cancelled' GROUP BY p.id ORDER BY units_sold DESC LIMIT 5; - Top 3 Product Categories by Revenue:
SELECT p.category, SUM(oi.quantity * oi.unit_price) AS revenue FROM products p JOIN order_items oi ON p.id = oi.product_id JOIN orders o ON oi.order_id = o.id WHERE o.status != 'cancelled' GROUP BY p.category ORDER BY revenue DESC LIMIT 3; - Customer With Most Orders:
SELECT c.first_name, c.last_name, COUNT(o.id) AS order_count FROM customers c JOIN orders o ON c.id = o.customer_id GROUP BY c.id ORDER BY order_count DESC LIMIT 1;
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。