search-purchases.tool.ts•1.7 kB
import { searchQuickbooksPurchases } from "../handlers/search-quickbooks-purchases.handler.js";
import { ToolDefinition } from "../types/tool-definition.js";
import { z } from "zod";
// Define the tool metadata
const toolName = "search_purchases";
const toolTitle = "Search Purchases";
const toolDescription = "Search purchases in QuickBooks Online that match given criteria.";
// Define the expected input schema for searching purchases
const inputSchema = {
criteria: z.array(z.any()).optional(),
asc: z.string().optional(),
desc: z.string().optional(),
limit: z.number().optional(),
offset: z.number().optional(),
count: z.boolean().optional(),
fetchAll: z.boolean().optional(),
};
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 searchQuickbooksPurchases(params);
if (response.isError) {
return {
content: [
{ type: "text" as const, text: `Error searching purchases: ${response.error}` },
],
};
}
return {
content: [
{ type: "text" as const, text: `Purchases found:` },
{ type: "text" as const, text: JSON.stringify(response.result) },
],
};
};
export const SearchPurchasesTool: ToolDefinition<typeof inputSchema, typeof outputSchema> = {
name: toolName,
title: toolTitle,
description: toolDescription,
inputSchema: inputSchema,
outputSchema: outputSchema,
handler: toolHandler,
};