Skip to main content
Glama

rr_create_purchase_order

Create draft purchase orders for inventory replenishment by specifying vendor, items, quantities, and delivery dates to prevent stockouts.

Instructions

Create a draft purchase order

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
vendor_idYes
po_numberNo
notesNo
expected_delivery_dateNo
itemsNo

Implementation Reference

  • The callApi function is the handler that executes the tool logic for rr_create_purchase_order. It makes a POST request to the ReplenishRadar API endpoint (/api/mcp/call) with the tool name and input arguments, then returns the result.
    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;
    }
  • The inputSchema for rr_create_purchase_order defines the validation structure with vendor_id (required), po_number, notes, expected_delivery_date, and items array containing sku, quantity, and unit_cost fields.
    { name: 'rr_create_purchase_order', description: 'Create a draft purchase order', inputSchema: { type: 'object' as const, properties: { vendor_id: { type: 'string' }, po_number: { type: 'string' }, notes: { type: 'string' }, expected_delivery_date: { type: 'string' }, items: { type: 'array', items: { type: 'object', properties: { sku: { type: 'string' }, quantity: { type: 'number' }, unit_cost: { type: 'number' } } } } }, required: ['vendor_id'] } },
  • src/index.ts:47-47 (registration)
    The tool is registered in the TOOLS array with name 'rr_create_purchase_order' and description 'Create a draft purchase order'.
    { name: 'rr_create_purchase_order', description: 'Create a draft purchase order', inputSchema: { type: 'object' as const, properties: { vendor_id: { type: 'string' }, po_number: { type: 'string' }, notes: { type: 'string' }, expected_delivery_date: { type: 'string' }, items: { type: 'array', items: { type: 'object', properties: { sku: { type: 'string' }, quantity: { type: 'number' }, unit_cost: { type: 'number' } } } } }, required: ['vendor_id'] } },
  • The CallToolRequestSchema handler dispatches tool calls by extracting the tool name and arguments, then calling the callApi function to execute the tool logic and returning the formatted response.
    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:82-84 (registration)
    The ListToolsRequestSchema handler registers all tools including rr_create_purchase_order by returning the TOOLS array to the MCP server.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: 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/ReplenishRadar/MCP'

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