feat: gnubok-mcp npm package for Claude Desktop (#78)

* feat: add gnubok-mcp npm package for Claude Desktop

Published as gnubok-mcp@1.0.0 on npm. Users configure Claude Desktop
with `npx gnubok-mcp` + their API key. Zero dependencies, 1.3 KB.

Works as a stdio-to-HTTP bridge while Claude Desktop's OAuth connector
feature is in beta. Updated settings panel instructions to show the
npx approach instead of the OAuth connector flow.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* fix: harden gnubok-mcp bridge (v1.0.1)

- Rename URL → MCP_URL to avoid shadowing built-in URL constructor
- Wrap non-2xx responses in JSON-RPC error instead of forwarding raw
  HTTP body (prevents CDN HTML pages from corrupting stdio stream)
- Restore select-all on Claude Desktop config snippet

Published as gnubok-mcp@1.0.1.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jakob Wennberg
2026-03-21 16:48:32 +01:00
committed by GitHub
co-authored by Claude Opus 4.6
parent 51467717f1
commit 53d1807e8f
3 changed files with 164 additions and 4 deletions
+13 -4
View File
@@ -204,11 +204,20 @@ export function ApiKeysPanel() {
<div>
<p className="text-sm font-medium mb-1">Claude Desktop</p>
<p className="text-xs text-muted-foreground mb-2">
Inställningar &rarr; Connectors &rarr; Add custom connector. Klistra in URL:en nedan.
Du loggas in automatiskt via OAuth.
Lägg till i <code className="text-xs">claude_desktop_config.json</code> (Inställningar &rarr; Developer):
</p>
<pre className="rounded-md bg-muted p-3 text-xs font-mono overflow-x-auto select-all">
{mcpUrl}
<pre className="rounded-md bg-muted p-4 text-xs font-mono overflow-x-auto select-all">
{`{
"mcpServers": {
"gnubok": {
"command": "npx",
"args": ["gnubok-mcp"],
"env": {
"GNUBOK_API_KEY": "gnubok_sk_..."
}
}
}
}`}
</pre>
</div>
+124
View File
@@ -0,0 +1,124 @@
#!/usr/bin/env node
/**
* gnubok-mcp — Connect Claude Desktop to your gnubok bookkeeping account.
*
* Usage in claude_desktop_config.json:
* {
* "mcpServers": {
* "gnubok": {
* "command": "npx",
* "args": ["gnubok-mcp"],
* "env": {
* "GNUBOK_API_KEY": "gnubok_sk_..."
* }
* }
* }
* }
*
* Get your API key at: https://app.gnubok.se/settings?tab=api
*/
const API_KEY = process.env.GNUBOK_API_KEY
const MCP_URL = process.env.GNUBOK_URL || 'https://app.gnubok.se/api/extensions/ext/mcp-server/mcp'
if (!API_KEY) {
process.stderr.write(
'Error: GNUBOK_API_KEY is required.\n' +
'Get your API key at: https://app.gnubok.se/settings?tab=api\n' +
'\n' +
'Add it to your Claude Desktop config:\n' +
'{\n' +
' "mcpServers": {\n' +
' "gnubok": {\n' +
' "command": "npx",\n' +
' "args": ["gnubok-mcp"],\n' +
' "env": {\n' +
' "GNUBOK_API_KEY": "gnubok_sk_..."\n' +
' }\n' +
' }\n' +
' }\n' +
'}\n'
)
process.exit(1)
}
let buffer = ''
process.stdin.setEncoding('utf8')
process.stdin.on('data', (chunk) => {
buffer += chunk
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(`gnubok-mcp 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(`gnubok-mcp: invalid JSON\n`)
return
}
const isNotification = parsed.id === undefined || parsed.id === null
try {
const res = await fetch(MCP_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${API_KEY}`,
},
body: line,
})
if (res.status === 202 || res.status === 204) {
return
}
const text = await res.text()
// Guard against non-JSON error responses (CDN HTML pages, proxy errors)
if (!res.ok && !isNotification) {
let message = `HTTP ${res.status}`
try {
const json = JSON.parse(text)
if (json.error) message = typeof json.error === 'string' ? json.error : JSON.stringify(json.error)
} catch { /* body wasn't JSON — use generic message */ }
const errorResponse = JSON.stringify({
jsonrpc: '2.0',
id: parsed.id,
error: { code: -32000, message },
})
process.stdout.write(errorResponse + '\n')
return
}
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: `Connection error: ${err.message}` },
})
process.stdout.write(errorResponse + '\n')
}
}
}
+27
View File
@@ -0,0 +1,27 @@
{
"name": "gnubok-mcp",
"version": "1.0.1",
"description": "Connect Claude Desktop to your gnubok bookkeeping account",
"bin": {
"gnubok-mcp": "./index.mjs"
},
"type": "module",
"license": "MIT",
"keywords": [
"mcp",
"gnubok",
"bookkeeping",
"claude",
"accounting"
],
"repository": {
"type": "git",
"url": "https://github.com/erp-mafia/gnubok"
},
"engines": {
"node": ">=18"
},
"files": [
"index.mjs"
]
}