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.
51 lines
1.7 KiB
JavaScript
51 lines
1.7 KiB
JavaScript
#!/usr/bin/env node
|
|
/* 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'
|
|
import { init, getUser } from './state.js'
|
|
|
|
const server = new McpServer({
|
|
name: 'opengym',
|
|
version: '0.1.0'
|
|
})
|
|
|
|
// 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()
|
|
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 tool listings up so the user sees a useful error after fixing their
|
|
// env and restarting.
|
|
}
|
|
|
|
for (const t of TOOLS) {
|
|
server.tool(
|
|
t.name,
|
|
t.description,
|
|
t.schema,
|
|
async (params) => {
|
|
try {
|
|
const result = t.handler(params || {})
|
|
return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }
|
|
} catch (err) {
|
|
const code = err.code || 'ERROR'
|
|
return {
|
|
isError: true,
|
|
content: [{ type: 'text', text: `${code}: ${err.message}` }]
|
|
}
|
|
}
|
|
}
|
|
)
|
|
}
|
|
|
|
const transport = new StdioServerTransport()
|
|
await server.connect(transport)
|
|
// Process stays alive serving JSON-RPC over stdio until the LLM client disconnects.
|