Skip to main content
Glama
Demontie

Products API MCP Server

by Demontie

get_products

Retrieve a list of products with optional filters for ID, title, category, brand, price, and rating. Supports pagination to manage large datasets efficiently.

Instructions

Get a list of products with optional filtering and pagination.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
brandNoFilter products by brand
categoryNoFilter products by category
idNoFilter products by ID
limitNoMaximum number of products to return
priceNoFilter products by price
qNoFilter products by title
ratingNoFilter products by rating
skipNoNumber of products to skip

Implementation Reference

  • The async handler function that implements the get_products tool logic: fetches products from dummyjson.com API using provided parameters, handles search and filters, formats response as MCP text content.
    handler: async (params: types.ProductParams): Promise<types.McpResponse> => { try { const { q, ...rest } = params; let result: types.ProductsResponse; let response; if (q) { response = await fetch(`https://dummyjson.com/products/search?q=${q}`, { method: "GET", }); } else { const urlParams = new URLSearchParams(); Object.entries(rest).forEach(([key, value]) => { if (value !== undefined) { urlParams.set(key, value.toString()); } }); response = await fetch( `https://dummyjson.com/products?${urlParams.toString()}`, { method: "GET", } ); } result = await response.json(); if (!result.products) { throw new Error("No results returned from API"); } const content: types.McpTextContent = { type: "text", text: `Products Results:\n\n${JSON.stringify( result.products, null, 2 )}`, }; return { content: [content], }; } catch (error) { console.error(error); throw new Error(`Failed to fetch products: ${error.message} ${error}`); } },
  • Zod schema defining the input parameters for the get_products tool, including optional filters and pagination.
    parameters: { id: z.string().optional().describe("Filter products by ID"), q: z.string().optional().describe("Filter products by title"), category: z.string().optional().describe("Filter products by category"), brand: z.string().optional().describe("Filter products by brand"), price: z.number().optional().describe("Filter products by price"), rating: z.number().optional().describe("Filter products by rating"), skip: z .number() .optional() .default(0) .describe("Number of products to skip"), limit: z .number() .optional() .default(10) .describe("Maximum number of products to return"), },
  • src/index.ts:15-20 (registration)
    Registration of the get_products tool on the MCP server using server.tool() with name, description, parameters, and handler.
    getProductsTool.name, getProductsTool.description, getProductsTool.parameters, getProductsTool.handler );

Other Tools

Related 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/Demontie/my-first-mcp'

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