Skip to main content
Glama
XeroAPI

Xero MCP Server

Official

create-invoice

Generate and send invoices in Xero by specifying contact details and line items. Ensure accurate billing and streamline financial transactions with this tool.

Instructions

Create an invoice in Xero.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contactIdYes
lineItemsYes
referenceNo

Implementation Reference

  • Handler function executing the 'create-invoice' tool logic: calls createXeroInvoice, handles errors, generates deep link to the invoice, and formats the response as MCP content.
    async ({ contactId, lineItems, type, reference, date }) => { const xeroInvoiceType = type === "ACCREC" ? Invoice.TypeEnum.ACCREC : Invoice.TypeEnum.ACCPAY; const result = await createXeroInvoice(contactId, lineItems, xeroInvoiceType, reference, date); if (result.isError) { return { content: [ { type: "text" as const, text: `Error creating invoice: ${result.error}`, }, ], }; } const invoice = result.result; const deepLink = invoice.invoiceID ? await getDeepLink( invoice.type === Invoice.TypeEnum.ACCREC ? DeepLinkType.INVOICE : DeepLinkType.BILL, invoice.invoiceID, ) : null; return { content: [ { type: "text" as const, text: [ "Invoice created successfully:", `ID: ${invoice?.invoiceID}`, `Contact: ${invoice?.contact?.name}`, `Type: ${invoice?.type}`, `Date: ${invoice?.date}`, `Total: ${invoice?.total}`, `Status: ${invoice?.status}`, deepLink ? `Link to view: ${deepLink}` : null, ] .filter(Boolean) .join("\n"), }, ], }; },
  • Zod schema defining the input parameters for the 'create-invoice' tool, including contactId, lineItems, type, reference, and date.
    { contactId: z.string().describe("The ID of the contact to create the invoice for. \ Can be obtained from the list-contacts tool."), lineItems: z.array(lineItemSchema), type: z.enum(["ACCREC", "ACCPAY"]).describe("The type of invoice to create. \ ACCREC is for sales invoices, Accounts Receivable, or customer invoices. \ ACCPAY is for purchase invoices, Accounts Payable invoices, supplier invoices, or bills. \ If the type is not specified, the default is ACCREC."), reference: z.string().describe("A reference number for the invoice.").optional(), date: z.string().describe("The date the invoice was created (YYYY-MM-DD format).").optional(), },
  • Registers the 'create-invoice' tool (via CreateTools) with the MCP server by calling server.tool with its name, description, schema, and handler.
    CreateTools.map((tool) => tool()).forEach((tool) => server.tool(tool.name, tool.description, tool.schema, tool.handler),
  • Core helper function that performs the actual Xero API call to create an invoice, used by the tool handler.
    export async function createXeroInvoice( contactId: string, lineItems: InvoiceLineItem[], type: Invoice.TypeEnum = Invoice.TypeEnum.ACCREC, reference?: string, date?: string, ): Promise<XeroClientResponse<Invoice>> { try { const createdInvoice = await createInvoice( contactId, lineItems, type, reference, date, ); if (!createdInvoice) { throw new Error("Invoice creation failed."); } return { result: createdInvoice, isError: false, error: null, }; } catch (error) { return { result: null, isError: true, error: formatError(error), }; } }
  • Aggregates and exports CreateTools array including the CreateInvoiceTool for registration.
    export const CreateTools = [ CreateContactTool, CreateCreditNoteTool, CreateManualJournalTool, CreateInvoiceTool, CreateQuoteTool, CreatePaymentTool, CreateItemTool, CreateBankTransactionTool, CreatePayrollTimesheetTool, CreateTrackingCategoryTool, CreateTrackingOptionsTool

Other Tools

Related Tools

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