get-purchase.tool.ts•1.44 kB
import { getQuickbooksPurchase } from "../handlers/get-quickbooks-purchase.handler.js";
import { ToolDefinition } from "../types/tool-definition.js";
import { z } from "zod";
// Define the tool metadata
const toolName = "get_purchase";
const toolTitle = "Get Purchase";
const toolDescription = "Get a purchase by Id from QuickBooks Online.";
// Define the expected input schema for getting a purchase
const inputSchema = {
id: z.string(),
};
const outputSchema = {
success: z.boolean().describe("Whether the operation was successful"),
data: z.any().optional().describe("The result data"),
error: z.string().optional().describe("Error message if operation failed"),
};
// Define the tool handler
const toolHandler = async (params: z.infer<z.ZodObject<typeof inputSchema>>) => {
const response = await getQuickbooksPurchase(params.id);
if (response.isError) {
return {
content: [
{ type: "text" as const, text: `Error getting purchase: ${response.error}` },
],
};
}
return {
content: [
{ type: "text" as const, text: `Purchase retrieved:` },
{ type: "text" as const, text: JSON.stringify(response.result) },
],
};
};
export const GetPurchaseTool: ToolDefinition<typeof inputSchema, typeof outputSchema> = {
name: toolName,
title: toolTitle,
description: toolDescription,
inputSchema: inputSchema,
outputSchema: outputSchema,
handler: toolHandler,
};