Comments: trim to the established cadence
The MCP code came in with 5–8 line file headers, JSDoc on every
one-line wrapper, and inline explanations that referenced the PR
itself ("so the MCP server can reuse it") — none of which matches
api/server.js or frontend/src/lib/, where comments are one-line,
fact-shaped and never mention the change that introduced them.
Trimmed across mcp/src/*.js, i18n-core.js, i18n.js, exercises.js,
format.js, mcp/test/tools.test.js, mcp/vitest.config.js and
mcp/README.md. Tool prefaces lost their numbers; duplicate fs.watch
rationale folded into one; the ASCII import diagram in the README
replaced with a paragraph; the cross-references and self-references
removed. Also fixed two real defects: a corrupted Cyrillic word in a
state.js comment and a missing space in a tools.test.js comment.
No code changes; 92 frontend + 32 MCP tests still pass.
This commit is contained in:
1 parent
4143ab8676
commit
6aaf2a3eea
11 files changed
+93
-245
No files matched your search
+8
-21
@@ -1,15 +1,7 @@
|
||||
#!/usr/bin/env node
|
||||
// openGym MCP server — stdio transport, read-only tools over a single user's state file.
|
||||
//
|
||||
// Spawning model (per the official MCP design): the LLM client (Claude Desktop, Cursor,
|
||||
// Cline, …) starts this process locally, talks JSON-RPC over stdin/stdout, and tears it down
|
||||
// when the session ends. That matches openGym's "your data stays in a folder you control"
|
||||
// ethos — no extra container, no new outbound network, no third-party service.
|
||||
//
|
||||
// Env:
|
||||
// OPENGYM_DATA directory containing db.json + state-<uid>.json (default: ./data)
|
||||
// OPENGYM_UID which profile to answer for (default: auto-detect the single-user case)
|
||||
// OPENGYM_LANG reserved for future label-localisation (default: en)
|
||||
/* openGym MCP server — stdio transport. The LLM client (Claude Desktop, Cursor, …) spawns
|
||||
this process locally, talks JSON-RPC over stdin/stdout, tears it down when the session ends.
|
||||
No extra container, no new outbound network — your data stays in a folder you control. */
|
||||
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
|
||||
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
||||
import { TOOLS } from './tools.js'
|
||||
@@ -20,22 +12,17 @@ const server = new McpServer({
|
||||
version: '0.1.0'
|
||||
})
|
||||
|
||||
// Initialise the state view up-front so a bad config (missing data dir, ambiguous uid) fails
|
||||
// fast with a clear message on stderr rather than silently answering every tool call with the
|
||||
// "no synced state" fallback. init() is idempotent — the LLM client restart is cheap.
|
||||
// Fail fast on bad config so a misnamed OPENGYM_DATA doesn't silently answer every call with
|
||||
// the no-state sentinel. Always register every tool so the LLM sees the full list at
|
||||
// handshake, even when state didn't resolve.
|
||||
try {
|
||||
init()
|
||||
// Always register every tool, regardless of whether state resolved — an LLM client that
|
||||
// learns the tool list at handshake should see all eight. The handlers themselves degrade
|
||||
// gracefully if state is null (returns the no-state sentinel object).
|
||||
const u = getUser()
|
||||
console.error(`[opengym-mcp] serving profile ${u.name} (${u.id})`)
|
||||
} catch (e) {
|
||||
console.error(`[opengym-mcp] ${e.message}`)
|
||||
// Don't exit — keep the server up so the LLM client still gets tool listings and a useful
|
||||
// error if it tries to call one. Most issues are env-shaped (wrong OPENGYM_DATA path) and
|
||||
// a user will restart once they fix it; failing at handshake is more annoying than a clear
|
||||
// runtime error.
|
||||
// Don't exit — keep the tool listings up so the user sees a useful error after fixing their
|
||||
// env and restarting.
|
||||
}
|
||||
|
||||
for (const t of TOOLS) {
|
||||
|
||||
Reference in new issue
Block a user