Skip to main content
Glama
Krishcode264

CommerceOps MCP Server

by Krishcode264

๐Ÿ›’ CommerceOps MCP Server โ€” AI-First Commerce Operations Server

An AI-native, production-grade Model Context Protocol (MCP) server written in TypeScript, designed to enable AI Operations Agents to autonomously investigate and resolve complex e-commerce operational exceptions (stuck orders, missed payment webhooks, warehouse fulfillment delays, and oversold inventory).


๐ŸŽฏ Key Architectural Pillars

  1. Raw Operational Signals (No Pre-Baked Diagnostic Labels): Seed orders store only realistic backend fields (order_status, payment, inventory, fulfillment). diagnose() computes root-cause explanations and evidence dynamically at runtime.

  2. Strict Bounded Action Enum & Safety Policy: All state mutations are restricted to a closed enum of actions (refund_duplicate_charge, requeue_to_warehouse, release_reserved_stock, resync_shipping_address). Every resolution call structurally enforces a pre-execution safety check (evaluate_safety).

  3. Universal Risk-Score Pre-Gate & Central Policy Config:

    • Payment Risk Gate: Orders with risk_score > 60 are blocked and escalated immediately.

    • Autonomous Refund Cap: Auto-refunds capped at โ‚น1,000 INR. Over-limit refunds are escalated.

    • Fulfillment Staleness Threshold: Warehouse requeue requires days_since_last_update >= 3.

    • Oversold Stock Protection: Stock release blocked if stock_on_hand === 0.

  4. Neon PostgreSQL Database & Dual Store Architecture:

    • Cloud Persistence: Uses @neondatabase/serverless to store all 6 normalized order tables, audit_log, and order_analysis_log in a Neon DB instance when DATABASE_URL is set.

    • Local Dev Fallback: Gracefully falls back to an in-memory store when running locally without a database connection.

  5. Durable Auditing & Order Analysis Activity Logging:

    • Audit Log: Durably records every resolution attempt (executed vs escalated), policy reason, and actor.

    • Analysis Log: Records diagnostic runs, evidence snapshots, and safety check evaluations for full operational auditability.

    • Exposed via MCP resources (commerce://audit/log, commerce://analysis/log) and REST API (/api/audit, /api/analysis).


Related MCP server: commercetools MCP Essentials

๐Ÿ—๏ธ Technical Architecture Diagram

+-----------------------------------------------------------------------------------+
|                            MCP AI CONSUMER CLIENT                                 |
|            (Claude Desktop / Cursor / Custom Agent / Antigravity IDE)             |
+-----------------------------------------------------------------------------------+
                                         โ”‚
                   Remote SSE (/sse) OR Stdio Transport (--stdio)
                                         โ–ผ
+-----------------------------------------------------------------------------------+
|                           COMMERCE OPS MCP SERVER                                 |
|                                                                                   |
|  +------------------------+  +------------------------+  +---------------------+  |
|  |     BOUNDED TOOLS      |  |     MCP RESOURCES      |  |     MCP PROMPTS     |  |
|  | - list_orders          |  | - orders/seed          |  | - investigate_stuck |  |
|  | - search_orders        |  | - audit/log            |  +---------------------+  |
|  | - diagnose             |  | - analysis/log         |                           |
|  | - evaluate_safety      |  +------------------------+                           |
|  | - execute_resolution   |                                                       |
|  +------------------------+                                                       |
|                                        โ”‚                                          |
|                                        โ–ผ                                          |
|                  +------------------------------------------+                     |
|                  |     SAFETY & ESCALATION POLICY ENGINE    |                     |
|                  | - MAX_AUTO_REFUND_LIMIT_INR (โ‚น1,000)     |                     |
|                  | - Risk Gate (risk_score <= 60)          |                     |
|                  | - Staleness Threshold (3 days)           |                     |
|                  +------------------------------------------+                     |
|                                        โ”‚                                          |
|                                        โ–ผ                                          |
|                  +------------------------------------------+                     |
|                  |      COMMERCE STORE & DATA ENGINE        |                     |
|                  |   (OMS, WMS, Payment Gateway, Audit Log) |                     |
|                  +------------------------------------------+                     |
|                                        โ”‚                                          |
|                                        โ–ผ                                          |
|                  +------------------------------------------+                     |
|                  |     DURABLE FILE & NEON DB PERSISTENCE   |                     |
|                  |         (./data/audit_log.json)          |                     |
|                  +------------------------------------------+                     |
+-----------------------------------------------------------------------------------+

๐Ÿ“Š Seed Dataset & Policy Matrix (6 Core Scenarios)

Order ID

Customer

Amount

Raw Signals

Diagnostic Root Cause

Policy / Safety Evaluation

Expected Outcome

ORD-1001

Aarav Sharma

โ‚น300

captured, pending, webhook: false, risk: 10

Missed gateway webhook

Amount โ‚น300 <= โ‚น1,000 cap

EXECUTED: Refund โ‚น300 recorded

ORD-1002

Priya Patel

โ‚น4,999

reserved, picked: false, stale: 4 days

Fulfillment stalled at warehouse

Stale 4 days >= 3 threshold

EXECUTED: Requeued for picking

ORD-1003

Vikramaditya Roy

โ‚น4,000

status: refund_requested, risk: 20

Refund requested above cap

Amount โ‚น4,000 > โ‚น1,000 cap

ESCALATED: Requires supervisor approval

ORD-1004

Sneha Kulkarni

โ‚น12,999

captured, reserved, stock_on_hand: 0

Inventory oversold (flash-sale)

Stock on hand is 0

ESCALATED: Requires procurement review

ORD-1005

Rohan Verma

โ‚น1,499

captured, picked: true, stock_on_hand: 31

No issue found (control case)

N/A (normal processing)

NO ACTION: Progressing normally

ORD-1006

Meera Nair

โ‚น500

captured, pending, webhook: false, risk: 85

Missed gateway webhook

Risk score 85 > 60 threshold

ESCALATED: Blocked by Fraud Risk Gate


๐Ÿ› ๏ธ MCP Tools, Resources & Prompts

1. Bounded MCP Tools (src/mcp/tools.ts)

Tool Name

Description

Key Arguments

list_orders

Returns triage-level list of orders with computed flagged_for_review boolean.

status (optional filter)

search_orders

Returns full raw order record (nested payment, inventory, fulfillment, items).

order_id (required), status, customer

diagnose

Computes root-cause reasoning, evidence snapshot, and recommended action.

order_id (required)

evaluate_safety

Pre-execution safety check against centralized policy thresholds.

order_id (required), action (required)

execute_resolution

Executes bounded action after safety check. Writes to audit & analysis logs.

order_id (required), action (required), actor

reset_store_to_defaults

TRUNCATEs DB/memory store and re-seeds original 6 seed orders.

None

2. MCP Resources (src/mcp/resources.ts)

  • commerce://orders/seed: Live JSON list of all seed orders.

  • commerce://audit/log: Immutable audit log of all resolution attempts (executed / escalated).

  • commerce://analysis/log: Full agent activity trace (diagnostic runs, evidence, safety evaluations).

3. MCP Prompts (src/mcp/prompts.ts)

  • investigate_stuck_order: Step-by-step guided prompt instructing an AI Operations Agent to search order, run diagnosis, evaluate safety guardrails, execute resolution, and draft transparent customer updates.


๐Ÿš€ Deployment & Environment Setup

1. Environment Variables (.env)

Copy .env.example to .env:

DATABASE_URL=postgresql://neondb_owner:password@ep-host.aws.neon.tech/neondb?sslmode=require
PORT=3000

2. Build & Run locally

# Install dependencies
npm install

# Build TypeScript to dist/
npm run build

# Start production SSE server
npm start

3. Deploying to Render

  • Environment: Node.js Web Service

  • Build Command: npm run build

  • Start Command: npm start

  • Environment Variables: Add DATABASE_URL pointing to your Neon database URL.


๐Ÿงช Testing & MCP Inspector CLI Verification

Run Unit Test Suite (Vitest)

npm test

Output:

 โœ“ tests/workflow.test.ts (1 test)
 โœ“ tests/guardrails.test.ts (6 tests)
 โœ“ tests/mcp-tools.test.ts (5 tests)

 Test Files  3 passed (3)
      Tests  12 passed (12)

Test via MCP Inspector CLI (dist/stdio.js)

# 1. Test ORD-1006 risk score escalation
npx @modelcontextprotocol/inspector --cli node dist/stdio.js \
  --method tools/call --tool-name execute_resolution \
  --tool-arg order_id=ORD-1006 --tool-arg action=refund_duplicate_charge

# 2. Test ORD-1001 auto-refund execution
npx @modelcontextprotocol/inspector --cli node dist/stdio.js \
  --method tools/call --tool-name execute_resolution \
  --tool-arg order_id=ORD-1001 --tool-arg action=refund_duplicate_charge

# 3. Read Analysis Activity Logs Resource
npx @modelcontextprotocol/inspector --cli node dist/stdio.js \
  --method resources/read --uri commerce://analysis/log

๐Ÿ“ Repository Structure

commerce-ops-mcp/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ index.ts                # Remote SSE/HTTP Express Server (/sse, /message, /health, /api/*)
โ”‚   โ”œโ”€โ”€ stdio.ts                # Stdio Entrypoint for local MCP Inspector testing
โ”‚   โ”œโ”€โ”€ server.ts               # MCP Server instantiation & tool/resource registration
โ”‚   โ”œโ”€โ”€ chat.ts                 # Interactive Ops AI Chat handler
โ”‚   โ”œโ”€โ”€ config.ts               # Centralized Policy Config thresholds (caps, risk limit, staleness)
โ”‚   โ”œโ”€โ”€ db/
โ”‚   โ”‚   โ””โ”€โ”€ client.ts           # Singleton Neon Serverless PostgreSQL SQL client
โ”‚   โ”œโ”€โ”€ domain/
โ”‚   โ”‚   โ”œโ”€โ”€ types.ts            # Core Interfaces (Order, Payment, Inventory, AuditLog, AnalysisLog)
โ”‚   โ”‚   โ”œโ”€โ”€ mockData.ts         # Raw 6 Seed Orders (no diagnostic labels)
โ”‚   โ”‚   โ”œโ”€โ”€ store.ts            # In-Memory Store Implementation (ICommerceStore)
โ”‚   โ”‚   โ””โ”€โ”€ dbStore.ts          # Neon PostgreSQL Store Implementation (DatabaseCommerceStore)
โ”‚   โ””โ”€โ”€ mcp/
โ”‚       โ”œโ”€โ”€ tools.ts            # 5 Bounded MCP Tools + reset tool
โ”‚       โ”œโ”€โ”€ resources.ts        # MCP Resources (orders, audit log, analysis activity log)
โ”‚       โ”œโ”€โ”€ prompts.ts          # MCP Prompts (guided investigation workflow)
โ”‚       โ””โ”€โ”€ guardrails.ts       # Safety Guardrail Engine wrapper
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ guardrails.test.ts      # Policy thresholds & Risk-score pre-gate tests
โ”‚   โ”œโ”€โ”€ mcp-tools.test.ts       # Bounded tool execution & audit log tests
โ”‚   โ””โ”€โ”€ workflow.test.ts        # Full 6-seed scenario integration tests
โ”œโ”€โ”€ .env.example                # Template environment file
โ”œโ”€โ”€ .gitignore                  # Git ignore rules (.env, dist/, node_modules/, draft files)
โ”œโ”€โ”€ AI_WORKLOG.md               # AI Worklog, Prompts & Correction Audit
โ”œโ”€โ”€ package.json
โ””โ”€โ”€ tsconfig.json
F
license - not found
-
quality - not tested
C
maintenance

Maintenance

โ€“Maintainers
โ€“Response time
โ€“Release cycle
โ€“Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

View all related MCP servers

Related MCP Connectors

  • MCP server for AI agents to plan, verify, and deploy Cloudflare-native apps.

  • Hosted Amazon Seller and Vendor MCP server for Claude, ChatGPT, Cursor, Codex, Gemini, Copilot.

  • Hosted Amazon Seller Central and Amazon Ads MCP server for Claude, ChatGPT, Cursor, and agents.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Krishcode264/commerce-ops-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server