Skip to main content
Glama

GetCustomersMeAddresses

Retrieve and filter customer addresses by fields like country_code, city, or postal_code. Sort, paginate, and manage address data efficiently using the Medusa MCP Server.

Instructions

Retrieve the addresses of the logged-in customer. The addresses can be filtered by fields such as country_code. The addresses can also be sorted or paginated.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cityNo
country_codeNo
fieldsNo
limitNo
offsetNo
orderNo
postal_codeNo
qNo

Implementation Reference

  • Generic handler that executes the tool logic for GetCustomersMeAddresses by constructing query/body from input and calling Medusa SDK client.fetch on the corresponding API path (/store/customers/me/addresses).
    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 inputSchema for GetCustomersMeAddresses and other store tools based on OpenAPI parameters, mapping types to Zod schemas.
    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:34-41 (registration)
    Registers the GetCustomersMeAddresses tool (among others from store service) to the MCP server using server.tool().
    tools.forEach((tool) => { server.tool( tool.name, tool.description, tool.inputSchema, tool.handler );
  • wrapPath helper that wraps each OpenAPI path into a tool definition, setting name from operationId 'GetCustomersMeAddresses', description, schema, and handler.
    wrapPath(refPath: string, refFunction: SdkRequestType) { return defineTool((z): any => { let name; let description; let parameters: Parameter[] = []; let method = "get"; if ("get" in refFunction) { method = "get"; name = refFunction.get.operationId; description = refFunction.get.description; parameters = refFunction.get.parameters; } else if ("post" in refFunction) { method = "post"; name = refFunction.post.operationId; description = refFunction.post.description; parameters = refFunction.post.parameters ?? []; } if (!name) { throw new Error("No name found for the function"); } return { name: name!, description: description, 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) }, 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; } } }; }); }
  • defineTools method that maps over all OpenAPI paths to create tool definitions, including GetCustomersMeAddresses.
    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; }

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