Skip to main content
Glama

create_routine

Create a new workout routine by defining exercises, sets, and rest intervals. Optionally assign to a folder and handle duplicates.

Instructions

Create a new routine.

Required routine shape: { title, folder_id?, notes?, exercises: [ { exercise_template_id, rest_seconds?, notes?, sets: [ { type, weight_kg?, reps?, rpe? } ] } ] }

WORKFLOW for natural-language requests:

  1. Resolve every exercise name to a template id with search_exercise_templates.

  2. (Optional) Create or look up the target folder with the folder tools.

  3. Call this tool. If a routine with the same title already exists in the folder you'll get back a duplicate_of payload — confirm with the user, then re-call with force=True (or call update_routine instead).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
routineYes
forceNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The actual MCP tool handler (with @mcp.tool() and @tool_guard decorators) for create_routine. Parses the routine dict, delegates to _do_create_routine.
    @mcp.tool()
    @tool_guard
    async def create_routine(
        routine: dict[str, Any],
        force: bool = False,
    ) -> dict[str, Any]:
        """Create a new routine.
    
        Required `routine` shape:
          { title, folder_id?, notes?, exercises: [
              { exercise_template_id, rest_seconds?, notes?, sets: [
                  { type, weight_kg?, reps?, rpe? }
              ] }
          ] }
    
        WORKFLOW for natural-language requests:
          1. Resolve every exercise name to a template id with `search_exercise_templates`.
          2. (Optional) Create or look up the target folder with the folder tools.
          3. Call this tool. If a routine with the same title already exists in the
             folder you'll get back a `duplicate_of` payload — confirm with the user,
             then re-call with `force=True` (or call `update_routine` instead).
        """
        return await _do_create_routine(client, routine, force)
  • Core business logic: validates via Routine Pydantic schema, checks for duplicate title in folder (unless force=True), then POSTs to /routines.
    async def _do_create_routine(
        client, routine: dict[str, Any], force: bool,
    ) -> dict[str, Any]:
        """Module-level body of the create_routine tool — kept testable without FastMCP."""
        validated = Routine.model_validate(routine).model_dump(exclude_none=True)
        title = validated.get("title")
        folder_id = validated.get("folder_id")
    
        if not force and title:
            dup = await _find_duplicate(client, title, folder_id)
            if dup is not None:
                return {
                    "error": f"A routine titled {title!r} already exists in this folder.",
                    "hint": ("Confirm with the user. To overwrite, call `update_routine` "
                             "with the existing id. To create anyway, re-call with force=True."),
                    "duplicate_of": dup,
                }
    
        data = await client.post("/routines", json={"routine": validated})
        return {"text": f"Routine '{title}' created.", "data": data}
  • Pydantic schema used by create_routine to validate the routine payload before POSTing to Hevy API.
    class Routine(_Base):
        id: str | None = None
        title: str
        folder_id: int | None = None
        notes: str | None = None
        exercises: list[RoutineExercise] = Field(default_factory=list)
  • Server entry point calls register_all() which calls routines.register(), attaching create_routine to the MCP server.
    def build_server() -> tuple[FastMCP, AppContext]:
        _configure_logging()
        client = HevyClient()
        ctx = AppContext(client=client, template_cache=TTLCache(ttl_seconds=24 * 60 * 60))
    
        mcp = FastMCP(
            name="hevy-mcp",
            instructions=(
                "Tools to read and write a user's data on Hevy (workout-tracking app). "
                "When the user asks to build or modify a routine from natural language, "
                "ALWAYS resolve exercise names to template ids via `search_exercise_templates` "
                "before calling `create_routine` or `update_routine`. Do not invent ids. "
                "Workout list pages are capped at 10 items by Hevy."
            ),
        )
        register_all(mcp, ctx)
        return mcp, ctx
  • Module import/registration wiring: register_all() calls routines.register() which defines the create_routine tool.
    def register_all(mcp, ctx) -> None:
        workouts.register(mcp, ctx)
        routines.register(mcp, ctx)
Behavior4/5

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

Discloses duplicate detection behavior (duplicate_of payload) and the need for user confirmation. No annotations present, so description carries burden; it covers major behavioral aspects but does not mention idempotency or whether the tool modifies existing data without force.

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?

Well-structured with sections and bullet points, but somewhat verbose due to the inline JSON-like shape. Generally concise and front-loaded.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Covers all necessary aspects: required shape, workflow steps, duplicate behavior, and sibling distinction. Has output schema, so return values not needed.

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

Parameters5/5

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

With 0% schema coverage, description compensates fully by specifying the exact nested shape for the routine parameter and explaining the force parameter in the context of duplicate handling.

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 'Create a new routine' with specific verb and resource. Distinguishes from sibling tool update_routine by describing duplicate handling and the force parameter pathway.

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

Usage Guidelines5/5

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

Provides explicit workflow: resolve exercise names with search_exercise_templates, optionally handle folders, then call this tool. Details what to do on duplicate (confirm user, re-call with force=True or use update_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/Vellarasan/hevy-mcp'

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