rr_get_lost_sales
Estimate lost sales from stockouts to identify revenue opportunities and optimize inventory levels.
Instructions
Estimate lost sales from stockouts
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| days | No |
Implementation Reference
- src/index.ts:86-100 (handler)The main request handler for all MCP tool calls. When 'rr_get_lost_sales' is invoked, this handler extracts the tool name and arguments, then calls the callApi function to forward the request to the ReplenishRadar REST API.
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, }; } }); - src/index.ts:43-43 (schema)Schema definition for 'rr_get_lost_sales' tool: accepts a 'days' parameter (number, default 30) to estimate lost sales from stockouts over that time period.
{ name: 'rr_get_lost_sales', description: 'Estimate lost sales from stockouts', inputSchema: { type: 'object' as const, properties: { days: { type: 'number', default: 30 } } } }, - src/index.ts:43-43 (registration)Registration of 'rr_get_lost_sales' tool in the TOOLS array with name, description ('Estimate lost sales from stockouts'), and inputSchema.
{ name: 'rr_get_lost_sales', description: 'Estimate lost sales from stockouts', inputSchema: { type: 'object' as const, properties: { days: { type: 'number', default: 30 } } } }, - src/index.ts:57-74 (helper)The callApi function that implements the actual tool execution logic. It makes a POST request to https://api.replenishradar.com/api/mcp/call with the tool name ('rr_get_lost_sales') and input parameters, returning the API response.
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; }