Files
accounted/scripts/mcp-bridge.mjs
T
Jakob Wennberg ec27228a8e style: remove em/en dashes repo-wide, add CLAUDE.md rule against them (#890)
Em dashes (—) and en dashes (–) had spread across comments, docs, tests,
and a few UI strings, reading as AI-generated boilerplate rather than
house style. Replaced each with punctuation matching its context: colon
for explanatory clauses, comma for asides, plain hyphen for numeric/legal
ranges (e.g. "21-23§"), "to"/"till" for date ranges, parentheses for
paired-dash asides. messages/en.json and messages/sv.json were fixed by
hand together to keep sv/en in sync.

Left untouched where the dash is the functional subject rather than
decorative punctuation: date-range-parser.ts's separator regex,
charset-repair.ts's CP1252 byte-mapping table (and its test), the SIE
encoding mojibake docs, generic-csv.ts's minus-sign normalizer, the
agent system-prompt files that already instruct against em dashes, and
a golden iXBRL test fixture compared byte-for-byte.

Also fixes two bugs surfaced along the way: an off-by-one in
ApiKeysPanel's scope-label split (a leftover from an earlier partial
pass), and a charset-repair test that had lost the literal en-dash it
exists to verify.

Regenerated the agent atom seed migration (skills:generate) since 27
SKILL.md files changed. Added a CLAUDE.md rule against em/en dashes,
with an explicit carve-out for the functional-dash cases above.

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-04 15:58:06 +02:00

95 lines
2.3 KiB
JavaScript

#!/usr/bin/env node
/**
* Stdio-to-HTTP bridge for Claude Desktop.
* Reads JSON-RPC from stdin, POSTs to the gnubok MCP endpoint, writes response to stdout.
*
* Usage in claude_desktop_config.json:
* {
* "mcpServers": {
* "gnubok": {
* "command": "node",
* "args": ["/path/to/erp-base/scripts/mcp-bridge.mjs"],
* "env": {
* "GNUBOK_API_KEY": "gnubok_sk_...",
* "GNUBOK_URL": "http://localhost:3000/api/extensions/ext/mcp-server/mcp"
* }
* }
* }
* }
*/
const API_KEY = process.env.GNUBOK_API_KEY
const URL = process.env.GNUBOK_URL || 'http://localhost:3000/api/extensions/ext/mcp-server/mcp'
if (!API_KEY) {
process.stderr.write('Error: GNUBOK_API_KEY environment variable is required\n')
process.exit(1)
}
let buffer = ''
process.stdin.setEncoding('utf8')
process.stdin.on('data', (chunk) => {
buffer += chunk
// JSON-RPC messages are newline-delimited
let newlineIdx
while ((newlineIdx = buffer.indexOf('\n')) !== -1) {
const line = buffer.slice(0, newlineIdx).trim()
buffer = buffer.slice(newlineIdx + 1)
if (!line) continue
handleMessage(line).catch((err) => {
process.stderr.write(`Bridge error: ${err.message}\n`)
})
}
})
process.stdin.on('end', () => {
process.exit(0)
})
async function handleMessage(line) {
let parsed
try {
parsed = JSON.parse(line)
} catch {
process.stderr.write(`Invalid JSON: ${line}\n`)
return
}
// Notifications (no id) don't expect a response, but still forward them
const isNotification = parsed.id === undefined || parsed.id === null
try {
const res = await fetch(URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${API_KEY}`,
},
body: line,
})
if (res.status === 204) {
// No content (e.g. notifications/initialized): nothing to write back
return
}
const text = await res.text()
if (text) {
process.stdout.write(text + '\n')
}
} catch (err) {
if (!isNotification) {
const errorResponse = JSON.stringify({
jsonrpc: '2.0',
id: parsed.id,
error: { code: -32000, message: `Bridge error: ${err.message}` },
})
process.stdout.write(errorResponse + '\n')
}
}
}