All files / src/tools retailers.ts

100% Statements 6/6
46.15% Branches 6/13
100% Functions 2/2
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45          2x 6x                               2x 2x   1x                           1x          
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import * as z from "zod/v4";
import type { BolClient } from "../bol-client.js";
import { toTextResult, toErrorResult } from "../tool-result.js";
 
export const registerRetailerTools = (server: McpServer, client: BolClient): void => {
  server.registerTool(
    "get_retailer_information",
    {
      title: "Get Retailer Information",
      description:
        "Get retailer information. Provide a retailer ID to look up a specific retailer, or omit it to get your own account information.",
      annotations: { readOnlyHint: true, openWorldHint: true },
 
      inputSchema: z.object({
        retailerId: z
          .string()
          .optional()
          .describe("The retailer ID. Omit or use 'current' to get your own account information."),
      }),
    },
    async ({ retailerId }) => {
      try {
        const retailer = await client.getRetailerInformation(retailerId);
 
        return toTextResult(
          [
            `Retailer: ${retailer.displayName ?? retailer.retailerId ?? "Unknown"}`,
            retailer.retailerId ? `ID: ${retailer.retailerId}` : null,
            retailer.companyName ? `Company: ${retailer.companyName}` : null,
            retailer.displayName ? `Display Name: ${retailer.displayName}` : null,
            retailer.topRetailer !== undefined ? `Top Retailer: ${retailer.topRetailer}` : null,
            retailer.registrationDate ? `Registered: ${retailer.registrationDate}` : null,
          ]
            .filter(Boolean)
            .join("\n"),
          retailer as Record<string, unknown>,
        );
      } catch (error) {
        return toErrorResult(error);
      }
    },
  );
};