create-credit-note
Generate credit notes in Xero to issue refunds or adjust invoices, returning a direct link to view the created document.
Instructions
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.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| contactId | Yes | ||
| lineItems | Yes | ||
| reference | No |
Implementation Reference
- Core handler that creates the credit note via Xero API and handles errors.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), }; } }
- Tool-specific handler that wraps the core handler, adds deep link, and formats MCP response.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"), }, ], }; },
- Zod schema for line items and overall input parameters for the tool.const lineItemSchema = z.object({ description: z.string(), quantity: z.number(), unitAmount: z.number(), accountCode: z.string(), taxType: z.string(), }); 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(), },
- src/tools/create/index.ts:13-25 (registration)Registration of the create-credit-note tool (CreateCreditNoteTool) in the CreateTools array.export const CreateTools = [ CreateContactTool, CreateCreditNoteTool, CreateManualJournalTool, CreateInvoiceTool, CreateQuoteTool, CreatePaymentTool, CreateItemTool, CreateBankTransactionTool, CreatePayrollTimesheetTool, CreateTrackingCategoryTool, CreateTrackingOptionsTool ];
- src/tools/tool-factory.ts:17-19 (registration)MCP server registration of all CreateTools, including 'create-credit-note'.CreateTools.map((tool) => tool()).forEach((tool) => server.tool(tool.name, tool.description, tool.schema, tool.handler), );