MCP: read-only stdio server for LLM apps to query workout history
A Model Context Protocol bridge that lets an external LLM application (Claude Desktop, Cursor, Cline, Continue, …) read a user's openGym profile directly from ./data — no new container, no extra auth, no third-party service. The LLM client spawns the server locally as a stdio process (per the official MCP model); reads the same state-<uid>.json the api server writes; reuses the pure training helpers from frontend/src/lib/*.js so the numbers it answers with match what the Stats screen shows exactly. Eight tools in v1, all read-only: · list_routines, get_routine — names + exercise counts + per-exercise targets · get_week_plan — Mo/We/Fr assignments and today's routine, accounting for any date-specific overrides (a "rest" override cancels the day) · list_workouts, get_workout — newest-first session summaries + per-set breakdown · get_bodyweight — weigh-ins with the goal line and signed deltas vs goal · estimate_1rm — Epley/Brzycki/Lombardi formulas, all-time best + trend per exercise, or a PR table across all reps-mode exercises · muscle_balance — which muscles are trained vs neglected over a week/month/all window State is read with fs.watch (mtime fallback for platforms where watchers are flaky) so the server reflects a session the web UI just finished without a restart. No passkey material, VAPID keys, or session secrets ever cross the boundary — handlers only ever serialize fields from the state object plus the user's name from db.json. The MCP server has exactly one runtime dependency beyond the SDK: none. zod is the SDK's transitive; vitest and Stryker are devDeps only. Tests run against the demo seed fixture (demoSeed.js) — 32 cases pinning the JSON shape and the most user-facing edge cases (empty state, missing routine, rest-day override, zero-workout muscle_balance, three 1RM formulas, superset links, timed/cardio set labels).
This commit is contained in:
1 parent
fadeb17b6c
commit
92914dea43
9 files changed
+5641
No files matched your search
@@ -0,0 +1,21 @@
|
||||
// Vitest config for the MCP server tool tests. Mirrors the conventions of frontend/vite.config.js
|
||||
// (no global config, no auto-watch, run once and exit) — kept in mcp/ rather than hoisted to the
|
||||
// repo root so this package is self-contained and re-usable for any Node-side helper we add later.
|
||||
import { defineConfig } from 'vitest/config'
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
include: ['test/**/*.test.js'],
|
||||
// The tests import from ../src and ../../frontend/src/lib, both already ESM — no transform
|
||||
// needed beyond what Vite does natively. Fake timers are used in tests that pin "today"
|
||||
// (see tools.test.js header comment); they only mock Date, not setTimeout, so the file
|
||||
// watcher in state.js (real setTimeout/setInterval via fs.watch) keeps working.
|
||||
globals: false,
|
||||
environment: 'node',
|
||||
pool: 'forks',
|
||||
// Stryker spawns vitest per-mutant; isolating each test file in its own process keeps a
|
||||
// crashing mutant from taking siblings down with it. Costs ~50ms/test, trade worth it.
|
||||
isolate: true,
|
||||
reporters: ['default']
|
||||
}
|
||||
})
|
||||
Reference in new issue
Block a user