Prood
ApplicationsCommerce API

MCP Server

Model Context Protocol server exposing Commerce API operations as tools for AI agents.

The Commerce API exposes a Model Context Protocol (MCP) server at /mcp, allowing AI agents and LLM applications to interact with commerce data through standardized tools.

Endpoint

POST /mcp
Content-Type: application/json
Authorization: Bearer {jwt} | x-api-key: {key}

Uses streamable HTTP transport via mcp-handler.

Available tools

MCP tools mirror the REST API endpoints. Each tool maps to an OpenAPI operationId:

Catalog tools

ToolREST equivalentDescription
listProductsGET /v1/productsSearch and list products
getProductGET /v1/products/{id}Get product by ID
listCategoriesGET /v1/categoriesList categories
getStoreGET /v1/storeGet store info

Cart tools

ToolREST equivalentDescription
createCartPOST /v1/cartsCreate a new cart
getCartGET /v1/carts/{id}Get cart details
addCartItemPOST /v1/carts/{id}/itemsAdd item to cart
updateCartItemPATCH /v1/carts/{id}/items/{itemId}Update item quantity
removeCartItemDELETE /v1/carts/{id}/items/{itemId}Remove item
applyCartCouponPOST /v1/carts/{id}/couponApply coupon
removeCartCouponDELETE /v1/carts/{id}/couponRemove coupon
setCartShippingAddressPOST /v1/carts/{id}/shipping-addressSet shipping address
listCartShippingMethodsGET /v1/carts/{id}/shipping-methodsList shipping options
listCartPaymentMethodsGET /v1/carts/{id}/payment-methodsList payment options
placeOrderPOST /v1/carts/{id}/place-orderPlace order from cart

Admin tools

ToolREST equivalentDescription
adminListProductsGET /v1/admin/productsList all products
adminCreateProductPOST /v1/admin/productsCreate product
adminUpdateProductPATCH /v1/admin/products/{id}Update product
adminDeleteProductDELETE /v1/admin/products/{id}Delete product
adminListOrdersGET /v1/admin/ordersList orders
adminGetOrderGET /v1/admin/orders/{id}Get order detail
adminFulfillOrderPOST /v1/admin/orders/{id}/fulfillFulfill order
adminRefundOrderPOST /v1/admin/orders/{id}/refundRefund order
adminListCustomersGET /v1/admin/customersList customers
adminGetDashboardStatsGET /v1/admin/dashboard/statsDashboard statistics
adminUpdateStorePATCH /v1/admin/storeUpdate store settings

Authentication

MCP requests use the same authentication as REST:

MethodHeaderScopes
Agent JWTAuthorization: Bearer {jwt}From capability grants
API keyx-api-key: {key}From key metadata

The MCP handler resolves the caller via resolve-caller.ts and sets context in AsyncLocalStorage for tool execution.

Implementation

// apps/api/lib/mcp/handler.ts
import { createMcpHandler } from 'mcp-handler'
import { tools } from './tools'

export const mcpHandler = createMcpHandler({
  tools,
  authenticate: async (request) => {
    const caller = await resolveCaller(request)
    mcpContext.enterWith({ caller })
    return caller
  },
})

Each tool in lib/mcp/tools.ts calls the same commerce-service.ts functions as REST route handlers:

{
  name: 'listProducts',
  description: 'Search and list products in the catalog',
  inputSchema: { ... },
  handler: async (input) => {
    const { caller } = mcpContext.getStore()!
    return listProducts(caller.orgId, input)
  },
}

Connecting an MCP client

Cursor / Claude Desktop

Add to your MCP config:

{
  "mcpServers": {
    "prood-commerce": {
      "url": "http://localhost:3005/mcp",
      "headers": {
        "x-api-key": "pk_your_api_key"
      }
    }
  }
}

Programmatic

Use the @modelcontextprotocol/sdk client:

import { Client } from '@modelcontextprotocol/sdk/client/index.js'

const client = new Client({ name: 'my-agent', version: '1.0.0' })
await client.connect(transport)

const result = await client.callTool({
  name: 'listProducts',
  arguments: { query: 'shirt', limit: 5 },
})

On this page