Skip to main content
Glama
XeroAPI

Xero MCP Server

Official

get-timesheet

Retrieve a specific payroll timesheet from Xero using its unique identifier to access employee hours, dates, and update information.

Instructions

Retrieve a single payroll timesheet from Xero by its ID. This provides details such as the timesheet ID, employee ID, start and end dates, total hours, and the last updated date.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
timesheetIDYesThe ID of the timesheet to retrieve.

Implementation Reference

  • Main handler function that retrieves a timesheet from Xero, handles errors, and returns a standardized response.
    export async function getXeroPayrollTimesheet(timesheetID: string): Promise< XeroClientResponse<Timesheet | null> > { try { const timesheet = await getTimesheet(timesheetID); return { result: timesheet, isError: false, error: null, }; } catch (error) { return { result: null, isError: true, error: formatError(error), }; } }
  • Core helper function that authenticates the Xero client and fetches the timesheet data from the Xero Payroll NZ API.
    async function getTimesheet(timesheetID: string): Promise<Timesheet | null> { await xeroClient.authenticate(); // Call the Timesheet endpoint from the PayrollNZApi const timesheet = await xeroClient.payrollNZApi.getTimesheet( xeroClient.tenantId, timesheetID, ); return timesheet.body.timesheet ?? null; }
  • Defines, registers, and exports the 'get-timesheet' tool using CreateXeroTool helper. Includes input schema, description, and a wrapper handler that formats the response as MCP content.
    const GetPayrollTimesheetTool = CreateXeroTool( "get-timesheet", `Retrieve a single payroll timesheet from Xero by its ID. This provides details such as the timesheet ID, employee ID, start and end dates, total hours, and the last updated date.`, { timesheetID: z.string().describe("The ID of the timesheet to retrieve."), }, async (params: { timesheetID: string }) => { const { timesheetID } = params; const response = await getXeroPayrollTimesheet(timesheetID); if (response.isError) { return { content: [ { type: "text" as const, text: `Error retrieving timesheet: ${response.error}`, }, ], }; } const timesheet = response.result; if (!timesheet) { return { content: [ { type: "text" as const, text: `No timesheet found with ID: ${timesheetID}`, }, ], }; } return { content: [ { type: "text" as const, text: [ `Timesheet ID: ${timesheet.timesheetID}`, `Employee ID: ${timesheet.employeeID}`, `Start Date: ${timesheet.startDate}`, `End Date: ${timesheet.endDate}`, `Total Hours: ${timesheet.totalHours}`, `Last Updated: ${timesheet.updatedDateUTC}`, ] .filter(Boolean) .join("\n"), }, ], }; }, );
  • Zod schema for the tool's input parameters: timesheetID as string.
    { timesheetID: z.string().describe("The ID of the timesheet to retrieve."), },

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