Skip to main content
Glama

PostCartsIdPromotions

Add promotions to a shopping cart in Medusa to apply discounts or special offers during checkout.

Instructions

Add a list of promotions to a cart.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idNo
fieldsNo

Implementation Reference

  • src/index.ts:35-42 (registration)
    Registers all tools, including PostCartsIdPromotions, on the MCP server by calling server.tool for each tool from services.
    tools.forEach((tool) => {
        server.tool(
            tool.name,
            tool.description,
            tool.inputSchema,
            tool.handler
        );
    });
  • src/index.ts:14-17 (registration)
    Calls defineTools on MedusaStoreService to get the list of store tools, including PostCartsIdPromotions.
    tools = [
        ...medusaStoreService.defineTools(),
        ...medusaAdminService.defineTools()
    ];
  • Generates all store API tools by iterating over OpenAPI spec paths and wrapping each with wrapPath, including the one for PostCartsIdPromotions.
    defineTools(store = storeJson): any[] {
        const paths = Object.entries(store.paths) as [string, SdkRequestType][];
        const tools = paths.map(([path, refFunction]) =>
            this.wrapPath(path, refFunction)
        );
        return tools;
    }
  • Handler logic for the PostCartsIdPromotions tool (and all store POST tools): constructs query/body from input, calls Medusa SDK fetch with POST method to the specific refPath for carts/{id}/promotions.
    handler: async (
        input: InferToolHandlerInput<any, ZodTypeAny>
    ): Promise<any> => {
        const query = new URLSearchParams(input);
        const body = Object.entries(input).reduce(
            (acc, [key, value]) => {
                if (
                    parameters.find(
                        (p) => p.name === key && p.in === "body"
                    )
                ) {
                    acc[key] = value;
                }
                return acc;
            },
            {} as Record<string, any>
        );
        if (method === "get") {
            console.error(
                `Fetching ${refPath} with GET ${query.toString()}`
            );
            const response = await this.sdk.client.fetch(refPath, {
                method: method,
                headers: {
                    "Content-Type": "application/json",
                    "Accept": "application/json",
                    "Authorization": `Bearer ${process.env.PUBLISHABLE_KEY}`
                },
                query: query
            });
            return response;
        } else {
            const response = await this.sdk.client.fetch(refPath, {
                method: method,
                headers: {
                    "Content-Type": "application/json",
                    "Accept": "application/json",
                    "Authorization": `Bearer ${process.env.PUBLISHABLE_KEY}`
                },
                body: JSON.stringify(body)
            });
            return response;
        }
    }
  • Dynamically generates the input schema for PostCartsIdPromotions from the OpenAPI parameters of the /carts/{id}/promotions endpoint.
    inputSchema: {
        ...parameters
            .filter((p) => p.in != "header")
            .reduce((acc, param) => {
                switch (param.schema.type) {
                    case "string":
                        acc[param.name] = z.string().optional();
                        break;
                    case "number":
                        acc[param.name] = z.number().optional();
                        break;
                    case "boolean":
                        acc[param.name] = z.boolean().optional();
                        break;
                    case "array":
                        acc[param.name] = z
                            .array(z.string())
                            .optional();
                        break;
                    case "object":
                        acc[param.name] = z.object({}).optional();
                        break;
                    default:
                        acc[param.name] = z.string().optional();
                }
                return acc;
            }, {} as any)
    },
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action is 'Add,' implying a mutation, but doesn't cover critical aspects like required permissions, whether promotions are applied immediately, error handling, or response format. This leaves significant gaps for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, direct sentence with no wasted words, making it highly concise and front-loaded. Every part contributes to the core purpose without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity as a mutation with 2 parameters, 0% schema coverage, no annotations, and no output schema, the description is insufficient. It lacks details on behavior, parameter usage, and expected outcomes, making it incomplete for effective agent use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate for undocumented parameters. It mentions adding promotions to a cart, which hints at the 'id' parameter for cart identification and 'fields' for promotion data, but provides no details on format, constraints, or examples, failing to adequately clarify the two parameters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Add') and target resource ('a list of promotions to a cart'), making the purpose immediately understandable. It doesn't distinguish from sibling tools like PostCartsIdLineItems or PostCartsIdShippingMethods, which also add things to carts, so it misses full differentiation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. For example, it doesn't mention prerequisites like needing an existing cart ID or how it relates to other cart-modification tools in the sibling list, leaving the agent to infer usage context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/SGFGOV/medusa-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server