Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

MCP: CI laeuft ueberhaupt erstmal, und der Server ueberlebt seinen Client nicht

Duarte Santose007f76d432c
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 4e3af3452..e8632b40a 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -6,11 +6,13 @@ on:
pull_request:
paths:
- 'frontend/**'
+ - 'mcp/**'
- '.github/workflows/test.yml'
push:
branches: [main]
paths:
- 'frontend/**'
+ - 'mcp/**'
- '.github/workflows/test.yml'
workflow_dispatch:
@@ -41,3 +43,23 @@ jobs:
working-directory: frontend
- run: node scripts/check-locales.mjs
working-directory: frontend
+
+ mcp:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v7
+ - uses: actions/setup-node@v7
+ with:
+ node-version: 22
+ cache: npm
+ cache-dependency-path: mcp/package-lock.json
+ - run: npm ci
+ working-directory: mcp
+ - run: npm test
+ working-directory: mcp
+ # The one check the vitest suite structurally cannot make. The MCP server is a bare node
+ # process, but vitest runs its tests through Vite — import.meta.glob, .jsx imports and
+ # ?raw all resolve happily there. That is how a Vite-only import reached a shared lib
+ # module with 33 green tests standing over a server that died on startup.
+ - run: npm run check:node-loadable
+ working-directory: mcp
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 58486abf4..78539f1c8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -35,6 +35,9 @@ release is invisible to you.
import inside a shared module is invisible under vitest, which transforms it, and fatal to the
MCP server, which does not — so the shared half stays clear of the bundler half by
construction rather than by remembering to.
+- `npm run check:node-loadable` in `mcp/` walks the server's import graph under a bare `node`,
+ which is the one thing the test suite cannot do from inside Vite. CI runs it, alongside the
+ MCP tests — neither had ever run there before.
The MCP server was contributed by [@Pengboi](https://github.com/Pengboi) — the first feature in
openGym written by someone other than me. Thank you.
diff --git a/mcp/package.json b/mcp/package.json
index 62afb7977..92e3de632 100644
--- a/mcp/package.json
+++ b/mcp/package.json
@@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"type": "module",
- "description": "MCP (Model Context Protocol) bridge for openGym — lets an external LLM read your routines, workouts, body-weight log, estimated 1RMs and muscle balance from your self-hosted data. Read-only, stdio transport; no extra container.",
+ "description": "MCP (Model Context Protocol) bridge for openGym \u2014 lets an external LLM read your routines, workouts, body-weight log, estimated 1RMs and muscle balance from your self-hosted data. Read-only, stdio transport; no extra container.",
"license": "AGPL-3.0-or-later",
"main": "src/index.js",
"bin": {
@@ -11,7 +11,8 @@
},
"scripts": {
"start": "node src/index.js",
- "test": "vitest run"
+ "test": "vitest run",
+ "check:node-loadable": "node scripts/check-node-loadable.mjs"
},
"dependencies": {
"@modelcontextprotocol/sdk": "^1.0.4",
diff --git a/mcp/scripts/check-node-loadable.mjs b/mcp/scripts/check-node-loadable.mjs
new file mode 100644
index 000000000..4400c6e13
--- /dev/null
+++ b/mcp/scripts/check-node-loadable.mjs
@@ -0,0 +1,55 @@
+#!/usr/bin/env node
+/* Does the server's import graph still load under plain node?
+ *
+ * This exists because the test suite cannot answer that question. `npm test` runs vitest, and
+ * vitest resolves modules through Vite — `import.meta.glob`, `?raw`, a stray `.jsx` import all
+ * work there. The server does not run under Vite. So a Vite-only import can land in a shared
+ * lib module, leave all 33 tests green, and still kill the server at startup. That is exactly
+ * what happened once: `history.js` began importing `t` from `i18n.js` (import.meta.glob over
+ * the locale packs, plus React), and the server died on `import` with the suite none the wiser.
+ *
+ * Run by bare `node` on purpose — being outside vitest IS the check. Do not port this to a
+ * vitest test file; that would make it pass unconditionally.
+ *
+ * Importing the two entry modules is enough on its own: everything the server touches hangs off
+ * them, so a lib module that grows a browser-only dependency next year fails here without this
+ * list being updated. The named list below only exists to point at the culprit instead of at a
+ * stack trace ten frames deep.
+ */
+const LIB = new URL('../../frontend/src/lib/', import.meta.url)
+
+// Every frontend/src/lib module the server reaches today. Named individually so a failure says
+// which one, rather than which import chain.
+const MODULES = [
+ 'i18n-core.js', 'format.js', 'exercises.js', 'exercises-data.js',
+ 'history.js', 'muscles.js', 'onerm.js', 'progression.js'
+]
+
+let failed = 0
+for (const m of MODULES) {
+ try {
+ await import(new URL(m, LIB))
+ console.log(` ok ${m}`)
+ } catch (e) {
+ failed++
+ console.error(` FAIL ${m} — ${e.message}`)
+ }
+}
+
+// The real assertion: the server's own entry points, which pull the whole graph transitively.
+// A module added to the graph later is covered by this even if the list above never learns it.
+for (const entry of ['../src/state.js', '../src/tools.js']) {
+ try {
+ await import(new URL(entry, import.meta.url))
+ console.log(` ok mcp/${entry.replace('../', '')}`)
+ } catch (e) {
+ failed++
+ console.error(` FAIL mcp/${entry.replace('../', '')} — ${e.message}`)
+ }
+}
+
+if (failed) {
+ console.error(`\n${failed} module(s) do not load under plain node — the MCP server would not start.`)
+ process.exit(1)
+}
+console.log('\nthe whole MCP import graph loads under plain node.')
diff --git a/mcp/src/state.js b/mcp/src/state.js
index 5f67c4785..72c2b03bb 100644
--- a/mcp/src/state.js
+++ b/mcp/src/state.js
@@ -75,6 +75,12 @@ export function init() {
_state = undefined
_loadedMtime = 0
})
+ // Unref'd, or the watcher alone holds the event loop open and the process outlives the
+ // client that spawned it — "exits when the LLM client disconnects" stops being true the
+ // moment there is a state file to watch. Most clients kill the child anyway, but one that
+ // merely closes the pipe would leak a process per session. Watching is unaffected: the
+ // stdio transport is what keeps the loop alive while a client is actually attached.
+ _watcher.unref()
} catch { /* fs.watch unsupported on this platform; tools will re-read on mtime change */ }
}