Repository navigation
MCP: read, create, change and delete programs and their workout days - #167
Open
daniel-bernardino747 wants to merge 1 commit into
Open
daniel-bernardino747 wants to merge 1 commit into
daniel-bernardino747 wants to merge 1 commit into
Conversation
…raceApps#154) An MCP client could list programs and start the day's workout, but not build or adjust a routine. Seven tools close that: - get_program (mcp:read): one program with its days and each exercise's sets, reps, weight, rest and notes. - create_program, update_program, create_template, update_template (mcp:write). - delete_program, delete_template (mcp:destroy, confirm: true). The writes follow the app's own routes: only the account that made a program changes it (program-access.js), fields merge by the newer-wins rule, and a day's exercises go through the same per-uuid merge and tombstones as PUT /api/templates/:id. update_template takes the day's whole list: an exercise sent with its uuid is changed in place and keeps what the tools don't expose (supersets, per-week targets), one without a uuid is added, one left out is removed. Tests: scripts/mcp-programs.test.js.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #154
Summary
An MCP client could list programs and start the day's workout, but not build or adjust a routine. This adds seven tools so an external client (I use Claude) can read, create, change and delete programs and their workout days.
It covers the MCP side of #154 only. Trace's own tools and assigning a template to a weekday are not part of this.
Tools
get_programmcp:readcreate_programmcp:writeupdate_programmcp:writecreate_templatemcp:writeupdate_templatemcp:writedelete_program,delete_templatemcp:destroyconfirm: trueupdate_templatetakes the day's whole list, in order: an exercise sent with theuuidfromget_programis changed in place, one without auuidis added, and one left out is removed. An exercise is named byexercise_idor by name; a name that matches a library exercise is linked to it, otherwise it is stored as free text.How it follows the app
program-access.js). A coach's program and the starter programs read withcan_edit: falseand the write tools refuse them.newer-wins.js), as PUT /api/programs/:id and PUT /api/templates/:id do.uuidkeeps what the tools don't expose (superset membership, per-week targets).Changes
server/lib/mcp/_program-write.js: shared input schema, stored/public exercise conversion, access checks, the exercise-list replaceserver/lib/mcp/tools/:get-program.js,create-program.js,update-program.js,create-template.js,update-template.js,delete-program.jsserver/lib/mcp/tools/index.js: registration behind the read, write and destroy gatesscripts/mcp-programs.test.js: 9 integration testsCHANGELOG.md,README.mdNo schema changes and no new dependencies.
How to test
MCP_ENABLED=1,MCP_WRITE_ENABLED=1andMCP_DESTROY_ENABLED=1, and create a token withmcp:read,mcp:writeandmcp:destroy.get_program.uuid, add one and leave one out inupdate_template; check the day in the app's editor.update_programon a starter program: it is refused.delete_templateanddelete_programrefuse withoutconfirm: true.node --test scripts/mcp-programs.test.jscovers the same paths.Tested
scripts/mcp-programs.test.js: 9 of 9 pass (Node 24, Linux)./api/mcpendpoint with a real token, including input validation.session-version.test.js"a password reset by email link signs every session out" (socket hang up), which fails the same way without this change in my container.Not done
/api/v1) equivalents. I can add either if you'd want them in this PR.This is only a suggestion. Feel free to use all of it, part of it or none of it.
I used AI (Claude Code) to help write these changes; I reviewed and tested them myself.