restart_timer
Restart a stopped timer by creating a new running time entry from an existing stopped entry. Provide the ID of the time entry to resume tracking.
Instructions
Restart a previously stopped timer, creating a new running time entry based on an existing entry.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | The ID of the time entry to restart the timer for |
Implementation Reference
- src/tools/time-entries.ts:153-169 (handler)The RestartTimerHandler class implements the ToolHandler interface. It validates args against RestartTimerSchema, calls harvestClient.restartTimer(), and returns the time entry data or handles errors.
class RestartTimerHandler implements ToolHandler { constructor(private readonly config: BaseToolConfig) {} async execute(args: Record<string, any>): Promise<CallToolResult> { try { const validatedArgs = validateInput(RestartTimerSchema, args, 'restart timer'); logger.info('Restarting timer via Harvest API', { timeEntryId: validatedArgs.id }); const timeEntry = await this.config.harvestClient.restartTimer(validatedArgs); return { content: [{ type: 'text', text: JSON.stringify(timeEntry, null, 2) }], }; } catch (error) { return handleMCPToolError(error, 'restart_timer'); } } } - src/schemas/time-entry.ts:174-176 (schema)RestartTimerSchema defines the input validation schema: requires a positive integer 'id' for the time entry to restart.
export const RestartTimerSchema = z.object({ id: z.number().int().positive(), // Time entry ID to restart }); - src/tools/time-entries.ts:333-347 (registration)The 'restart_timer' tool is registered in registerTimeEntryTools() with its name, description, inputSchema (requiring 'id'), and the RestartTimerHandler instance.
{ tool: { name: 'restart_timer', description: 'Restart a previously stopped timer, creating a new running time entry based on an existing entry.', inputSchema: { type: 'object', properties: { id: { type: 'number', description: 'The ID of the time entry to restart the timer for' }, }, required: ['id'], additionalProperties: false, }, }, handler: new RestartTimerHandler(config), }, - src/client/harvest-api.ts:130-131 (helper)HarvestApi.restartTimer() is a passthrough method that delegates to timeEntriesClient.restartTimer().
async restartTimer(input: RestartTimerInput): Promise<any> { return this.timeEntriesClient.restartTimer(input); - TimeEntriesClient.restartTimer() performs the actual HTTP PATCH request to /time_entries/{id}/restart, with input validation and error handling.
async restartTimer(input: RestartTimerInput): Promise<any> { try { // Validate input const validatedInput = RestartTimerSchema.parse(input); this.logger.debug('Restarting timer', { timeEntryId: validatedInput.id }); const response: AxiosResponse = await this.client.patch(`/time_entries/${validatedInput.id}/restart`); this.logger.info('Successfully restarted timer', { timeEntryId: response.data.id, projectId: response.data.project?.id, isRunning: response.data.is_running }); return response.data; } catch (error) { if (error instanceof z.ZodError) { this.logger.error('Restart timer validation failed:', error.errors); throw new Error('Invalid timer restart data'); } throw error; } }