E-Commerce MCP Server
Enables AI assistants to manage products, shopping carts, and orders in an online store through a well-defined MCP API.
README
E-Commerce MCP Server
A complete Model Context Protocol (MCP) server for e-commerce operations, enabling AI assistants to interact with your online store through a well-defined API.
Features
This MCP server provides comprehensive e-commerce functionality:
Product Management
- 📋 List all products or filter by category
- 🔍 Search products by name or description
- 📦 Get detailed product information
Shopping Cart
- 🛒 Create and manage shopping carts
- ➕ Add items to cart with quantity control
- ➖ Remove items from cart
- ✏️ Update item quantities
- 👁️ View cart contents and totals
Order Management
- 💳 Complete checkout with shipping and payment details
- 📝 Create orders from carts
- 📊 View order details and history
- 📋 List all orders
Installation
- Install dependencies:
npm install
- Build the server:
npm run build
- Run the server:
# For HTTP server (default, accessible via URL)
npm start
# Or explicitly set transport
TRANSPORT=http npm start
# For stdio (local use)
TRANSPORT=stdio npm start
Usage
Running as HTTP Server (Recommended)
The server runs on HTTP by default, making it accessible via URL at http://localhost:3000/mcp.
npm start
This allows others to connect to your MCP server using the URL:
- Claude Desktop can add it via MCP settings
- Other tools can connect using the endpoint URL
Testing the Server
Check if server is running:
curl http://localhost:3000/health
Configure in Claude Desktop
Add to your Claude Desktop configuration (claude_desktop_config.json):
{
"mcpServers": {
"ecommerce": {
"url": "http://localhost:3000/mcp"
}
}
}
Or if running remotely:
{
"mcpServers": {
"ecommerce": {
"url": "https://your-server.com/mcp"
}
}
}
Available Tools
1. ecommerce_list_products
List all products in the store, optionally filtered by category.
Parameters:
category(optional): Filter by category nameresponse_format: 'markdown' or 'json'
2. ecommerce_search_products
Search for products by name or description.
Parameters:
query: Search termcategory(optional): Filter by categoryresponse_format: 'markdown' or 'json'
3. ecommerce_get_product
Get detailed information about a specific product.
Parameters:
product_id: Unique product identifierresponse_format: 'markdown' or 'json'
4. ecommerce_create_cart
Create a new shopping cart.
Parameters:
response_format: 'markdown' or 'json'
Returns: Cart ID for future operations
5. ecommerce_get_cart
View the contents of a shopping cart.
Parameters:
cart_id: Unique cart identifierresponse_format: 'markdown' or 'json'
6. ecommerce_add_to_cart
Add a product to the shopping cart.
Parameters:
cart_id: Cart identifierproduct_id: Product to addquantity: Number of items (default: 1)response_format: 'markdown' or 'json'
7. ecommerce_remove_from_cart
Remove a product from the cart.
Parameters:
cart_id: Cart identifierproduct_id: Product to removeresponse_format: 'markdown' or 'json'
8. ecommerce_update_cart_item
Update the quantity of an item in the cart.
Parameters:
cart_id: Cart identifierproduct_id: Product to updatequantity: New quantityresponse_format: 'markdown' or 'json'
9. ecommerce_create_order
Complete checkout and create an order.
Parameters:
cart_id: Cart to checkoutshipping_address: Object with delivery detailsfull_name: Customer nameaddress_line1: Street addressaddress_line2: Apartment, suite, etc. (optional)city: City namestate: State/Provincepostal_code: ZIP/Postal codecountry: Country codephone: Contact number
payment_details: Object with payment infomethod: 'credit_card', 'debit_card', 'paypal', or 'bank_transfer'card_last4: Last 4 digits (optional)card_brand: Card brand (optional)transaction_id: Payment transaction ID (optional)
response_format: 'markdown' or 'json'
10. ecommerce_get_order
Get details of a specific order.
Parameters:
order_id: Unique order identifierresponse_format: 'markdown' or 'json'
11. ecommerce_list_orders
List all orders in the system.
Parameters:
response_format: 'markdown' or 'json'
Example Workflow
Here's a typical customer journey:
// 1. Browse products
ecommerce_list_products({ category: "Electronics" })
// 2. View product details
ecommerce_get_product({ product_id: "prod_001" })
// 3. Create a cart
ecommerce_create_cart({})
// Returns: { id: "cart_xxx", ... }
// 4. Add items to cart
ecommerce_add_to_cart({
cart_id: "cart_xxx",
product_id: "prod_001",
quantity: 2
})
// 5. View cart
ecommerce_get_cart({ cart_id: "cart_xxx" })
// 6. Complete checkout
ecommerce_create_order({
cart_id: "cart_xxx",
shipping_address: {
full_name: "John Doe",
address_line1: "123 Main St",
city: "New York",
state: "NY",
postal_code: "10001",
country: "US",
phone: "+1234567890"
},
payment_details: {
method: "credit_card",
card_last4: "4242",
card_brand: "Visa"
}
})
// 7. Check order status
ecommerce_get_order({ order_id: "order_xxx" })
Sample Products
The server comes pre-loaded with sample products:
- Wireless Headphones (prod_001) - $299.99
- Smart Watch (prod_002) - $399.99
- Laptop Backpack (prod_003) - $79.99
- Bluetooth Speaker (prod_004) - $149.99
- Ergonomic Mouse (prod_005) - $59.99
Customization
Adding Real Database Support
Replace the mock database in src/database.ts with your actual database:
// Example with PostgreSQL
import { Pool } from 'pg';
const pool = new Pool({
connectionString: process.env.DATABASE_URL
});
export async function getAllProducts(): Promise<Product[]> {
const result = await pool.query('SELECT * FROM products');
return result.rows;
}
Adding Authentication
Add authentication middleware to your HTTP server:
app.use((req, res, next) => {
const apiKey = req.headers['x-api-key'];
if (!apiKey || !isValidApiKey(apiKey)) {
return res.status(401).json({ error: 'Unauthorized' });
}
next();
});
Deploying to Production
- Environment Variables: Set
PORTfor the HTTP server - HTTPS: Use a reverse proxy (nginx, Caddy) for SSL
- Database: Connect to your production database
- Monitoring: Add logging and error tracking
Example deployment with environment variables:
PORT=8080 DATABASE_URL=postgres://... npm start
Architecture
ecommerce-mcp-server/
├── src/
│ ├── index.ts # Main MCP server with tool registrations
│ ├── types.ts # TypeScript interfaces
│ └── database.ts # Data layer (mock or real DB)
├── dist/ # Compiled JavaScript
├── package.json
├── tsconfig.json
└── README.md
Development
Build and run in dev mode:
npm run dev
Just build:
npm run build
MCP Protocol
This server implements the Model Context Protocol (MCP), which allows AI assistants to:
- Discover available tools through the protocol
- Call tools with validated parameters
- Receive structured responses
- Handle errors gracefully
All tools include:
- ✅ Input validation with Zod schemas
- 📝 Comprehensive descriptions
- 🏷️ Proper annotations (readOnly, destructive, idempotent)
- 🔄 Structured responses in both JSON and Markdown formats
License
MIT
Support
For issues or questions about this MCP server:
- Check the MCP documentation: https://modelcontextprotocol.io
- Review the tool descriptions in the code
- Test with the health endpoint:
/health
Contributing
To add new features:
- Define types in
src/types.ts - Implement data layer in
src/database.ts - Register new tools in
src/index.tsfollowing existing patterns - Update this README with the new functionality
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。