Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
"LICENSE"
],
"scripts": {
"build": "bun build packages/cli/src/index.ts --target node --external @tursodatabase/database --external @modelcontextprotocol/sdk --external zod --outfile dist/cli.mjs && node -e \"let f=require('fs');let c=f.readFileSync('dist/cli.mjs','utf8');f.writeFileSync('dist/cli.mjs',c.replace('#!/usr/bin/env bun','#!/usr/bin/env node'))\"",
"build": "bun build packages/cli/src/index.ts --target node --external @tursodatabase/database --external @modelcontextprotocol/sdk --external zod --external jsonc-parser --outfile dist/cli.mjs && node -e \"let f=require('fs');let c=f.readFileSync('dist/cli.mjs','utf8');f.writeFileSync('dist/cli.mjs',c.replace('#!/usr/bin/env bun','#!/usr/bin/env node'))\"",
"prepublishOnly": "bun run build",
"test": "bun test"
},
"dependencies": {
"@modelcontextprotocol/sdk": "^1.12.1",
"@tursodatabase/database": "^0.6.0",
"jsonc-parser": "^3.3.1",
"zod": "^3.24.0"
},
"devDependencies": {
Expand Down
38 changes: 32 additions & 6 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bun
import { startMcpServer } from "./mcp.js";
import { applyEdits, modify, parse as parseJsonc, type ParseError } from "jsonc-parser";

const command = process.argv[2];

Expand Down Expand Up @@ -61,12 +62,6 @@ if (!command || command === "serve") {
key: "mcpServers",
entry: mcpServersEntry,
},
{
name: "OpenCode",
path: join(xdgConfig, "opencode", "opencode.json"),
key: "mcp",
entry: opencodeMcpEntry,
},
];

let configured = 0;
Expand Down Expand Up @@ -98,6 +93,37 @@ if (!command || command === "serve") {
configured++;
}

// OpenCode: prefer opencode.jsonc over opencode.json
// Use jsonc-parser modify()/applyEdits() to preserve
// comments and formatting, mirroring OpenCode's addMcpToConfig().
const opencodeDir = join(xdgConfig, "opencode");
if (existsSync(opencodeDir)) {
const candidates = [
join(opencodeDir, "opencode.jsonc"),
join(opencodeDir, "opencode.json"),
];
const target = candidates.find(existsSync) ?? candidates[0];
const raw = existsSync(target) ? readFileSync(target, "utf-8") : "{}";
const text = raw.trim() ? raw : "{}";

const errors: ParseError[] = [];
const parsed = parseJsonc(text, errors, { allowTrailingComma: true });
if (errors.length) {
console.log(`OpenCode: config invalid, skipping (${target})`);
} else if ((parsed as any)?.mcp?.cachebro) {
console.log(`OpenCode: already configured (${target})`);
configured++;
} else {
const edits = modify(text, ["mcp", "cachebro"], opencodeMcpEntry, {
formattingOptions: { tabSize: 2, insertSpaces: true },
});
const updated = applyEdits(text, edits);
writeFileSync(target, updated.endsWith("\n") ? updated : updated + "\n");
console.log(`OpenCode: configured (${target})`);
configured++;
}
}

if (configured === 0) {
console.log("No supported tools detected. You can manually add cachebro to your MCP config:");
console.log(JSON.stringify({ mcpServers: { cachebro: mcpServersEntry } }, null, 2));
Expand Down
Loading