rr_get_purchase_order
Retrieve a specific purchase order with its line items to manage inventory and track procurement details for e-commerce sellers.
Instructions
Get a single purchase order with line items
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| po_id | Yes |
Implementation Reference
- src/index.ts:57-74 (handler)The `callApi` function performs the actual execution of the tool logic by forwarding the request to the ReplenishRadar REST API. All MCP tools, including `rr_get_purchase_order`, are handled through this function.
async function callApi(toolName: string, input: Record<string, unknown>): Promise<unknown> { const resp = await fetch(`${BASE_URL}/api/mcp/call`, { method: 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${API_KEY}`, }, body: JSON.stringify({ tool: toolName, input }), }); if (!resp.ok) { const errorBody = await resp.text(); throw new Error(`API error ${resp.status}: ${errorBody}`); } const data = await resp.json(); return data.result; } - src/index.ts:35-35 (registration)The tool `rr_get_purchase_order` is defined within the `TOOLS` array, which provides the name, description, and input schema for the MCP server's `ListTools` handler.
{ name: 'rr_get_purchase_order', description: 'Get a single purchase order with line items', inputSchema: { type: 'object' as const, properties: { po_id: { type: 'string' } }, required: ['po_id'] } }, - src/index.ts:86-100 (registration)The `CallToolRequestSchema` handler in `src/index.ts` processes incoming tool execution requests and routes them to `callApi`.
server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; try { const result = await callApi(name, (args as Record<string, unknown>) || {}); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }], }; } catch (error) { const message = error instanceof Error ? error.message : String(error); return { content: [{ type: 'text', text: `Error: ${message}` }], isError: true, }; } });