Labsco
commercetools logo

commercetools MCP Essentials

13

from commercetools

An MCP server and toolkit for integrating with the commercetools platform APIs.

🔥🔥🔥🔥✓ VerifiedAccount requiredNeeds API keys

[!IMPORTANT] Commerce MCP is provided free of charge as an early access service. Our Service Level Agreement do not apply to Commerce MCP, and it is provided on an "as-is" basis.

commercetools MCP Essentials

This repository contains both a MCP server (which you can integrate with many MCP clients) and agent essentials that can be used from within agent frameworks.

commercetools Model Context Protocol

Available tools

Special Tool Options

ToolDescription
allEnable all available tools (read, create, and update operations)
all.readEnable all read-only tools (safe for read-only access)

Individual Tools

ToolDescription
products.readRead product information
products.createCreate product information
products.updateUpdate product information
project.readRead project information
product-search.readSearch products
category.readRead category information
category.createCreate category
category.updateUpdate category
channel.readRead channel information
channel.createCreate channel
channel.updateUpdate channel information
product-selection.readRead product selection
product-selection.createCreate product selection
product-selection.updateUpdate product selection
order.readRead order information
order.createCreate order (from cart, quote, import)
order.updateUpdate order information
cart.readRead cart information
cart.createCreate cart
cart.updateUpdate cart information
customer.readRead customer information
customer.createCreate customer
customer.updateUpdate customer information
customer-group.readRead customer group
customer-group.createCreate customer group
customer-group.updateUpdate customer group
quote.readRead quote information
quote.createCreate quote
quote.updateUpdate quote information
quote-request.readRead quote request
quote-request.createCreate quote request
quote-request.updateUpdate quote request
staged-quote.readRead staged quote
staged-quote.createCreate staged quote
staged-quote.updateUpdate staged quote
standalone-price.readRead standalone price
standalone-price.createCreate standalone price
standalone-price.updateUpdate standalone price
product-discount.readRead product discount
product-discount.createCreate product discount
product-discount.updateUpdate product discount
cart-discount.readRead cart discount
cart-discount.createCreate cart discount
cart-discount.updateUpdate cart discount
discount-code.readRead discount code information
discount-code.createCreate discount code
discount-code.updateUpdate discount code information
product-type.readRead product type
product-type.createCreate product type
product-type.updateUpdate product type
bulk.createCreate entities in bulk
bulk.updateUpdate entities in bulk
inventory.readRead inventory information
inventory.createCreate inventory
inventory.updateUpdate inventory information
store.readRead store
store.createCreate store
store.updateUpdate store
business-unit.readRead business unit
business-unit.createCreate business unit
business-unit.updateUpdate business unit
payments.readRead payment information
payments.createCreate payment
payments.updateUpdate payment information
tax-category.readRead tax category information
tax-category.createCreate tax category
tax-category.updateUpdate tax category information
shipping-methods.readRead shipping method information
shipping-methods.createCreate shipping method
shipping-methods.updateUpdate shipping method information
zones.readRead zone information
zones.createCreate zone
zones.updateUpdate zone information
recurring-orders.readRead recurring order information
recurring-orders.createCreate recurring order
recurring-orders.updateUpdate recurring order information
shopping-lists.readRead shopping list information
shopping-lists.createCreate shopping list
shopping-lists.updateUpdate shopping list information
extensions.readRead extension information
extensions.createCreate extension
extensions.updateUpdate extension information
subscriptions.readRead subscription information
subscriptions.createCreate subscription
subscriptions.updateUpdate subscription information
payment-methods.readRead payment method information
payment-methods.createCreate payment method
payment-methods.updateUpdate payment method information
product-tailoring.readRead product tailoring information
product-tailoring.createCreate product tailoring
product-tailoring.updateUpdate product tailoring information
custom-objects.readRead custom object information
custom-objects.createCreate custom object
custom-objects.updateUpdate custom object information
types.readRead type information
types.createCreate type
types.updateUpdate type information

To view information on how to develop the MCP server, see this README.

Dynamic Tool Loading

The MCP server includes a dynamic tool loading feature that automatically switches to a more efficient loading strategy when the number of enabled tools exceeds a configurable threshold. This helps optimize performance and reduce context usage when working with large numbers of tools.

How it works

  • Default threshold: 30 tools
  • Behavior: When the number of enabled tools exceeds the threshold, the server switches to dynamic tool loading

Configuration

You can configure the dynamic tool loading threshold in two ways:

Command Line Argument

npx -y @commercetools/mcp-essentials --tools=all --dynamicToolLoadingThreshold=50 --clientId=CLIENT_ID --clientSecret=CLIENT_SECRET --projectKey=PROJECT_KEY --authUrl=AUTH_URL --apiUrl=API_URL

Environment Variable

export DYNAMIC_TOOL_LOADING_THRESHOLD=50
npx -y @commercetools/mcp-essentials --tools=all --clientId=CLIENT_ID --clientSecret=CLIENT_SECRET --projectKey=PROJECT_KEY --authUrl=AUTH_URL --apiUrl=API_URL

Example with Claude Desktop

{
  "mcpServers": {
    "commercetools": {
      "command": "npx",
      "args": [
        "-y",
        "@commercetools/mcp-essentials@latest",
        "--tools=all",
        "--clientId=CLIENT_ID",
        "--clientSecret=CLIENT_SECRET",
        "--authUrl=AUTH_URL",
        "--projectKey=PROJECT_KEY",
        "--apiUrl=API_URL",
        "--dynamicToolLoadingThreshold=25"
      ]
    }
  }
}

MCP Essentials

The commercetools MCP Essentials enables popular agent frameworks including LangChain, Vercel's AI SDK, and Model Context Protocol (MCP) to integrate with APIs through function calling. The library is not exhaustive of the entire commercetools API. It includes support for TypeScript and is built directly on top of the [Node][node-sdk] SDK.

Included below are basic instructions, but refer to the TypeScript package for more information.

TypeScript

Installation

You don't need this source code unless you want to modify the package. If you just want to use the package run:

npm install @commercetools/agent-essentials

Requirements

  • Node 18+

Usage

The library needs to be configured with your commercetools project credentials which are available in your Merchant center. Important: Ensure that the API client credentials have the necessary scopes aligned with the actions you configure in the agent essentials. For example, if you configure products: { read: true }, your API client must have the view_products scope. Additionally, configuration enables you to specify the types of actions that can be taken using the agent essentials.

Client Credentials Authentication (Default)

import { CommercetoolsAgentEssentials } from "@commercetools/agent-essentials/langchain";

const commercetoolsAgentEssentials = await CommercetoolsAgentEssentials.create({
  authConfig: {
    type: 'client_credentials',
    clientId: process.env.CLIENT_ID!,,
    clientSecret: process.env.CLIENT_SECRET!,,
    projectKey: process.env.PROJECT_KEY!,
    authUrl: process.env.AUTH_URL!,
    apiUrl: process.env.API_URL!,
  },
  configuration: {
    actions: {
      products: {
        read: true,
        create: true,
        update: true,
      },
      project: {
        read: true,
      },
    },
  },
});

Access Token Authentication

import { CommercetoolsAgentEssentials } from "@commercetools/agent-essentials/langchain";

const commercetoolsAgentEssentials = await CommercetoolsAgentEssentials.create({
  authConfig: {
    type: "auth_token",
    accessToken: process.env.ACCESS_TOKEN!,
    projectKey: process.env.PROJECT_KEY!,
    authUrl: process.env.AUTH_URL!,
    apiUrl: process.env.API_URL!,
  },
  configuration: {
    actions: {
      products: {
        read: true,
        create: true,
        update: true,
      },
      project: {
        read: true,
      },
    },
  },
});

Tools

The agent essentials work with LangChain and Vercel's AI SDK and can be passed as a list of tools. For example:

import { AgentExecutor, createStructuredChatAgent } from "langchain/agents";

const tools = commercetoolsAgentEssentials.getTools();

const agent = await createStructuredChatAgent({
  llm,
  tools,
  prompt,
});

const agentExecutor = new AgentExecutor({
  agent,
  tools,
});

Model Context Protocol

The commercetools MCP Essentials also supports setting up your own MCP server. For example:

import { CommercetoolsAgentEssentials } from "@commercetools/agent-essentials/modelcontextprotocol";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";

const server = await CommercetoolsAgentEssentials.create({
  authConfig: {
    type: 'client_credentials',
    clientId: process.env.CLIENT_ID!,,
    clientSecret: process.env.CLIENT_SECRET!,,
    projectKey: process.env.PROJECT_KEY!,
    authUrl: process.env.AUTH_URL!,
    apiUrl: process.env.API_URL!,
  },
  configuration: {
    actions: {
      products: {
        read: true,
      },
      cart: {
        read: true,
        create: true,
        update: true,
      },
    },
  },
});

async function main() {
  const transport = new StdioServerTransport();
  await server.connect(transport);
  console.error("My custom commercetools MCP Server running on stdio");
}

main().catch((error) => {
  console.error("Fatal error in main():", error);
  process.exit(1);
});

getTools()

Returns the current set of available tools that can be used with LangChain, AI SDK, or other agent frameworks:

const tools = commercetoolsAgentEssentials.getTools();

Custom Tools

The self managed @commercetools/agent-essentials includes supports for custom tools. A list of custom tools implementations can be passed over and registered at runtime by the bootstrapping MCP server. This is especially useful when the intended tool is not yet implemented into the MCP essentials or to give users complete control and customization of their tools behaviour and how it interact with the underlying LLM.

usage

import { CommercetoolsAgentEssentials } from "@commercetools/agent-essentials/modelcontextprotocol";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";

const server = await CommercetoolsAgentEssentials.create({
  authConfig: {...},
  configuration: {
    customTools: [
      {
        name: "Get Project",
        method: "get_project",
        description: `This tool will fetch information about a commercetools project.\n\n
           This tool will accept a project and fetch information about the provided key. \n\n
          `, // It is important that this description is well details and explicitly descripts what this tool does and the paramenters it receieves/
        parameters: z.object({
          projectKey: z
            .string()
            .optional()
            .describe(
              "The key of the project to read. If not provided, the current project will be used."
            ),
        }),
        actions: {},
        execute: async (args: { projectKey: string }, api: ApiRoot) => {
          // already existing functions can be used here e.g const response = await import('ctService').getProject('demo-project-key-a7fc1182');
          const response = await api.withProjectKey(args).get().execute();
          return JSON.stringify(response);
        },
      },
      ...
    ],
    actions: {...},
  },
});
...

Streamable HTTP MCP server

As of version v2.0.0 of the @commercetools/mcp-essentials MCP server now supports Streamable HTTP (remote) server.

npx -y @commercetools/mcp-essentials \
  --tools=all \
  --authType=client_credentials \
  --clientId=CLIENT_ID \
  --clientSecret=CLIENT_SECRET \
  --projectKey=PROJECT_KEY \
  --authUrl=AUTH_URL \
  --apiUrl=API_URL \
  --remote=true \
  --stateless=true \
  --port=8888

You can connect to the running remote server using Claude by specifying the below in the claude_desktop_config.json file.

{
  "mcpServers": {
    "commercetools": {
      "command": "npx",
      "args": ["mcp-remote", "http://localhost:8888/mcp", "..."]
    }
  }
}

You can also use the Streamable HTTP server with the Agent Essentials like an SDK and develop on it.

import express from "express";
import {
  CommercetoolsAgentEssentials,
  CommercetoolsAgentEssentialsStreamable,
} from "@commercetools/agent-essentials/modelcontextprotocol";

const expressApp = express();

const getAgentServer = async () => {
  return CommercetoolsAgentEssentials.create({
    authConfig: {
      type: "client_credentials",
      clientId: process.env.CLIENT_ID!,
      clientSecret: process.env.CLIENT_SECRET!,
      projectKey: process.env.PROJECT_KEY!,
      authUrl: process.env.AUTH_URL!,
      apiUrl: process.env.API_URL!,
    },
    configuration: {
      actions: {
        products: {
          read: true,
        },
        cart: {
          read: true,
          create: true,
          update: true,
        },
      },
    },
  });
};

const serverStreamable = new CommercetoolsAgentEssentialsStreamable({
  stateless: false, // make the MCP server stateless/stateful
  server: getAgentServer,
  app: expressApp, // optional express app instance
  streamableHttpOptions: {
    sessionIdGenerator: undefined,
  },
});

serverStreamable.listen(8888, function () {
  console.log("listening on 8888");
});

Without using the CommercetoolsAgentEssentials, you can directly use only the CommercetoolsAgentEssentialsStreamable class and the agent server will be bootstrapped internally.

import { CommercetoolsAgentEssentialsStreamable } from "@commercetools/agent-essentials/modelcontextprotocol";
import express from "express";

const expressApp = express();

const server = new CommercetoolsAgentEssentialsStreamable({
  authConfig: {
    type: "client_credentials",
    clientId: process.env.CLIENT_ID!,
    clientSecret: process.env.CLIENT_SECRET!,
    projectKey: process.env.PROJECT_KEY!,
    authUrl: process.env.AUTH_URL!,
    apiUrl: process.env.API_URL!,
  },
  configuration: {
    actions: {
      project: {
        read: true,
      },
      // other tools can go here
    },
  },

  stateless: false,
  app: expressApp,
  streamableHttpOptions: {
    sessionIdGenerator: undefined,
  },
});

server.listen(8888, function () {
  console.log("listening on 8888");
});