clipbait 1.4.1 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +40 -6
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -68,6 +68,34 @@ function prompt(question) {
68
68
  return new Promise((resolve) => rl.question(question, (a) => { rl.close(); resolve(a); }));
69
69
  }
70
70
 
71
+ // Register the Clipbait MCP server by editing Claude Code's config directly.
72
+ // This is the reliable path: the `claude` CLI often isn't on PATH (agents,
73
+ // sandboxes), but the config file is always the source of truth. Claude Code
74
+ // reads MCP servers from ~/.claude.json under projects[cwd].mcpServers (local
75
+ // scope) and, when present, a top-level mcpServers (user scope) — we write
76
+ // both so it shows up regardless of which directory Claude opens in.
77
+ function writeMcpConfig(mcpUrl) {
78
+ const cfgPath = path.join(os.homedir(), ".claude.json");
79
+ let cfg;
80
+ try { cfg = JSON.parse(fs.readFileSync(cfgPath, "utf8")); }
81
+ catch { return false; } // no/unreadable config → caller prints manual steps
82
+ const entry = { type: "http", url: mcpUrl };
83
+ cfg.mcpServers = cfg.mcpServers || {};
84
+ cfg.mcpServers.clipbait = entry;
85
+ const cwd = process.cwd();
86
+ cfg.projects = cfg.projects || {};
87
+ cfg.projects[cwd] = cfg.projects[cwd] || {};
88
+ cfg.projects[cwd].mcpServers = cfg.projects[cwd].mcpServers || {};
89
+ cfg.projects[cwd].mcpServers.clipbait = entry;
90
+ try {
91
+ // Atomic write (temp + rename) so a failure can't corrupt the config.
92
+ const tmp = cfgPath + ".clipbait.tmp";
93
+ fs.writeFileSync(tmp, JSON.stringify(cfg, null, 2));
94
+ fs.renameSync(tmp, cfgPath);
95
+ return true;
96
+ } catch { return false; }
97
+ }
98
+
71
99
  // The /clipbait Claude Code slash command. Installed by setup so users can type
72
100
  // "/clipbait <url>" and let Claude drive the whole clip pipeline.
73
101
  const SLASH_COMMAND = `---
@@ -119,14 +147,20 @@ async function runSetup(providedKey) {
119
147
  fs.writeFileSync(path.join(cmdDir, "clipbait.md"), SLASH_COMMAND);
120
148
  console.log("✓ Installed the /clipbait command for Claude Code");
121
149
 
122
- // 2) Register the MCP server with Claude Code (if the `claude` CLI exists).
123
- const { spawnSync } = require("child_process");
124
- const r = spawnSync("claude", ["mcp", "add", "--transport", "http", "clipbait", mcpUrl], { stdio: "ignore" });
125
- if (!r.error && r.status === 0) {
150
+ // 2) Register the MCP server with Claude Code. Prefer editing the config
151
+ // file directly (works everywhere); fall back to the `claude` CLI, then to
152
+ // printing manual steps.
153
+ if (writeMcpConfig(mcpUrl)) {
126
154
  console.log("✓ Connected the Clipbait MCP server to Claude Code");
127
155
  } else {
128
- console.log("• Couldn't auto-connect the MCP server (Claude Code CLI not found). Run this once:");
129
- console.log(" claude mcp add --transport http clipbait " + mcpUrl);
156
+ const { spawnSync } = require("child_process");
157
+ const r = spawnSync("claude", ["mcp", "add", "--transport", "http", "clipbait", mcpUrl], { stdio: "ignore" });
158
+ if (!r.error && r.status === 0) {
159
+ console.log("✓ Connected the Clipbait MCP server to Claude Code");
160
+ } else {
161
+ console.log("• Couldn't auto-connect the MCP server. Add it manually:");
162
+ console.log(" claude mcp add --transport http clipbait " + mcpUrl);
163
+ }
130
164
  }
131
165
 
132
166
  console.log("\n🎬 Done! Restart Claude Code, then type:\n /clipbait https://youtube.com/watch?v=…\n");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clipbait",
3
- "version": "1.4.1",
3
+ "version": "1.5.0",
4
4
  "description": "Clipbait CLI — turn any video into viral clips, and auto-clip live streams, from your terminal or AI agent.",
5
5
  "bin": { "clipbait": "index.js" },
6
6
  "type": "commonjs",