Skip to main content
Glama
XeroAPI

Xero MCP Server

Official

create-payment

Record payment transactions against authorized invoices in Xero. Provide invoice ID, account ID, and payment amount to process payments and generate direct links to view them in Xero.

Instructions

Create a payment against an invoice in Xero. This tool records a payment transaction against an invoice. You'll need to provide the invoice ID, account ID to make the payment from, and the amount. The amount must be positive and should not exceed the remaining amount due on the invoice. A payment can only be created for an invoice that is status AUTHORIZED A payment can only be created for an invoice that is not fully paid When a payment is created, a deep link to the payment in Xero is returned. This deep link can be used to view the payment in Xero directly. This link should be displayed to the user.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
invoiceIdYesThe ID of the invoice to pay
accountIdYesThe ID of the account the payment is made from
amountYesThe amount of the payment (must be positive)
dateNoOptional payment date in YYYY-MM-DD format
referenceNoOptional payment reference/description

Implementation Reference

  • Main tool execution handler: calls createXeroPayment, handles errors, generates deep link, and formats response.
      async ({ invoiceId, accountId, amount, date, reference }) => {
        const result = await createXeroPayment({
          invoiceId,
          accountId,
          amount,
          date,
          reference,
        });
        if (result.isError) {
          return {
            content: [
              {
                type: "text" as const,
                text: `Error creating payment: ${result.error}`,
              },
            ],
          };
        }
    
        const payment = result.result;
    
        const deepLink = payment.paymentID
          ? await getDeepLink(DeepLinkType.PAYMENT, payment.paymentID)
          : null;
    
        return {
          content: [
            {
              type: "text" as const,
              text: [
                "Invoice created successfully:",
                `ID: ${payment?.paymentID}`,
                `Reference: ${payment?.reference}`,
                `Invoice Number: ${payment?.invoiceNumber}`,
                `Amount: ${payment?.amount}`,
                `Status: ${payment?.status}`,
                deepLink ? `Link to view: ${deepLink}` : null,
              ]
                .filter(Boolean)
                .join("\n"),
            },
          ],
        };
      },
    );
  • Input schema validation using Zod for the create-payment tool.
    {
      invoiceId: z.string().describe("The ID of the invoice to pay"),
      accountId: z
        .string()
        .describe("The ID of the account the payment is made from"),
      amount: z
        .number()
        .positive()
        .describe("The amount of the payment (must be positive)"),
      date: z
        .string()
        .optional()
        .describe("Optional payment date in YYYY-MM-DD format"),
      reference: z
        .string()
        .optional()
        .describe("Optional payment reference/description"),
    },
  • Registration of the create-payment tool (as part of CreateTools) to the MCP server.
    CreateTools.map((tool) => tool()).forEach((tool) =>
      server.tool(tool.name, tool.description, tool.schema, tool.handler),
  • Core handler: authenticates with Xero client and creates payment against invoice using Xero API.
    export async function createXeroPayment({
      invoiceId,
      accountId,
      amount,
      date,
      reference,
    }: PaymentProps): Promise<XeroClientResponse<Payment>> {
      try {
        const createdPayment = await createPayment({
          invoiceId,
          accountId,
          amount,
          date,
          reference,
        });
    
        if (!createdPayment) {
          throw new Error("Payment creation failed.");
        }
    
        return {
          result: createdPayment,
          isError: false,
          error: null,
        };
      } catch (error) {
        return {
          result: null,
          isError: true,
          error: formatError(error),
        };
      }
    }
  • Low-level helper to construct Payment object and call Xero API createPayment.
    async function createPayment({
      invoiceId,
      accountId,
      amount,
      date,
      reference,
    }: PaymentProps): Promise<Payment | undefined> {
      await xeroClient.authenticate();
    
      const payment: Payment = {
        invoice: {
          invoiceID: invoiceId,
        },
        account: {
          accountID: accountId,
        },
        amount: amount,
        date: date || new Date().toISOString().split("T")[0], // Today's date if not specified
        reference: reference,
      };
    
      const response = await xeroClient.accountingApi.createPayment(
        xeroClient.tenantId,
        payment,
        undefined, // idempotencyKey
        getClientHeaders(), // options
      );
    
      return response.body.payments?.[0];
    }
Behavior4/5

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

With no annotations provided, the description carries full burden and does well by disclosing key behavioral traits: the payment amount constraints (positive, not exceeding remaining due), invoice prerequisites (AUTHORIZED status, not fully paid), and the return value (a deep link to Xero that should be displayed). It doesn't cover error handling or rate limits, but provides substantial operational context.

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 sized and front-loaded with the core purpose. Every sentence adds value: first states the action, second lists key parameters, third-fourth specify constraints, fifth-sixth describe prerequisites, and final sentences explain the return value. Some redundancy exists in stating invoice constraints twice, but overall efficient.

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

Completeness4/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 and no output schema, the description does well by covering purpose, constraints, prerequisites, and return format. It could be more complete by explicitly stating this is a write operation (implied by 'create') and mentioning potential side effects on invoice status, but provides sufficient context for correct tool selection and invocation.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents all 5 parameters thoroughly. The description adds minimal value beyond the schema by mentioning invoiceId, accountId, and amount as required parameters and reinforcing the amount constraints, but doesn't provide additional semantic context about date format interpretation or reference usage.

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

Purpose5/5

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

The description clearly states the specific action ('create a payment'), target resource ('against an invoice in Xero'), and distinguishes it from siblings like 'create-invoice' or 'list-payments'. It goes beyond the tool name by specifying it's a transaction recording operation.

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

Usage Guidelines4/5

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

The description provides clear context about when to use this tool: for invoices that are 'status AUTHORIZED' and 'not fully paid'. However, it doesn't explicitly mention when NOT to use it or name specific alternative tools among the siblings, though the conditions imply alternatives aren't needed for this specific operation.

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