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

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

No annotations are provided, so the description carries full burden. It implies a state change ('revert to draft'), but doesn't disclose behavioral traits like whether this requires specific permissions, if it's reversible, what happens to associated data, or error conditions. For a mutation tool with zero annotation coverage, this is a significant gap.

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

Conciseness5/5

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

The description is a single, efficient sentence with zero waste. It's front-loaded with the core action and resource, making it easy to parse. Every word earns its place.

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 and no output schema, the description is incomplete. It lacks information on behavioral implications (e.g., side effects, permissions), expected outcomes, or error handling. Given the complexity of reverting a timesheet, more context is 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.

Parameters3/5

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

Schema description coverage is 100%, with the single parameter 'timesheetID' fully documented in the schema. The description adds no additional parameter semantics beyond implying the ID is for a timesheet in Xero, which is already clear from context. Baseline 3 is appropriate when the schema does the heavy lifting.

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 action ('revert') and resource ('payroll timesheet') with specific context ('to draft in Xero by its ID'). It distinguishes from obvious siblings like 'delete-timesheet' (destructive removal) and 'update-timesheet-line' (modification), but doesn't explicitly differentiate from all related tools like 'approve-timesheet' (opposite state change).

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. It doesn't mention prerequisites (e.g., timesheet must be approved), exclusions, or compare with siblings like 'update-timesheet-line' for corrections. The description only states what it does, not when it's appropriate.

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