Skip to main content
Glama

GetProducts

Retrieve product listings from Medusa with filtering, sorting, and pagination options to manage inventory data efficiently.

Instructions

Retrieve a list of products. The products can be filtered by fields such as id. The products can also be sorted or paginated.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fieldsNo
offsetNo
limitNo
orderNo
$andNo
$orNo
qNo
idNo
titleNo
handleNo
is_giftcardNo
collection_idNo
tag_idNo
type_idNo
created_atNo
updated_atNo
region_idNo
provinceNo
sales_channel_idNo
category_idNo
variantsNo
country_codeNo
cart_idNo

Implementation Reference

  • This is the core handler function that implements the logic for the GetProducts tool (and all store tools). It processes the input parameters, constructs the appropriate query or body, and makes the API request to the Medusa store backend using the SDK's client.fetch method.
        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 Zod input schema for the GetProducts tool based on the OpenAPI specification parameters for the corresponding 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)
    },
  • src/index.ts:35-42 (registration)
    Registers the GetProducts tool (among others) with the MCP server by calling server.tool for each generated tool.
    tools.forEach((tool) => {
        server.tool(
            tool.name,
            tool.description,
            tool.inputSchema,
            tool.handler
        );
    });
  • Generates all store tools, including GetProducts, by iterating over OpenAPI paths and calling wrapPath to define each tool.
    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;
    }
  • Helper utility that wraps the tool handler to match MCP protocol requirements, serializes output to JSON text, and handles errors appropriately.
    export const defineTool = (
        cb: (zod: typeof z) => ToolDefinition<any, ZodAny, any>
    ) => {
        const tool = cb(z);
    
        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 full burden but offers minimal behavioral disclosure. It mentions filtering, sorting, and pagination but doesn't describe response format, pagination defaults, error conditions, authentication requirements, rate limits, or whether this is a read-only operation. For a tool with 23 parameters and no annotation coverage, this is inadequate.

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

Conciseness4/5

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

The description is appropriately brief (two sentences) and front-loaded with the core purpose. Every sentence adds some value, though more detail would be warranted given the parameter complexity.

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 high complexity (23 parameters, no schema descriptions, no output schema, no annotations), the description is severely incomplete. It doesn't explain return values, error handling, authentication, or the semantics of most parameters. For a list retrieval tool with extensive filtering options, this leaves too much undefined.

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?

With 0% schema description coverage for 23 parameters, the description fails to compensate. It mentions filtering by 'fields such as `id`' and sorting/pagination but doesn't explain the purpose of most parameters (like $and, $or, variants, cart_id, etc.) or provide syntax guidance. The description adds minimal value beyond what's evident from parameter names.

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 verb ('Retrieve') and resource ('list of products'), making the purpose unambiguous. It distinguishes from sibling GetProductsId by indicating this returns a list rather than a single product. However, it doesn't explicitly contrast with other list tools like GetCollections or GetOrders.

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?

The description mentions filtering, sorting, and pagination capabilities but provides no guidance on when to use this tool versus alternatives like GetProductsId (for single products) or other list endpoints. No explicit when/when-not instructions or sibling comparisons are included.

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