search-bill-payments.tool.ts•1.73 kB
import { searchQuickbooksBillPayments } from "../handlers/search-quickbooks-bill-payments.handler.js";
import { ToolDefinition } from "../types/tool-definition.js";
import { z } from "zod";
// Define the tool metadata
const toolName = "search_bill_payments";
const toolTitle = "Search Bill Payments";
const toolDescription = "Search bill payments in QuickBooks Online that match given criteria.";
// Define the expected input schema for searching bill payments
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 searchQuickbooksBillPayments(params);
if (response.isError) {
return {
content: [
{ type: "text" as const, text: `Error searching bill payments: ${response.error}` },
],
};
}
return {
content: [
{ type: "text" as const, text: `Bill payments found:` },
{ type: "text" as const, text: JSON.stringify(response.result) },
],
};
};
export const SearchBillPaymentsTool: ToolDefinition<typeof inputSchema, typeof outputSchema> = {
name: toolName,
title: toolTitle,
description: toolDescription,
inputSchema: inputSchema,
outputSchema: outputSchema,
handler: toolHandler,
};