Skip to main content
Glama
XeroAPI

Xero MCP Server

Official

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
NameRequiredDescriptionDefault
codeYes
nameYes
descriptionNo
purchaseDescriptionNo
purchaseDetailsNo
salesDetailsNo
isTrackedAsInventoryNo
inventoryAssetAccountCodeNo

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(), },
  • 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),
  • 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, });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/XeroAPI/xero-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server