create-item
Add new items to your Xero accounting system, defining product or service details for sales and purchase tracking.
Instructions
Create an item in Xero.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | ||
| name | Yes | ||
| description | No | ||
| purchaseDescription | No | ||
| purchaseDetails | No | ||
| salesDetails | No | ||
| isTrackedAsInventory | No | ||
| inventoryAssetAccountCode | No |
Implementation Reference
- Core handler function that wraps the Xero API call to create an item, handling errors and returning structured response.export async function createXeroItem( itemDetails: ItemDetails ): Promise<XeroClientResponse<Item | null>> { try { const item = await createItem(itemDetails); return { result: item, isError: false, error: null, }; } catch (error) { return { result: null, isError: true, error: formatError(error), }; }
- Tool-specific handler that calls the core createXeroItem handler and formats the MCP tool response.async ({ code, name, description, purchaseDescription, purchaseDetails, salesDetails, isTrackedAsInventory, inventoryAssetAccountCode, }) => { const result = await createXeroItem({ code, name, description, purchaseDescription, purchaseDetails, salesDetails, isTrackedAsInventory, inventoryAssetAccountCode, }); if (result.isError) { return { content: [ { type: "text" as const, text: `Error creating item: ${result.error}`, }, ], }; } const item = result.result; return { content: [ { type: "text" as const, text: [ "Item created successfully:", `ID: ${item?.itemID}`, `Code: ${item?.code}`, `Name: ${item?.name}`, ] .filter(Boolean) .join("\n"), }, ], }; },
- Input schema for the create-item tool defined using Zod, including sub-schemas for purchase and sales details.const CreateItemTool = CreateXeroTool( "create-item", "Create an item in Xero.", { code: z.string(), name: z.string(), description: z.string().optional(), purchaseDescription: z.string().optional(), purchaseDetails: purchaseDetailsSchema.optional(), salesDetails: salesDetailsSchema.optional(), isTrackedAsInventory: z.boolean().optional(), inventoryAssetAccountCode: z.string().optional(), },
- src/tools/tool-factory.ts:17-18 (registration)Registers all create tools, including create-item, with the MCP server using server.tool().CreateTools.map((tool) => tool()).forEach((tool) => server.tool(tool.name, tool.description, tool.schema, tool.handler),
- src/helpers/create-xero-tool.ts:5-17 (helper)Helper factory function used to standardize the creation of Xero MCP tools with name, description, schema, and handler.export const CreateXeroTool = <Args extends ZodRawShapeCompat>( name: string, description: string, schema: Args, handler: ToolCallback<Args>, ): (() => ToolDefinition<ZodRawShapeCompat>) => () => ({ name: name, description: description, schema: schema, handler: handler, });