Skip to main content
Glama
Shop Analytics MCP Server

Shop Analytics MCP Server

by bogdaamn

Shop Analytics MCP Server

Ein schreibgeschützter MCP-Server über stdio, der es einem KI-Agenten ermöglicht, analytische Fragen zur SQLite-Datenbank eines Online-Shops (customers, products, orders, order_items) zu beantworten — ohne sie jemals verändern zu können.

Siehe SPEC.md für die vollständige Begründung des Designs (Entscheidungsprotokoll, Schema, Sicherheitsmodell, Teststrategie).

Anforderungen

  • Node.js >= 24.10.0 (erforderlich für setAuthorizer von node:sqlite, das von der unten beschriebenen Schreibschutz-Garantie verwendet wird). Prüfe das mit node --version.

  • Keine weiteren Laufzeitabhängigkeiten über das hinaus, was npm ci installiert.

Related MCP server: Read-Only SQLite Shop Database MCP Server

Installieren → Konfigurieren → Ausführen → Verbinden

npm ci
npm run build
SHOP_DB_PATH=./shop.db npm start
  • shop.db ist in diesem Repository einsatzbereit enthalten. Falls du die Datenbank einmal deterministisch aus dem Schema neu erzeugen musst, führe npm run seed aus (siehe Datenbank unten).

  • SHOP_DB_PATH ist optional; standardmäßig wird shop.db im aktuellen Arbeitsverzeichnis verwendet. Im Quellcode ist kein absoluter Pfad hartkodiert.

  • Der Server spricht MCP ausschließlich über stdio — es gibt keinen HTTP-Server und nichts anderes zu starten.

Einen KI-Agenten verbinden

Konfigurationsbeispiele für zwei Clients findest du in config/:

  • config/claude-code.mcp.json — in die .mcp.json eines Projekts kopieren oder claude mcp add-json mit dem shop-analytics-Eintrag ausführen. Trage zuerst die absoluten Pfade für args/env ein.

  • config/codex.mcp.toml — die Tabelle [mcp_servers.shop-analytics] in ~/.codex/config.toml kopieren (oder in ein projektspezifisches .codex/config.toml) oder den Befehl codex mcp add aus dem Datei-Kopfkommentar verwenden.

Um den Server manuell ohne einen bestimmten Agenten auszuprobieren, verwende den tool-agnostischen MCP Inspector:

SHOP_DB_PATH=$(pwd)/shop.db npx @modelcontextprotocol/inspector node dist/src/index.js

Tools

Der Server stellt genau 8 spezialisierte, schreibgeschützte Tools bereit — kein Tool akzeptiert oder führt beliebiges SQL aus. Jede erfolgreiche Antwort hat die Form { "data": [...], "meta": {...} }; jeder Fehler ist eine einfache, sichere, für Menschen lesbare Nachricht (kein SQL, keine Dateipfade oder Stack-Traces), gekennzeichnet mit isError: true.

Tool

Antworten

Wichtige Parameter

get_database_schema

„Zeig mir alle Tabellen und was sie enthalten."

(keine)

get_customers_by_country

"Wie viele Kunden kommen aus Deutschland?"

country (erforderlich)

get_top_countries_by_customers

"Welches Land hat die meisten Kunden?"

limit (Standard: 1)

get_top_customers_by_spend

"Wer hat am meisten ausgegeben?"

limit, from, to

get_top_selling_products

"Was sind die 5 meistverkauften Produkte?"

limit (Standard: 5), from, to

get_top_categories_by_revenue

"Was sind die 3 umsatzstärksten Kategorien?"

limit (Standard: 3), from, to

get_revenue_for_period

"Wie viel Umsatz haben wir in 2025 erzielt?"

from, to

get_top_customers_by_orders

"Welcher Kunde hat die meisten Bestellungen aufgegeben?"

limit, from, to

from/to sind YYYY-MM-DD und definieren ein halboffenes UTC-Intervall [from, to); from muss strikt früher als to sein. Alle Finanz- und Zählkennzahlen schließen Bestellungen mit Status cancelled aus. Die vollständigen Verträge der einzelnen Tools (exakte Antwortstrukturen, Rangfolgeregeln) findest du in SPEC.md §4.

Sicherheit

Drei unabhängige, mehrstufig ineinsgreifende Schutzschichten garantieren, dass die Datenbank nie verändert wird, selbst bei einem feindseligen Prompt wie "Alle stornierten Bestellungen löschen":

  1. Die SQLite-Verbindung wird mit readOnly: true geöffnet.

  2. Direkt nach dem Öffnen wird PRAGMA query_only = ON gesetzt.

  3. Ein SQLite-authorizer verweigert ausdrücklich jede Schreib-/DDL-Aktion (INSERT, UPDATE, DELETE, DROP, ALTER, CREATE, ATTACH, DETACH, Transaktionen, ...).

Darüber hinaus akzeptiert kein Tool rohes SQL, Tabellennnamen oder Spaltennamen — jede Abfrage ist ein festes Prepared Statement und jede Eingabe wird mit zod validisiert und als gebundener Parameter übergeben, niemals per String-Interpolation.

Datenbank

shop.db wird aus database/schema.sql von einem deterministischen Seed-Skript erzeugt — eine neue Ausführung erzeugt jedes Mal byte-identische Daten (fester PRNG-Seed, keine Abhängigkeit von der echten Uhrzeit):

npm run seed   # builds, then (re)writes ./shop.db from schema.sql + the seed script

Das Seed-Skript stellt bei der Generierung außerdem sicher, dass der Datensatz keine mehrdeutigen Ranglisten enthält (z. B. ein einzelnes Top-Land, einen einzelnen Top-Ausgeber) und einen von null verschiedenen Umsatz für 2025 aufweist — siehe SPEC.md §3.

Entwicklung

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

Dieses Projekt wurde mit TDD entwickelt: Für jedes Modul wurde zuerst ein fehlschlagender Test geschrieben, dann die Implementierung, Tool für Tool. Die Integrationssuite deckt alle 8 Akzeptanzszenarien Ende-zu-Ende ab, dazu Eingaben mit SQL-Injection-Optik, ungültige Parameterkombinationen und verifiziert, dass der SHA-256-Hash der Datenbankdatei nach jedem Lauf unverändert bleibt.

Projektstruktur

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)

Available Tools

8 tools
get_customers_by_countryGet customer count for a countryA

Returns how many customers are registered in a given country (case-insensitive match, e.g. 'germany' matches 'Germany'). An unknown country is a successful result with count 0, not an error. Use this to answer questions like 'how many customers are from Germany?'.

Inputs: country (required).

get_database_schemaGet database schemaA

Lists every business table (customers, products, orders, order_items), their columns (name, SQLite type, nullability, primary key) and foreign key relationships. Use this first to understand what data is available before calling the other tools. Takes no parameters.

Inputs: no named parameters.

get_revenue_for_periodGet total revenue for a periodA

Sums revenue (quantity * unit_price) across all orders in the requested period, or the whole dataset if no bounds are given. Orders with status 'cancelled' are always excluded from this metric. A period with no matching orders is a successful zero-revenue result, not an error. Optional half-open UTC interval [from, to). Both are 'YYYY-MM-DD'. Omitting a bound leaves that side open (e.g. only 'to' means "everything before to"). 'from' must be strictly earlier than 'to' or the call is rejected. Use this to answer 'how much revenue did we generate in 2025?' (pass from='2025-01-01', to='2026-01-01').

Inputs: to, from.

get_top_categories_by_revenueGet top product categories by revenueA

Ranks product categories by revenue (sum of quantity * unit_price for their products), descending (ties broken by category name ascending). Orders with status 'cancelled' are always excluded from this metric. Defaults to the top 3 categories. Optional half-open UTC interval [from, to). Both are 'YYYY-MM-DD'. Omitting a bound leaves that side open (e.g. only 'to' means "everything before to"). 'from' must be strictly earlier than 'to' or the call is rejected. Use this to answer 'what are the top 3 product categories by revenue?'.

Inputs: to, from, limit.

get_top_countries_by_customersGet top countries by customer countA

Ranks countries by number of registered customers, descending (ties broken by country name ascending). Defaults to the single top country; pass a higher 'limit' for a top-N leaderboard. Use this to answer 'which country has the most customers?'.

Inputs: limit.

get_top_customers_by_ordersGet top customers by number of ordersA

Ranks customers by how many orders they placed, descending (ties broken by customer id ascending). Orders with status 'cancelled' are always excluded from this metric. Defaults to the single top customer; pass a higher 'limit' for a top-N leaderboard. Optional half-open UTC interval [from, to). Both are 'YYYY-MM-DD'. Omitting a bound leaves that side open (e.g. only 'to' means "everything before to"). 'from' must be strictly earlier than 'to' or the call is rejected. Use this to answer 'which customer placed the most orders?'.

Inputs: to, from, limit.

get_top_customers_by_spendGet top customers by total spendA

Ranks customers by total money spent (sum of quantity * unit_price across their orders), descending. Orders with status 'cancelled' are always excluded from this metric. Ties broken by customer id ascending. Defaults to the single top spender; pass a higher 'limit' for a top-N leaderboard. Optional half-open UTC interval [from, to). Both are 'YYYY-MM-DD'. Omitting a bound leaves that side open (e.g. only 'to' means "everything before to"). 'from' must be strictly earlier than 'to' or the call is rejected. Use this to answer 'who is the customer who spent the most money?'.

Inputs: to, from, limit.

get_top_selling_productsGet top-selling productsA

Ranks products by units sold, descending (ties broken by revenue descending, then product id ascending). Orders with status 'cancelled' are always excluded from this metric. Defaults to the top 5 products. Optional half-open UTC interval [from, to). Both are 'YYYY-MM-DD'. Omitting a bound leaves that side open (e.g. only 'to' means "everything before to"). 'from' must be strictly earlier than 'to' or the call is rejected. Use this to answer 'what are the top 5 best-selling products?'.

Inputs: to, from, limit.

Tool Schema Changelog

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

Loading tool schema changelog…

    TDQS

    A4.7/5.0

    Scored across 8 tools

    Disambiguation5/5

    Each tool targets a distinct analytics query—schema, country customer counts, leaderboards for customers, products, categories, and revenue periods. There is no overlap; an agent can unambiguously pick the right tool for a given question.

    Naming Consistency5/5

    All tool names follow the same pattern: 'get_' followed by a descriptive phrase in snake_case (e.g., get_top_selling_products, get_revenue_for_period). The naming is perfectly consistent and immediately conveys the operation and focus.

    Tool Count5/5

    With 8 tools, the server is well-scoped for a shop analytics domain. Each tool covers a distinct business question without redundancy, and the count is in the ideal range for usability and clarity.

    Completeness4/5

    The set covers core analytics needs: customer demographics, top customers by spend and orders, top products and categories, revenue totals, and schema discovery. Minor gaps exist (e.g., no per-product revenue breakdown or filtering by specific customers), but the surface is largely complete for typical analytics queries.

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      A
      quality
      D
      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
      -
    • F
      license
      A
      quality
      D
      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
      D
      maintenance
      Enables AI agents to read-only query an online store's SQLite database, listing tables, inspecting schemas, and running SELECT queries over customers, products, orders, and order items.
      3
      -
    • F
      license
      A
      quality
      D
      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
      -