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