Commerce Operations MCP Server
Enables AI agents to independently investigate and resolve e-commerce order issues, particularly refund processing, with tools for order search, refund eligibility checks, and safe refund execution.
README
Commerce Operations MCP Server
AI-native solution for commerce operations teams to independently investigate and resolve order issues, particularly refund processing.
Problem Statement
Operations teams in e-commerce businesses frequently depend on engineers to:
- Investigate order issues across multiple systems
- Determine refund eligibility
- Process refunds safely without risking duplicate refunds or fraud
This MCP server makes ops teams more independent by providing AI agents with safe, structured access to commerce operations.
Solution Overview
An MCP server that exposes commerce operations tools for AI agents:
- Order Investigation: Search and retrieve order details
- Refund Eligibility: Check if orders qualify for refunds based on business rules
- Safe Refund Processing: Execute refunds with built-in safety checks
- Audit Trail: Track all refund operations
Architecture
AI Agent (Claude/Gemini)
↓
MCP Protocol (stdio/SSE)
↓
TypeScript MCP Server
↓
SQLite Database (mock commerce data)
Key Design Decisions
MCP as Core Architecture: The MCP server is the primary interface for all operations. It's not a wrapper - it implements:
- Business logic for refund eligibility
- Safety checks and validation
- Audit logging
- Transactional integrity
Tool Design: Five focused tools that map to real operations workflows:
search_orders- Find orders by various criteriaget_order_details- Retrieve complete order informationcheck_refund_eligibility- Validate refund eligibility before processingprocess_refund- Execute refund with safety checksget_refund_history- Audit trail for refunds
Safety First:
- Prevents duplicate refunds
- Validates refund amounts don't exceed order total
- Enforces 90-day refund window
- Requires detailed reasons (audit trail)
- Read-only tools for investigation, single destructive tool with guards
Setup
Prerequisites
- Node.js 18+
- npm or yarn
Installation
npm install
npm run build
Running Locally
npm run dev
The server runs on stdio and communicates via MCP protocol.
Running Tests
npm run build
node dist/test.js
Tests verify:
- Order search and retrieval
- Refund eligibility rules
- Refund processing safety checks
- Multiple partial refunds
- Audit logging
MCP Tools
1. search_orders
Search for orders with filters:
email: Customer emailorderId: Specific order IDstatus: Order status (pending, confirmed, shipped, delivered, cancelled)paymentStatus: Payment status (pending, paid, failed, refunded, partially_refunded)
2. get_order_details
Retrieve complete order information including items, shipping, payment, and refund history.
Input: orderId
3. check_refund_eligibility
Validate if an order qualifies for refund.
Business Rules:
- Payment must be completed (paid status)
- Not already fully refunded
- Within 90 days of purchase
- Returns max refundable amount
Input: orderId
4. process_refund
Execute a refund with safety checks.
Safety Checks:
- Validates eligibility first
- Prevents duplicate full refunds
- Prevents excess refunds
- Requires detailed reason (min 10 characters)
- Creates audit log
Input:
orderId: Order to refundamount: Refund amount (supports partial refunds)reason: Detailed reason for audit trail
5. get_refund_history
Retrieve all refund transactions for an order.
Input: orderId
Example Workflow
Scenario: Customer reports they received a damaged laptop
-
Search for customer orders:
search_orders({ email: "alice@example.com" }) -
Get order details:
get_order_details({ orderId: "ORD-2024-001" }) -
Check refund eligibility:
check_refund_eligibility({ orderId: "ORD-2024-001" }) -
Process refund (if eligible):
process_refund({ orderId: "ORD-2024-001", amount: 1299.99, reason: "Customer received damaged laptop, verified with photos" }) -
Verify refund:
get_refund_history({ orderId: "ORD-2024-001" })
Deployment
Railway Deployment
-
Create Railway project:
railway init -
Add start command to Procfile or use npm start
-
Deploy:
railway up -
Expose via SSE transport for remote access
Environment Variables
For production deployment:
NODE_ENV=productionPORT- Railway will set automatically
Sample Data
The system includes 6 sample orders with various states:
- Delivered paid orders (eligible for refund)
- Already refunded order (not eligible)
- Pending payment order (not eligible)
- Shipped orders
- Various payment methods
Safety Considerations
Implemented
- ✅ No duplicate full refunds
- ✅ Amount validation (positive, <= remaining)
- ✅ Eligibility checks before processing
- ✅ Audit logging for all refunds
- ✅ Transaction atomicity
- ✅ Required refund reasons
Production Requirements (Out of Scope)
- Authentication/authorization
- Rate limiting
- Fraud detection
- Payment gateway integration
- Multi-currency support
- Role-based access control
Assumptions
- Data: Using synthetic SQLite data; real systems would connect to production databases via read replicas
- Payments: Mock refund processing; real systems integrate with Stripe/PayPal/etc.
- Authentication: Assumes trusted environment; production needs auth
- Single-tenant: One database; real system would be multi-tenant
- Business Rules: 90-day refund window is configurable; simplified from real-world policies
Limitations & Future Work
Current Limitations
- No actual payment gateway integration
- No email notifications
- No approval workflows
- Single database (no scaling)
- No fraud detection
Next Steps (Priority Order)
- Add SSE transport for remote hosting
- Implement authentication using API keys or OAuth
- Add approval workflows for refunds over threshold
- Integrate payment gateway (Stripe API)
- Add notification system (email customers)
- Implement rate limiting and fraud detection
- Add analytics tools (refund metrics, trends)
- Multi-tenant support with organization isolation
Trade-offs
Why SQLite? Fast to set up, no external dependencies, perfect for demo. Production would use PostgreSQL with read replicas.
Why stdio transport? Simplest MCP transport for initial development. SSE transport needed for remote hosting.
Why synchronous processing? Simpler to implement and test. Production would use async job queues for refunds.
Why embedded business logic? Keeps MCP server as single source of truth. Alternative would be separate service layer.
Tech Stack
- TypeScript - Type safety and better developer experience
- @modelcontextprotocol/sdk - MCP protocol implementation
- better-sqlite3 - Fast embedded database
- zod - Runtime type validation for tool inputs
- Railway/Render - Hosting platform
License
MIT
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。