create-journal-entry.tool.ts•1.51 kB
import { createQuickbooksJournalEntry } from "../handlers/create-quickbooks-journal-entry.handler.js";
import { ToolDefinition } from "../types/tool-definition.js";
import { z } from "zod";
// Define the tool metadata
const toolName = "create_journal_entry";
const toolTitle = "Create Journal Entry";
const toolDescription = "Create a journal entry in QuickBooks Online.";
// Define the expected input schema for creating a journal entry
const inputSchema = {
journalEntry: z.any(),
};
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 createQuickbooksJournalEntry(params.journalEntry);
if (response.isError) {
return {
content: [
{ type: "text" as const, text: `Error creating journal entry: ${response.error}` },
],
};
}
return {
content: [
{ type: "text" as const, text: `Journal entry created:` },
{ type: "text" as const, text: JSON.stringify(response.result) },
],
};
};
export const CreateJournalEntryTool: ToolDefinition<typeof inputSchema, typeof outputSchema> = {
name: toolName,
title: toolTitle,
description: toolDescription,
inputSchema: inputSchema,
outputSchema: outputSchema,
handler: toolHandler,
};