Getting Started

Tools

Edit this page

Tools are the "actions" that your AI agent can perform. In the LLM Gateway, tools are built on top of your Backends and automatically adapted to various LLM formats (MCP, OpenAI, Grok).

Built-in Tools

The gateway comes with a set of standard commerce tools. You can enable them by simply adding their names to your configuration.

| Tool Name | Backend Required | Description | |-----------|------------------|-------------| | search_products | products | Search for products using keywords and filters. | | get_product_details | products | Get full details for a specific product. | | check_inventory | products | Check if items are in stock and get ATP. | | add_to_cart | cart | Add a product variant to the current cart. | | create_order | orders | Initialize checkout and create a draft order. |

Universal Tool Abstraction

One of the core strengths of the gateway is its universal tool format. You define a tool once using Zod for schema validation, and the gateway handles the rest.

1import { createTool } from '@commercegateway/commerce-gateway';
2import { z } from 'zod';
3 
4const myCustomTool = createTool({
5 name: 'recommend_by_style',
6 description: 'Find products that match a specific style',
7 schema: z.object({
8 style: z.enum(['modern', 'vintage', 'industrial']),
9 limit: z.number().optional().default(5),
10 }),
11 handler: async ({ style, limit }, context) => {
12 "cmt">// Access your backend via context
13 return await context.backends.products.searchByStyle(style, limit);
14 }
15});

How Adaption Works

When you serve your gateway, it dynamically generates the correct definitions for the target platform:

For Claude (MCP)

The gateway generates a JSON-RPC response that Claude's MCP client can consume, including instructions on how to call the tool.

For OpenAI (Function Calling)

The gateway converts the Zod schema into a JSON Schema format that OpenAI expects in the tools array of a chat completion request.

For Grok

Similar to OpenAI, it formats the tools for X's LLM engine.

Authentication & Security

Tools are automatically protected by the gateway's authentication layer. When an LLM attempts to call a tool, the gateway verifies:

  1. The request has a valid session or API key.
  2. The session is allowed to call the specific tool.
  3. The inputs match the defined schema.

Next Steps

Check out the Guides to see how these tools appear in different AI environments.