Stalled Fulfillment Recovery MCP Server

Stalled Fulfillment Recovery MCP Server

An MCP server that enables operations teams to diagnose and recover stalled fulfillment orders via tools like retry_fulfillment and escalate_order, with safety boundaries limiting writes to retry and audit operations.

Category
访问服务器

README

Stalled Fulfillment Recovery — MCP Server

An MCP server that lets ops (via an AI assistant) diagnose and recover orders stuck in "processing" due to missing or failed fulfillment tasks.

Safety by construction: the only write tools are retry_fulfillment (resets a fulfillment task) and escalate_order (writes an audit entry). There are no payment mutation tools — the domain boundary is the safety boundary.

Product Decisions & Assumptions

Problem: Operations teams can't independently diagnose or fix stalled fulfillment issues — they lack cross-system visibility and safe write access, so even routine cases get escalated to engineers.

Scope: Single-order investigation of stalled fulfillment. We handle three known stall patterns (no fulfillment task, failed task, silently stalled task). Genuinely novel or ambiguous failures escalate to humans via escalate_order.

Assumptions:

  • User interacts via an MCP-connected AI client (e.g. Claude Desktop) — no custom frontend
  • Writes are simulated (no real warehouse/carrier API) but safety boundaries (dry-run, rate-limit, escalation) are real
  • Single-order investigation, not batch operations

Exclusions: Authentication, multi-tenant access control, payment mutations, real carrier integrations, batch operations, frontend.

Database Setup (PostgreSQL)

This server uses PostgreSQL for persistent data storage. Tables are auto-created on startup.

# Environment Variable (optional, defaults to postgres://localhost:5432/fulfillment_mcp)
export DATABASE_URL="postgres://username:password@localhost:5432/fulfillment_mcp"

Quick Start

npm install
npm run build && npm start   # production on :3000
# or
npm run dev                  # dev server on :3000

Health check:

curl http://localhost:3000/health

MCP Inspector:

npx @modelcontextprotocol/inspector --url http://localhost:3000/mcp

MCP Capabilities

Tools

Tool Type Description
get_order Read Fetches an order + its fulfillment task in one call
get_fulfillment Read Fetches a fulfillment task by ID with full failure detail
list_stalled_orders Read Surfaces all orders stuck in processing (3 stall types) via optimized SQL JOIN
retry_fulfillment Write Resets a stalled fulfillment to pending. Always dry-run first
escalate_order Write (audit only) Flags an order for human review without mutating state
get_audit_log Read Returns the full action history for an order

Resources

Resource URI Description
order://{order_id} Direct JSON access to an order and its fulfillment task
fulfillment://{order_id} Direct JSON access to a fulfillment task by order ID

Prompts

Prompt Description
diagnose_stalled_orders Guided workflow that instructs the AI to discover stalled orders, inspect each, decide retry vs escalate, and summarize actions. Accepts optional threshold_hours parameter.

Stall Detection

list_stalled_orders detects three types of stall for any paid/processing order older than threshold_hours (default: 24h), using a single optimized SQL LEFT JOIN query:

stall_reason Condition
no_fulfillment_task No FulfillmentTask row was ever created
fulfillment_failed FulfillmentTask.status === "failed"
fulfillment_stalled Task is pending/in_progress but lastActivityAt is older than the threshold

Example Workflow

Ops: "Show me all stuck orders"

AI: → list_stalled_orders(threshold_hours: 24)
    ← 3 stalled orders found

AI: → get_order("ORD-1042")
    ← Order: processing, Fulfillment: failed (warehouse_api_timeout, 2 attempts)

AI: → retry_fulfillment("ORD-1042", confirm=false)
    ← dry_run: will reset FUL-1042 to pending (attempt 3)

Ops: "Looks good, go ahead."

AI: → retry_fulfillment("ORD-1042", confirm=true)
    ← success: fulfillment reset, audit entry created

AI: → get_audit_log("ORD-1042")
    ← [fulfillment_retry @ 2026-08-01T04:15:00Z]

Safety Details

  • Dry-run required: retry_fulfillment returns a preview when confirm=false without mutating anything. Show this to the operator before confirming.
  • Rate-limit: A second retry on the same order within 10 minutes is rejected with double_retry_prevented. This is a rate-limit (time window), not true idempotency — a second retry after the cooldown is permitted, because the first may itself have failed.
  • Escalation path: When an order doesn't match the standard stall pattern, use escalate_order to write a permanent audit entry recording why the AI declined to act automatically.
  • No payment tools: There is no refund or payment write tool in this MCP. The scope boundary enforces the safety boundary.

Development & Testing

npm run build         # TypeScript compile
npm run test          # Vitest safety tests against live PostgreSQL
npm run test:watch    # Watch mode

Tests run against live PostgreSQL and create their own data at runtime — no hardcoded fixtures or seed data dependencies.

Live Hosted Deployment

The MCP server is live and hosted on Render:

  • Base URL: https://mcp-ecom.onrender.com
  • MCP Endpoint: https://mcp-ecom.onrender.com/mcp
  • Health Check: https://mcp-ecom.onrender.com/health

Connecting in Cursor (~/.cursor/mcp.json)

{
  "mcpServers": {
    "stalled-fulfillment-recovery": {
      "url": "https://mcp-ecom.onrender.com/mcp"
    }
  }
}

Deployment

The server listens on process.env.PORT (default: 3000). Deploy anywhere that runs Node.js and has PostgreSQL access:

  • Railway / Render / Fly.io / Heroku: push the repo, set DATABASE_URL and PORT
  • Docker: node dist/index.js
  • The MCP endpoint is POST /mcp (stateless HTTP, no sessions)

After deploying:

curl https://mcp-ecom.onrender.com/health
npx @modelcontextprotocol/inspector --url https://mcp-ecom.onrender.com/mcp

Tech Stack

  • Database: PostgreSQL (pg driver)
  • MCP SDK: @modelcontextprotocol/sdk ^1.12 (stable)
  • Transport: StreamableHTTPServerTransport (stateless, HTTP)
  • Framework: Express 5
  • Validation: Zod 3
  • Tests: Vitest — focused safety verification against live PostgreSQL
  • Language: TypeScript (ESM, strict)

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选