Skip to main content
Glama
XeroAPI

Xero MCP Server

Official

create-credit-note

Generate a credit note in Xero using defined contact ID and line item details to adjust invoices or refund transactions accurately.

Instructions

Create a credit note in Xero.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contactIdYes
lineItemsYes
referenceNo

Implementation Reference

  • MCP tool definition for 'create-credit-note': includes schema, description, and execution handler that calls the core Xero handler and formats response with deep link.
    const CreateCreditNoteTool = CreateXeroTool( "create-credit-note", "Create a credit note in Xero.\ When a credit note is created, a deep link to the credit note in Xero is returned. \ This deep link can be used to view the credit note in Xero directly. \ This link should be displayed to the user.", { contactId: z.string(), lineItems: z.array(lineItemSchema), reference: z.string().optional(), }, async ({ contactId, lineItems, reference }) => { const result = await createXeroCreditNote(contactId, lineItems, reference); if (result.isError) { return { content: [ { type: "text" as const, text: `Error creating credit note: ${result.error}`, }, ], }; } const creditNote = result.result; const deepLink = creditNote.creditNoteID ? await getDeepLink(DeepLinkType.CREDIT_NOTE, creditNote.creditNoteID) : null; return { content: [ { type: "text" as const, text: [ "Credit note created successfully:", `ID: ${creditNote?.creditNoteID}`, `Contact: ${creditNote?.contact?.name}`, `Total: ${creditNote?.total}`, `Status: ${creditNote?.status}`, deepLink ? `Link to view: ${deepLink}` : null, ] .filter(Boolean) .join("\n"), }, ], }; }, );
  • Core handler function that authenticates with Xero, creates the credit note via API, and returns success/error response.
    export async function createXeroCreditNote( contactId: string, lineItems: CreditNoteLineItem[], reference?: string, ): Promise<XeroClientResponse<CreditNote>> { try { const createdCreditNote = await createCreditNote( contactId, lineItems, reference, ); if (!createdCreditNote) { throw new Error("Credit note creation failed."); } return { result: createdCreditNote, isError: false, error: null, }; } catch (error) { return { result: null, isError: true, error: formatError(error), }; } }
  • Zod schema for credit note line items, used in tool input validation.
    const lineItemSchema = z.object({ description: z.string(), quantity: z.number(), unitAmount: z.number(), accountCode: z.string(), taxType: z.string(), });
  • Groups CreateCreditNoteTool with other create tools for batch registration.
    export const CreateTools = [ CreateContactTool, CreateCreditNoteTool, CreateManualJournalTool, CreateInvoiceTool, CreateQuoteTool, CreatePaymentTool, CreateItemTool, CreateBankTransactionTool, CreatePayrollTimesheetTool, CreateTrackingCategoryTool, CreateTrackingOptionsTool ];
  • Registers all CreateTools (including create-credit-note) on the MCP server via server.tool() calls.
    CreateTools.map((tool) => tool()).forEach((tool) => server.tool(tool.name, tool.description, tool.schema, tool.handler), );

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