import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
const server = new McpServer({
name: "my-store-server",
version: "1.0.0"
});
// ---- Product Search ----
server.tool(
"search_products",
"Search products. Supports keyword and category filtering. Returns product name, price, and stock status.",
{
query: { type: "string", description: "Search keyword" },
category: { type: "string", description: "Category name (optional)" },
minPrice: { type: "number", description: "Minimum price (optional)" },
maxPrice: { type: "number", description: "Maximum price (optional)" },
limit: { type: "number", description: "Number of results, default 10, max 50" }
},
async ({ query, category, minPrice, maxPrice, limit = 10 }) => {
const filters: any = {};
if (category) filters.category = category;
if (minPrice) filters.price = { $gte: minPrice };
if (maxPrice) filters.price = { ...filters.price, $lte: maxPrice };
const results = await db.products.search(query, filters, Math.min(limit, 50));
return {
content: [{
type: "text",
text: JSON.stringify({
results: results.map(p => ({
name: p.name,
sku: p.sku,
price: p.price,
currency: "USD",
inStock: p.inventory > 0,
category: p.category,
url: `https://mystore.com/product/${p.slug}`
})),
total: results.totalCount,
query
}, null, 2)
}]
};
}
);
// ---- Product Details ----
server.tool(
"get_product",
"Get full details for a single product, including description, specifications, ratings, and inventory.",
{
sku: { type: "string", description: "Product SKU code" }
},
async ({ sku }) => {
const product = await db.products.findBySku(sku);
if (!product) {
return {
content: [{ type: "text", text: `SKU not found: ${sku}` }],
isError: true
};
}
return {
content: [{
type: "text",
text: JSON.stringify({
name: product.name,
sku: product.sku,
description: product.description,
price: product.price,
currency: "USD",
brand: product.brand,
category: product.category,
inStock: product.inventory > 0,
inventory: product.inventory,
rating: product.averageRating,
reviewCount: product.reviewCount,
specs: product.specifications,
images: product.images,
url: `https://mystore.com/product/${product.slug}`
}, null, 2)
}]
};
}
);
// ---- Order Query ----
server.tool(
"get_order",
"Query order status and details. Requires order ID.",
{
orderId: { type: "string", description: "Order ID" }
},
async ({ orderId }) => {
const order = await db.orders.findById(orderId);
if (!order) {
return {
content: [{ type: "text", text: `Order not found: ${orderId}` }],
isError: true
};
}
return {
content: [{
type: "text",
text: JSON.stringify({
id: order.id,
status: order.status,
createdAt: order.createdAt,
items: order.items.map(i => ({
name: i.name, quantity: i.quantity, price: i.price
})),
total: order.total,
shipping: {
method: order.shippingMethod,
trackingNumber: order.trackingNumber,
estimatedDelivery: order.estimatedDelivery
}
}, null, 2)
}]
};
}
);
// ---- OTR Trust Query (ORBEXA Integration) ----
server.tool(
"otr_verify",
"Query a merchant website's OTR trust score. Returns six-dimensional trust assessment results.",
{
domain: { type: "string", description: "Merchant domain, e.g. example.com" }
},
async ({ domain }) => {
const response = await fetch(
`https://${domain}/.well-known/otr/verify`
);
if (!response.ok) {
return {
content: [{ type: "text", text: `${domain} has not deployed the OTR protocol` }],
isError: true
};
}
const otr = await response.json();
return {
content: [{
type: "text",
text: JSON.stringify({
domain: otr.domain,
trustScore: otr.trustScore,
dimensions: otr.dimensions,
badges: otr.badges,
lastScan: otr.lastScan
}, null, 2)
}]
};
}
);
// Start
const transport = new StdioServerTransport();
await server.connect(transport);