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
| Name | Required | Description | Default |
|---|---|---|---|
| contactId | Yes | ||
| lineItems | Yes | ||
| reference | No |
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(), });
- src/tools/create/index.ts:13-25 (registration)Groups CreateCreditNoteTool with other create tools for batch registration.export const CreateTools = [ CreateContactTool, CreateCreditNoteTool, CreateManualJournalTool, CreateInvoiceTool, CreateQuoteTool, CreatePaymentTool, CreateItemTool, CreateBankTransactionTool, CreatePayrollTimesheetTool, CreateTrackingCategoryTool, CreateTrackingOptionsTool ];
- src/tools/tool-factory.ts:17-19 (registration)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), );