Skip to main content
Glama

PostCartsIdComplete

Complete a shopping cart to finalize and place an order in the Medusa e-commerce system.

Instructions

Complete a cart and place an order.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idNo
fieldsNo

Implementation Reference

  • The core handler logic for the PostCartsIdComplete tool (and all store POST tools). It constructs query parameters and body from input, then uses the Medusa SDK to perform a POST request to the /carts/{id}/complete endpoint.
        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 PostCartsIdComplete using Zod schemas inferred from the OpenAPI spec parameters for the corresponding operation.
    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)
    },
  • src/index.ts:35-42 (registration)
    Registers the PostCartsIdComplete tool (among others from medusaStoreService.defineTools()) with the MCP server.
    tools.forEach((tool) => {
        server.tool(
            tool.name,
            tool.description,
            tool.inputSchema,
            tool.handler
        );
    });
  • The method that iterates over the store OpenAPI spec to create tool definitions, including PostCartsIdComplete via wrapPath for the POST /carts/{id}/complete path.
    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;
    }
  • Wrapper around the inner handler that formats the response as MCP-compliant text/JSON output or error, used for all tools including PostCartsIdComplete.
    const wrappedHandler = async (
        input: InferToolHandlerInput<Zod.ZodAny, Zod.ZodAny>,
        _: RequestHandlerExtra
    ): Promise<{
        content: CallToolResult["content"];
        isError?: boolean;
        statusCode?: number;
    }> => {
        try {
            const result = await tool.handler(input);
            return {
                content: [
                    {
                        type: "text",
                        text: JSON.stringify(result, null, 2)
                    }
                ]
            };
        } catch (error) {
            return {
                content: [
                    {
                        type: "text",
                        text: `Error: ${
                            error instanceof Error
                                ? error.message
                                : String(error)
                        }`
                    }
                ],
                isError: true
            };
        }
    };
    
    return {
        ...tool,
        handler: wrappedHandler
    };
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 mentions 'place an order,' implying a write operation that likely mutates data and triggers downstream processes, but fails to detail critical aspects such as required permissions, whether the cart is archived or deleted post-completion, error conditions, or rate limits. This leaves significant gaps in understanding the tool's behavior.

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 extremely concise with a single, front-loaded sentence that directly states the tool's purpose. There is no wasted verbiage or unnecessary elaboration, making it easy to parse quickly.

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 complexity of a cart completion tool (likely involving mutations and order creation), the description is insufficient. With no annotations, 0% schema coverage, and no output schema, it fails to provide necessary context such as parameter meanings, behavioral traits, or expected outcomes. This leaves the agent with inadequate information to use the tool correctly.

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?

The input schema has 0% description coverage, so the description must compensate but does not. It mentions no parameters, leaving 'id' and 'fields' undocumented. Without explanation, it's unclear what 'id' refers to (e.g., cart ID) or what 'fields' might contain (e.g., order metadata). This lack of semantic detail hinders effective tool invocation.

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 ('Complete a cart') and outcome ('place an order'), which is specific and distinguishes it from sibling tools that primarily retrieve data (e.g., GetCartsId) or modify cart components (e.g., PostCartsIdLineItems). However, it doesn't explicitly mention what 'complete' entails beyond ordering, leaving some ambiguity about the final state of the cart.

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 specify prerequisites (e.g., whether the cart must have items or be in a specific state) or contrast with other cart-related tools like PostCartsIdCustomer for updating customer details. This lack of context makes it unclear when this tool is appropriate.

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