Skip to main content
Glama
XeroAPI

Xero MCP Server

Official

revert-timesheet

Revert a submitted payroll timesheet to draft status in Xero using its unique identifier to allow for corrections or updates before final processing.

Instructions

Revert a payroll timesheet to draft in Xero by its ID.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
timesheetIDYesThe ID of the timesheet to revert.

Implementation Reference

  • Core handler function that calls the internal revertTimesheet helper to interact with Xero Payroll NZ API and wraps the result in a standard XeroClientResponse.
    export async function revertXeroPayrollTimesheet(timesheetID: string): Promise<
      XeroClientResponse<Timesheet | null>
    > {
      try {
        const revertedTimesheet = await revertTimesheet(timesheetID);
    
        return {
          result: revertedTimesheet,
          isError: false,
          error: null,
        };
      } catch (error) {
        return {
          result: null,
          isError: true,
          error: formatError(error),
        };
      }
    }
  • Low-level helper that authenticates and directly calls Xero's revertTimesheet API endpoint.
    async function revertTimesheet(timesheetID: string): Promise<Timesheet | null> {
      await xeroClient.authenticate();
    
      // Call the revertTimesheet endpoint from the PayrollNZApi
      const revertedTimesheet = await xeroClient.payrollNZApi.revertTimesheet(
        xeroClient.tenantId,
        timesheetID,
      );
    
      return revertedTimesheet.body.timesheet ?? null;
    }
  • Creates and exports the MCP tool definition for 'revert-timesheet', including Zod input schema, description, and execution handler that wraps the core logic and formats MCP response.
    const RevertPayrollTimesheetTool = CreateXeroTool(
      "revert-timesheet",
      `Revert a payroll timesheet to draft in Xero by its ID.`,
      {
        timesheetID: z.string().describe("The ID of the timesheet to revert."),
      },
      async (params: { timesheetID: string }) => {
        const { timesheetID } = params;
        const response = await revertXeroPayrollTimesheet(timesheetID);
    
        if (response.isError) {
          return {
            content: [
              {
                type: "text" as const,
                text: `Error reverting timesheet: ${response.error}`,
              },
            ],
          };
        }
    
        const timesheet = response.result;
    
        return {
          content: [
            {
              type: "text" as const,
              text: `Successfully reverted timesheet with ID: ${timesheet?.timesheetID} to draft.`,
            },
          ],
        };
      },
    );
  • Aggregates and exports the revert-timesheet tool (imported as RevertPayrollTimesheetTool) in the UpdateTools array for higher-level tool registration.
    import ApprovePayrollTimesheetTool from "./approve-payroll-timesheet.tool.js";
    import RevertPayrollTimesheetTool from "./revert-payroll-timesheet.tool.js";
    import UpdateBankTransactionTool from "./update-bank-transaction.tool.js";
    import UpdateContactTool from "./update-contact.tool.js";
    import UpdateCreditNoteTool from "./update-credit-note.tool.js";
    import UpdateInvoiceTool from "./update-invoice.tool.js";
    import UpdateItemTool from "./update-item.tool.js";
    import AddTimesheetLineTool from "./update-payroll-timesheet-add-line.tool.js";
    import UpdatePayrollTimesheetLineTool
      from "./update-payroll-timesheet-update-line.tool.js";
    import UpdateManualJournalTool from "./update-manual-journal-tool.js";
    import UpdateQuoteTool from "./update-quote.tool.js";
    import UpdateTrackingCategoryTool from "./update-tracking-category.tool.js";
    import UpdateTrackingOptionsTool from "./update-tracking-options.tool.js";
    
    export const UpdateTools = [
      UpdateContactTool,
      UpdateCreditNoteTool,
      UpdateInvoiceTool,
      UpdateManualJournalTool,
      UpdateQuoteTool,
      UpdateItemTool,
      UpdateBankTransactionTool,
      ApprovePayrollTimesheetTool,
      AddTimesheetLineTool,
      UpdatePayrollTimesheetLineTool,
      RevertPayrollTimesheetTool,
      UpdateTrackingCategoryTool,
      UpdateTrackingOptionsTool
    ];
  • Generic factory function used to standardize creation of MCP ToolDefinition objects from name, description, Zod schema, and handler callback.
    export const CreateXeroTool =
      <Args extends ZodRawShapeCompat>(
        name: string,
        description: string,
        schema: Args,
        handler: ToolCallback<Args>,
      ): (() => ToolDefinition<ZodRawShapeCompat>) =>
      () => ({
        name: name,
        description: description,
        schema: schema,
        handler: handler,
      });

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