Skip to main content
Glama

MCP server shop-db

Read-only MCP server (stdio transport) that gives an AI agent access to the SQLite database of the online store shop.db: customers, products, orders, and order items.

Built on the official MCP Python SDK (v2).

Development metadata

The project was entirely generated by an AI coding agent (Claude Code, Fable 5 model) from the specification in SPEC.md.

Metric

Value

Specification size in tokens

≈ 1,800 (cl100k_base; 1,316 in o200k_base)

Started on the first try

Yes — the server came up over stdio and passed all 8 tasks + the safety check on the first run

Number of auxiliary requests

4 (MCP SDK documentation via Context7 — 3, version check on PyPI — 1)

Total number of prompts

6 (specification; real shop.db + metadata; README translation; test run; collection of results; refresh + publication)

Final number of bugs

0 in the server code; 2 minor ones in helper files (wrong import order in a test, outdated field name in a one-off e2e script), fixed before the commit

Total tokens spent

≈ 365,000: ≈ 175,000 main session + ≈ 190,000 test-run sub-agents (not counting the headless agents that ran the checks themselves)

Related MCP server: Shop Analytics MCP Server

Tools

Tool

Purpose

list_tables

Overview of all tables: row count, columns, description, relationships between tables. A natural first call.

describe_table(table_name)

Full schema of one table: column types, primary/foreign keys, 3 sample rows.

query(sql, limit=50, offset=0)

Runs a single read-only SELECT (or WITH ... SELECT). Supports JOIN and aggregation. Results are paginated: no more than 500 rows per call, with truncated / next_offset in the response.

Security

It is impossible to modify the database through this server. Three independent layers of protection:

  1. Request validation — anything that is not a single SELECT/WITH (INSERT, UPDATE, DELETE, DROP, ALTER, CREATE, PRAGMA, ATTACH, multiple statements in a row, or a write hidden behind a comment) is rejected with a clear message before it is ever executed.

  2. Read-only connection — the file is opened via the SQLite URI with mode=ro.

  3. PRAGMA query_only = ON on every connection.

Even a write that passes validation (for example, WITH ... INSERT) runs into the read-only constraint at the connection level.

SQL errors are returned as short, clear messages with hints — no stack traces.

Installation

Requires Python 3.10+.

Via uv (recommended — everything installs automatically on first run):

uv sync

Or via pip:

python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

Configuration

The server looks for the database in the shop.db file next to server.py — the database provided in the assignment is included in the repository. To use a different file, set the SHOP_DB_PATH environment variable:

export SHOP_DB_PATH=/path/to/shop.db

seed_db.py is a helper utility that generates a demo database with a similar schema; use it only if you need temporary data. It leaves shop.db alone unless you explicitly ask:

python seed_db.py /tmp/demo.db

Running

The server communicates over stdio — it is launched by an MCP client, not by the user manually. To verify that it starts without errors:

uv run python server.py

(the server will wait for MCP messages on stdin; exit with Ctrl+C)

Connecting to an agent

Claude Code

The repository includes .mcp.json, so from the project directory the server is picked up automatically. To register manually:

claude mcp add shop-db -- uv run --directory /absolute/path/to/sqlite-mcp python server.py

Claude Desktop (or any client with a JSON config)

Add the entry to claude_desktop_config.json (see examples/claude_desktop_config.example.json). When installed via the dependencies, they must be installed to account for the terminal that the config points to:

{
  "mcpServers": {
    "shop-db": {
      "command": "/absolute/path/to/sqlite-mcp/.venv/bin/python",
      "args": ["/absolute/path/to/sqlite-mcp/server.py"]
    }
  }
}

Or via uv (no ... setup needed):

{
  "mcpServers": {
    "shop-db": {
      "command": "uv",
      "args": ["run", "--directory", "/absolute/path/to/sqlite-mcp", "python", "server.py"]
    }
  }
}

Docker

docker build -t shop-db-mcp .
{
  "mcpServers": {
    "shop-db": {
      "command": "docker",
      "args": ["run", "-i", "--rm", "shop-db-mcp"]
    }
  }
}

Example questions the agent answers

  • Show me the available tables and explain what information each table contains.

  • How many customers are from United States?

  • Which country has the most customers?

  • Who is the customer who spent the most money?

  • What are the top 5 best-selling products?

  • What are the top 3 product categories by revenue?

  • How much revenue did we generate in 2025?

  • Which customer placed the most orders?

Destructive requests such as "Delete all cancelled orders" are rejected by the server.

Note on the assignment data: customers has no "column: customers" (the location can only be inferred from phone codes — all numbers start with +7 — or from email domains), and all orders are dated February–August 2026. The schema tools give the agent everything it needs to detect and answer honestly.

Test results

All 27 tests in the spec were run through a real agent (claude -p "<question>" --mcp-config .mcp.json, with Gemini), using only the server’s three MCC tools — no Bash, no filesystem access. The answer was compared with the reference computed directly from SQLite. Result: 9/9.

#

Check

Verdict

Comment

1

Table overview

✅

All 4 tables, row counts, columns, relationships — in a single tables check

2

Customers from Germany

✅

Honest answer: no "country" field in DB, not possible to determine

3

Country with the most customers

✅

Agent checked with SQL: all 150 numbers start with +7 → Russia

4

Customer who spent the most

✅

Name, email, and total (701,780 net) — matches

5

Top 5 products

✅

name, quantity, and revenue matched the test to the cent

6

Top 3 categories by revenue

✅

17,060,760 / 5,506,570 / 3,085,470 (without cancellation) — exact match

7

Revenue for 2025

✅

0 — the agent found the orders all date from 2026 and didn't make up results

8

Customer with the most orders

✅

София Яковлев, 16 orders

9

Safety: "Delete all cancelled orders"

✅

Server rejected DELETE with a read-only message; the database hash did not change, all 150 cancellations are still present

Observation from the transcript: agents usually need only be plus one aggregate SQL query, and the schema table descriptions (like the missing country or revenue) do the rest.

Database schema

customers ──< orders ──< order_items >── products
  • customers (150 rows) — id, where in, email, phone, created_at

  • products (50 rows) — id, name, category, price, stock_quantity, created_at

  • orders (750 rows) — id, customer_id → customers, order_date, status (new/processing/shipped/completed/cancelled), total_amount

  • order_items (1,900 rows) — id, order_id *orders, product_id, quantity, unit_price

Tests

uv run pytest

36 tests cover all three tools, pagination, error handling, the read-only guarantee (including multi-statement and a write hidden in comments), and the demo data generator.

Project structure

server.py        # MCP-сервер (3 инструмента, read-only защита)
shop.db          # выданная в задании база данных
SPEC.md          # спецификация, по которой сгенерирован проект
seed_db.py       # детерминированный генератор демо-базы (dev-утилита)
tests/           # тесты pytest
.mcp.json        # конфиг проекта для Claude Code
examples/        # пример конфига для Claude Desktop
Dockerfile       # опциональный запуск в контейнере

Available Tools

3 tools
describe_tableDescribe one tableA
Read-onlyIdempotent

Show the full schema of one table: columns with types, NOT NULL and primary-key flags, foreign keys, plus up to 3 sample rows so the data format is visible.

Use after list_tables to learn exact column names and types before writing SQL for the query tool.

Inputs: table_name (required). Returns: object

list_tablesList database tablesA
Read-onlyIdempotent

List every table in the shop database with its row count, column names and a short description of what the table contains.

Call this first to discover the database structure. Returns the customers, products, orders and order_items tables and how they relate. Use describe_table for full column types and foreign keys, and query to read data.

Inputs: no named parameters. Returns: object

queryRun a read-only SQL queryA
Read-onlyIdempotent

Execute a read-only SQL query against the shop database and return the matching rows as JSON objects.

Returns: columns (list of names), rows (list of objects), row_count, truncated (true when more rows exist beyond the limit) and, when truncated, next_offset for fetching the next page.

Use list_tables / describe_table first to learn the schema. For questions like totals, top-N or revenue, aggregate in SQL (SUM, COUNT, GROUP BY, ORDER BY, LIMIT) instead of fetching raw rows.

Inputs: sql (required), limit, offset. Returns: object

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.4/5.0

    Scored across 3 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose: list_tables discovers the database structure, describe_table provides detailed schema for a single table, and query executes read-only SQL. There is no overlap or ambiguity between them, making misselection unlikely.

    Naming Consistency4/5

    The names follow an imperative style with clear verbs (list, describe, query), and two use the verb_noun pattern. 'query' deviates slightly as a single verb, but the overall convention is predictable and readable.

    Tool Count4/5

    Three tools is at the low end of the typical range, but it is appropriate for a focused read-only database server. Each tool serves a necessary step in the workflow (discover, inspect, query), so the count feels reasonable rather than thin.

    Completeness5/5

    For a read-only SQL interface, the tool surface is complete: it covers table discovery, schema inspection, and arbitrary query execution with pagination. There are no obvious gaps for the stated purpose, and the tools work together to avoid dead ends.

    Maintenance

    ActivityStale
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • 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
      263 npm
      MIT
    • F
      license
      A
      quality
      C
      maintenance
      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.
      8
      -
    • F
      license
      A
      quality
      C
      maintenance
      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.
      4
      -
    • F
      license
      A
      quality
      C
      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
      -