Skip to main content
Glama
XeroAPI

Xero MCP Server

Official

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
NameRequiredDescriptionDefault
contactIdYes
lineItemsYes
referenceNo

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(),
      },
  • 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
    ];
  • 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),
    );
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden but only states that creation returns a deep link. It lacks critical behavioral details: whether this is a write operation (implied but not explicit), permission requirements, idempotency, error handling, or rate limits. The mention of displaying the link is a minor behavioral note but insufficient for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately concise with three sentences that are front-loaded (purpose first, then output details). No wasted words, though it could be more structured by separating purpose from behavioral notes.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mutation tool with no annotations, 0% schema coverage, and no output schema, the description is incomplete. It covers the basic purpose and output format but misses parameter semantics, usage context, error handling, and other behavioral traits needed for safe and effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate but provides no parameter information. It doesn't explain what 'contactId', 'lineItems', or 'reference' mean, their formats, or how they relate to credit note creation. This leaves all 3 parameters undocumented beyond the schema structure.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'create' and resource 'credit note in Xero', making the purpose specific and understandable. It distinguishes from siblings like 'update-credit-note' by focusing on creation rather than modification, though it doesn't explicitly contrast with other creation tools like 'create-invoice'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. The description mentions the output (a deep link) but doesn't explain prerequisites, scenarios for credit notes over other documents, or comparisons to siblings like 'create-invoice' or 'update-credit-note'.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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