Commerce Layer MCP Server for Metrics Analysis
Analyze Commerce Layer data with a local MCP server and built-in metrics tools for fast, flexible analysis and debugging.
npx -y @commercelayer/mcp-server-metricsOverview
This project provides a local Model Context Protocol (MCP) server tailored for analyzing Commerce Layer metrics. The server acts as a local bridge between AI agents (or local tooling) and the Commerce Layer Metrics API, exposing a collection of prebuilt tools that make it fast to query, aggregate, and inspect historical orders, carts, and returns data. Running this server locally helps with rapid iteration, debugging, and exploratory data-analysis workflows without requiring direct calls to the remote API from every script or agent.
The Metrics MCP Server ships with a set of query primitives (breakdowns, date breakdowns, stats and searches) implemented as MCP tools. These tools cover common analytics needs—top-sellers, cart activity, promotion attribution, error inspection—so you can compose reproducible queries and surface results directly inside a model-driven workflow or a local developer environment.
Features
- Local MCP server implementation compatible with Model Context Protocol hosts (e.g., Claude Desktop)
- Built-in metric tools to query Commerce Layer Metrics API for orders, carts, and returns
- Four query types: breakdown, date-breakdown, stats, and search
- Ready-made tools for common analytics tasks (best-sellers, frequently-bought-together, orders-by-currency, etc.)
- Bundling support for MCP hosts (pack an extension bundle for Claude Desktop)
- Lightweight install, build and packaging workflow; compiled output stored in dist/
Installation / Configuration
Clone, install dependencies, build, and prepare the MCP server:
# clone the repository
# install dependencies (pnpm recommended)
# compile the project
# prepare the distributable files (produces dist/)
If you plan to load the server as a Claude Desktop extension, create a bundle:
# build a packed MCP bundle (mcpb/commercelayer-metrics.mcpb)
Configuration notes
- During installation or when first invoked in an MCP host you will be prompted for Commerce Layer credentials (client_id and client_secret) to connect with your organization. Keep these secrets safe.
- The compiled server artifacts are under
dist/. Depending on your host you may run the server fromdist/or upload the.mcpbbundle produced bynpm run mcpbto Claude Desktop.
Example minimal environment variables (host-specific; adapt if your environment requires):
Available Resources
The server exposes tools that operate on three metric resources:
- orders
- carts
- returns
Each resource supports four query types:
| Query Type | Purpose |
|---|---|
| breakdown | Aggregations grouped by a field (e.g., revenue by market) |
| date-breakdown | Time series aggregations by date (e.g., daily orders) |
| stats | Single-value statistics (sum, avg, count) over a field |
| search | Record search and listing (non-aggregated query & pagination) |
Tool names follow the pattern: Best-selling products by market Customers who bought a specific product Frequently-bought-together products Latest archived or placed orders Orders by currency or by day Orders associated with a specific promotion Debugging order errors Example pseudo-request (date breakdown for daily order counts): Repository and source This MCP server is intended to accelerate analysis workflows and provide reproducible, model-driven access to Commerce Layer metric data for both analytics and debugging scenarios.Use Cases (concrete examples)
Tips for Developers
mcpb/commercelayer-metrics.mcpb) before sharing the extension; the host will request client credentials on first connection.