Skip to main content
Glama

update-routine

Update an existing workout routine by ID. Modify title, notes, and exercise configurations for your Hevy routines.

Instructions

Update an existing routine by ID. You can modify the title, notes, and exercise configurations. Returns the updated routine with all changes applied.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
routineIdYes
titleYes
notesNo
exercisesNo

Implementation Reference

  • src/index.ts:76-76 (registration)
    The top-level MCP server registration call for all routine tools, including 'update-routine'. Calls registerRoutineTools(server, hevyClient).
    registerRoutineTools(server, hevyClient);
  • The core handler implementation for the 'update-routine' tool. It registers with server.tool(), receives routineId, title, notes, and exercises params, transforms data via hevyClient.updateRoutine(), and returns the updated routine.
    server.tool(
    	"update-routine",
    	"Update an existing routine by ID. You can modify the title, notes, and exercise configurations. Returns the updated routine with all changes applied.",
    	updateRoutineSchema,
    	withErrorHandling(async (args: UpdateRoutineParams) => {
    		if (!hevyClient) {
    			throw new Error(
    				"API client not initialized. Please provide HEVY_API_KEY.",
    			);
    		}
    		const { routineId, title, notes, exercises } = args;
    		let usesRepRanges = false;
    		const data: PutV1RoutinesRoutineid200 = await hevyClient.updateRoutine(
    			routineId,
    			{
    				routine: {
    					title,
    					notes: notes ?? null,
    					exercises: exercises.map((exercise): PutRoutinesRequestExercise => {
    						const sets = exercise.sets.map((set): PutRoutinesRequestSet => {
    							const repRange = buildRepRange(set.repRange);
    							const fixedReps = getFixedRepsFromRepRange(repRange);
    							const reps =
    								typeof set.reps === "number" ? set.reps : fixedReps;
    							return {
    								type: set.type as PutRoutinesRequestSetTypeEnumKey,
    								weight_kg: set.weight ?? set.weightKg ?? null,
    								reps: reps ?? null,
    								distance_meters: set.distance ?? set.distanceMeters ?? null,
    								duration_seconds: set.duration ?? set.durationSeconds ?? null,
    								custom_metric: set.customMetric ?? null,
    								rep_range: repRange,
    							};
    						});
    
    						if (
    							sets.some(
    								(set) =>
    									set.rep_range != null &&
    									getFixedRepsFromRepRange(set.rep_range) === null,
    							)
    						) {
    							usesRepRanges = true;
    						}
    
    						return {
    							exercise_template_id: exercise.exerciseTemplateId,
    							superset_id: exercise.supersetId ?? null,
    							rest_seconds: exercise.restSeconds ?? null,
    							notes: exercise.notes ?? null,
    							sets,
    						};
    					}),
    				},
    			},
    		);
    
    		if (!data) {
    			return createEmptyResponse(
    				`Failed to update routine with ID ${routineId}`,
    			);
    		}
    
    		const routine = formatRoutine(data);
    		const response = createJsonResponse(routine, {
    			pretty: true,
    			indent: 2,
    		});
    
    		if (usesRepRanges) {
    			response.content.push({
    				type: "text",
    				text: repRangeDisplayWarningText,
    			});
    		}
    
    		return response;
    	}, "update-routine"),
    );
  • The input schema (updateRoutineSchema) for 'update-routine', defining routineId (string), title (string), notes (optional string), and exercises (array of objects with exerciseTemplateId, supersetId, restSeconds, notes, sets). Uses Zod for validation.
    // Update existing routine
    const updateRoutineSchema = {
    	routineId: z.string().min(1),
    	title: z.string().min(1),
    	notes: z.string().optional(),
    	exercises: z.preprocess(
    		parseJsonArray,
    		z.array(
    			z.object({
    				exerciseTemplateId: z.string().min(1),
    				supersetId: z.coerce.number().nullable().optional(),
    				restSeconds: z.coerce.number().int().min(0).optional(),
    				notes: z.string().optional(),
    				sets: z.array(
    					z.object({
    						type: z
    							.enum(["warmup", "normal", "failure", "dropset"])
    							.default("normal"),
    						weight: z.coerce.number().optional(),
    						weightKg: z.coerce.number().optional(),
    						reps: zNullableInt,
    						distance: z.coerce.number().int().optional(),
    						distanceMeters: z.coerce.number().int().optional(),
    						duration: z.coerce.number().int().optional(),
    						durationSeconds: z.coerce.number().int().optional(),
    						customMetric: z.coerce.number().optional(),
    						repRange: zOptionalRepRange,
    					}),
    				),
    			}),
    		),
    	),
    } as const;
  • CoerceNullishNumberInput helper used to preprocess nullable number fields in the schema.
    function coerceNullishNumberInput(value: unknown): unknown {
    	if (value === null || value === undefined) {
    		return value;
    	}
    
    	if (typeof value !== "string") {
    		return value;
    	}
    
    	const trimmed = value.trim();
    	if (trimmed === "") {
    		return undefined;
    	}
    
    	const lowered = trimmed.toLowerCase();
    	if (lowered === "null") {
    		return null;
    	}
    	if (lowered === "undefined") {
    		return undefined;
    	}
    
    	const asNumber = Number(trimmed);
    	if (Number.isNaN(asNumber)) {
    		return value;
    	}
    
    	return asNumber;
    }
  • Helper functions buildRepRange and getFixedRepsFromRepRange used in the update-routine handler to process rep range data on sets.
    function buildRepRange(repRange?: {
    	start?: number | null;
    	end?: number | null;
    }): { start?: number; end?: number } | null {
    	if (!repRange) {
    		return null;
    	}
    
    	const start = repRange.start ?? undefined;
    	const end = repRange.end ?? undefined;
    	if (start === undefined && end === undefined) {
    		return null;
    	}
    
    	return { start, end };
    }
    
    /**
     * Returns a fixed rep count when `repRange` is a fixed range (start and end are
     * both non-null and equal). Otherwise returns null.
     */
    function getFixedRepsFromRepRange(
    	repRange:
    		| {
    				start?: number | null;
    				end?: number | null;
    		  }
    		| null
    		| undefined,
    ): number | null {
    	if (!repRange) {
    		return null;
    	}
    
    	const start = repRange.start ?? null;
    	const end = repRange.end ?? null;
    	if (start === null || end === null) {
    		return null;
    	}
    	if (start !== end) {
    		return null;
    	}
    
    	return start;
    }
Behavior2/5

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

No annotations provided. Description says 'modify' but doesn't specify if it's a full replace or partial update, or whether omitted fields reset. Also implies exercises are modifiable but schema lists exercises as optional, creating ambiguity.

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?

Two concise sentences, front-loaded with main action. Efficient but could include more detail without significant bloat.

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?

No output schema or annotations. Missing crucial behavioral details (partial vs full replace, behavior of omitted fields). For a mutation tool with nested objects (exercises), description is insufficient for correct invocation.

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

Parameters2/5

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

Schema description coverage is 0%. Description only names parameters (routineId, title, notes, exercises) without explaining format or constraints (e.g., title required, exercises nested structure). Adds little beyond schema names.

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?

Clearly states it updates an existing routine by ID, lists modifiable fields (title, notes, exercise configurations), and indicates return value (updated routine). Distinct from sibling create-routine.

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

Usage Guidelines3/5

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

No explicit guidance on when to use vs alternatives (e.g., create for new routines) or prerequisites (routineId must exist). Only states it updates an existing routine.

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/chrisdoc/hevy-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server