caelario-mcp 0.1.7 → 0.1.9

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.
package/README.md CHANGED
@@ -18,7 +18,9 @@ The page shows each step and helps you check the connection. New accounts start
18
18
  with 200 free credits.
19
19
 
20
20
  The installer opens this setup page automatically when you do not already have
21
- a key. Paste the key only into its secure terminal prompt, never into AI chat.
21
+ a key, or when the key in your terminal environment is rejected. It lets you
22
+ replace a rejected or incomplete key without restarting the command. Paste the
23
+ key only into its secure terminal prompt, never into AI chat.
22
24
 
23
25
  ## Install for Codex
24
26
 
@@ -26,14 +28,31 @@ a key. Paste the key only into its secure terminal prompt, never into AI chat.
26
28
  npx -y caelario-mcp@latest install codex
27
29
  ```
28
30
 
29
- ## Install for Claude Code
31
+ ## Install for Claude Code (terminal or desktop)
30
32
 
31
33
  ```bash
32
34
  npx -y caelario-mcp@latest install claude
33
35
  ```
34
36
 
35
- The installer prompts for a Caelario workspace API key and registers the stdio
36
- server at user scope. It does not ask for Instagram, TikTok, YouTube, X, or
37
+ The installer uses the terminal CLI when available. If it is missing, it detects
38
+ Claude desktop and configures its local MCP settings directly, including support
39
+ for local Code tab sessions. You do not need to install a separate CLI.
40
+
41
+ To choose Claude desktop explicitly (also for its regular chat surface), run:
42
+
43
+ ```bash
44
+ npx -y caelario-mcp@latest install claude-desktop
45
+ ```
46
+
47
+ Quit Claude completely and reopen it after installation. Approve Caelario when
48
+ Claude asks, then ask it to check your connection and available credits.
49
+ Existing desktop settings and other MCP servers are preserved. If the settings
50
+ file is malformed, the installer stops without overwriting it.
51
+
52
+ The installer finds your assistant before starting setup. On Windows it also
53
+ finds the Codex desktop app when `codex` is absent from your terminal PATH. It
54
+ prompts for a Caelario workspace API key and registers the stdio server at user
55
+ scope. It does not ask for Instagram, TikTok, YouTube, X, or
37
56
  Facebook credentials; provider identities are managed by Caelario.
38
57
 
39
58
  After installation, restart the client and ask:
@@ -1,22 +1,22 @@
1
- #!/usr/bin/env node
2
-
3
- import { installClient, printHelp } from "../src/install.js";
4
- import { runServer } from "../src/server.js";
5
-
6
- const [command = "serve", client] = process.argv.slice(2);
7
-
8
- try {
9
- if (command === "serve") {
10
- await runServer();
11
- } else if (command === "install" && (client === "codex" || client === "claude")) {
12
- await installClient(client);
13
- } else if (command === "--help" || command === "-h" || command === "help") {
14
- printHelp();
15
- } else {
16
- printHelp();
17
- process.exitCode = 2;
18
- }
19
- } catch (error) {
20
- process.stderr.write(`Caelario MCP: ${error instanceof Error ? error.message : String(error)}\n`);
21
- process.exitCode = 1;
22
- }
1
+ #!/usr/bin/env node
2
+
3
+ import { installClient, printHelp } from "../src/install.js";
4
+ import { runServer } from "../src/server.js";
5
+
6
+ const [command = "serve", client] = process.argv.slice(2);
7
+
8
+ try {
9
+ if (command === "serve") {
10
+ await runServer();
11
+ } else if (command === "install" && ["codex", "claude", "claude-desktop"].includes(client)) {
12
+ await installClient(client);
13
+ } else if (command === "--help" || command === "-h" || command === "help") {
14
+ printHelp();
15
+ } else {
16
+ printHelp();
17
+ process.exitCode = 2;
18
+ }
19
+ } catch (error) {
20
+ process.stderr.write(`Caelario MCP: ${error instanceof Error ? error.message : String(error)}\n`);
21
+ process.exitCode = 1;
22
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "caelario-mcp",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "mcpName": "io.github.chunkydonut21/caelario",
5
5
  "description": "MCP server for social media data from Instagram, TikTok, YouTube, X and Facebook. Run extractions, batches, schedules, saved results and usage workflows through Caelario.",
6
6
  "type": "module",
package/server.json CHANGED
@@ -9,12 +9,12 @@
9
9
  "source": "github",
10
10
  "id": "1346708115"
11
11
  },
12
- "version": "0.1.7",
12
+ "version": "0.1.9",
13
13
  "packages": [
14
14
  {
15
15
  "registryType": "npm",
16
16
  "identifier": "caelario-mcp",
17
- "version": "0.1.7",
17
+ "version": "0.1.9",
18
18
  "transport": {
19
19
  "type": "stdio"
20
20
  },
package/src/client.js ADDED
@@ -0,0 +1,74 @@
1
+ import { spawnSync } from "node:child_process";
2
+ import { existsSync } from "node:fs";
3
+ import { join } from "node:path";
4
+ import { homedir } from "node:os";
5
+ import { findClaudeDesktop } from "./desktop.js";
6
+
7
+ export function resolveClientExecutable(client, {
8
+ platform = process.platform,
9
+ env = process.env,
10
+ spawn = spawnSync,
11
+ exists = existsSync,
12
+ home = homedir(),
13
+ } = {}) {
14
+ if (!["codex", "claude", "claude-desktop"].includes(client)) throw new Error("client must be codex, claude or claude-desktop");
15
+ if (client === "claude-desktop") {
16
+ const desktop = findClaudeDesktop({ platform, env, home, exists });
17
+ if (desktop) return desktop;
18
+ throw new Error("Claude desktop was not found. Install and open Claude desktop, then run this command again.");
19
+ }
20
+ const options = { encoding: "utf8", stdio: "pipe", windowsHide: true, timeout: 10_000 };
21
+ const usable = (path) => {
22
+ const shell = platform === "win32" && /\.(cmd|bat)$/i.test(path);
23
+ const command = shell ? `"${path}"` : path;
24
+ const result = spawn(command, ["--version"], { ...options, shell });
25
+ if (result.error || result.status !== 0) return null;
26
+ if (client === "claude" && !/\bClaude Code\b|^\s*\d+\.\d+\.\d+(?:[-+][\w.-]+)?(?:\s|$)/i.test(result.stdout || "")) return null;
27
+ return { command, shell };
28
+ };
29
+ if (platform !== "win32") {
30
+ const found = usable(client);
31
+ if (found) return found;
32
+ } else {
33
+ const located = spawn("where.exe", [client], options);
34
+ if (!located.error && located.status === 0) {
35
+ for (const path of (located.stdout || "").trim().split(/\r?\n/)) {
36
+ if (path && exists(path)) {
37
+ const found = usable(path);
38
+ if (found) return found;
39
+ }
40
+ }
41
+ }
42
+ if (client === "codex") {
43
+ // Desktop installs include a CLI even when a normal terminal cannot find it.
44
+ const powershell = join(env.SystemRoot || "C:\\Windows", "System32", "WindowsPowerShell", "v1.0", "powershell.exe");
45
+ const app = spawn(powershell, ["-NoProfile", "-NonInteractive", "-Command",
46
+ "Get-AppxPackage -Name OpenAI.Codex -ErrorAction SilentlyContinue | ForEach-Object { Join-Path $_.InstallLocation 'app\\resources\\codex.exe' }",
47
+ ], options);
48
+ const candidates = !app.error && app.status === 0 ? (app.stdout || "").trim().split(/\r?\n/) : [];
49
+ if (env.LOCALAPPDATA) candidates.push(join(env.LOCALAPPDATA, "Programs", "Codex", "resources", "codex.exe"));
50
+ if (env.ProgramFiles) candidates.push(join(env.ProgramFiles, "Codex", "resources", "codex.exe"));
51
+ for (const path of candidates) {
52
+ if (path && exists(path)) {
53
+ const found = usable(path);
54
+ if (found) return found;
55
+ }
56
+ }
57
+ }
58
+ }
59
+ if (client === "claude") {
60
+ const candidates = [join(home, ".local", "bin", platform === "win32" ? "claude.exe" : "claude")];
61
+ if (platform === "win32" && env.APPDATA) candidates.push(join(env.APPDATA, "npm", "claude.cmd"));
62
+ for (const path of candidates) {
63
+ if (exists(path)) {
64
+ const found = usable(path);
65
+ if (found) return found;
66
+ }
67
+ }
68
+ const desktop = findClaudeDesktop({ platform, env, home, exists });
69
+ if (desktop) return desktop;
70
+ }
71
+ throw new Error(client === "codex"
72
+ ? "Codex was not found. Install the Codex desktop app or Codex CLI, then run this command again."
73
+ : "Neither Claude Code nor Claude desktop was found. Install either one, then run this command again.");
74
+ }
@@ -0,0 +1,19 @@
1
+ export const KEY_PATTERN = /^[A-Za-z0-9._-]{16,256}$/;
2
+
3
+ export function connectionConfiguration(apiKey, apiUrl = "https://api.caelario.com", platform = process.platform) {
4
+ if (!KEY_PATTERN.test(apiKey)) throw new Error("the Caelario API key format is invalid");
5
+ const origin = new URL(apiUrl);
6
+ if (!["http:", "https:"].includes(origin.protocol)) throw new Error("the Caelario API URL requires HTTP or HTTPS");
7
+ if (/[&|<>^%!()\r\n]/.test(origin.origin)) throw new Error("the Caelario API origin contains unsafe launcher characters");
8
+ if (origin.protocol !== "https:" && !["localhost", "127.0.0.1", "[::1]"].includes(origin.hostname)) {
9
+ throw new Error("the Caelario API URL must use HTTPS");
10
+ }
11
+ if (origin.pathname !== "/" || origin.search || origin.hash || origin.username || origin.password) {
12
+ throw new Error("the Caelario API URL must contain only an origin");
13
+ }
14
+ return {
15
+ command: platform === "win32" ? "cmd" : "npx",
16
+ args: [...(platform === "win32" ? ["/c", "npx"] : []), "-y", "caelario-mcp", "serve"],
17
+ env: { CAELARIO_API_URL: origin.origin, CAELARIO_API_KEY: apiKey },
18
+ };
19
+ }
package/src/desktop.js ADDED
@@ -0,0 +1,77 @@
1
+ import { existsSync, readFileSync, mkdirSync, openSync, closeSync, writeFileSync, renameSync, unlinkSync } from "node:fs";
2
+ import { homedir } from "node:os";
3
+ import { join, dirname } from "node:path";
4
+ import { randomUUID } from "node:crypto";
5
+ import { connectionConfiguration } from "./connection.js";
6
+
7
+ export function findClaudeDesktop({ platform = process.platform, env = process.env, home = homedir(), exists = existsSync } = {}) {
8
+ if (platform === "win32") {
9
+ const local = env.LOCALAPPDATA || join(home, "AppData", "Local");
10
+ const installed = [join(local, "AnthropicClaude", "claude.exe"), join(local, "Programs", "Claude", "Claude.exe")];
11
+ if (installed.some((path) => exists(path))) {
12
+ return { desktop: true, configPath: join(env.APPDATA || join(home, "AppData", "Roaming"), "Claude", "claude_desktop_config.json") };
13
+ }
14
+ } else if (platform === "darwin" && ["/Applications/Claude.app", join(home, "Applications", "Claude.app")].some((path) => exists(path))) {
15
+ return { desktop: true, configPath: join(home, "Library", "Application Support", "Claude", "claude_desktop_config.json") };
16
+ }
17
+ return null;
18
+ }
19
+
20
+ class DesktopConfigurationError extends Error {}
21
+
22
+ function readConfiguration(path) {
23
+ let source;
24
+ try { source = readFileSync(path, "utf8"); }
25
+ catch (error) {
26
+ if (error.code === "ENOENT") return { source: null, config: {} };
27
+ throw new DesktopConfigurationError("Could not read Claude desktop settings. Check file permissions and retry.");
28
+ }
29
+ let config;
30
+ try { config = JSON.parse(source.replace(/^\uFEFF/, "")); }
31
+ catch { throw new DesktopConfigurationError("Claude desktop settings contain invalid JSON. Fix them in Claude settings and retry. No settings were changed."); }
32
+ if (!config || typeof config !== "object" || Array.isArray(config)
33
+ || (config.mcpServers !== undefined && (!config.mcpServers || typeof config.mcpServers !== "object" || Array.isArray(config.mcpServers)))) {
34
+ throw new DesktopConfigurationError("Claude desktop settings have an invalid structure. Fix them in Claude settings and retry. No settings were changed.");
35
+ }
36
+ return { source, config };
37
+ }
38
+
39
+ export function checkClaudeDesktopConfiguration(path) {
40
+ readConfiguration(path);
41
+ }
42
+
43
+ export function configureClaudeDesktop(apiKey, apiUrl, { configPath, platform = process.platform } = {}) {
44
+ const entry = connectionConfiguration(apiKey, apiUrl, platform);
45
+ const lockPath = `${configPath}.caelario-install.lock`;
46
+ const temporaryPath = `${configPath}.caelario-${randomUUID()}.tmp`;
47
+ let lock;
48
+ let temporaryCreated = false;
49
+ try {
50
+ mkdirSync(dirname(configPath), { recursive: true, mode: 0o700 });
51
+ try { lock = openSync(lockPath, "wx", 0o600); }
52
+ catch (error) {
53
+ if (error.code === "EEXIST") throw new DesktopConfigurationError("Another Caelario installer is updating Claude desktop settings. Let it finish and retry.");
54
+ throw error;
55
+ }
56
+ const { source, config } = readConfiguration(configPath);
57
+ const updated = { ...config, mcpServers: { ...config.mcpServers, caelario: entry } };
58
+ const temporary = openSync(temporaryPath, "wx", 0o600);
59
+ temporaryCreated = true;
60
+ try { writeFileSync(temporary, `${JSON.stringify(updated, null, 2)}\n`); }
61
+ finally { closeSync(temporary); }
62
+ if (readConfiguration(configPath).source !== source) {
63
+ throw new DesktopConfigurationError("Claude desktop settings changed during installation. Run the installer again. No settings were overwritten.");
64
+ }
65
+ renameSync(temporaryPath, configPath);
66
+ temporaryCreated = false;
67
+ } catch (error) {
68
+ if (error instanceof DesktopConfigurationError) throw error;
69
+ throw new Error("Could not update Claude desktop settings. Close Claude, check file permissions and retry.");
70
+ } finally {
71
+ if (temporaryCreated) { try { unlinkSync(temporaryPath); } catch {} }
72
+ if (lock !== undefined) {
73
+ closeSync(lock);
74
+ try { unlinkSync(lockPath); } catch {}
75
+ }
76
+ }
77
+ }
package/src/install.js CHANGED
@@ -1,32 +1,22 @@
1
1
  import { spawnSync } from "node:child_process";
2
2
  import process from "node:process";
3
3
  import readline from "node:readline";
4
- import { SETUP_URL, setupInstructions, openSetupPage, verifyWorkspaceKey } from "./onboarding.js";
4
+ import { resolveClientExecutable } from "./client.js";
5
+ import { connectionConfiguration, KEY_PATTERN } from "./connection.js";
6
+ import { checkClaudeDesktopConfiguration, configureClaudeDesktop } from "./desktop.js";
7
+ import { SETUP_URL, setupInstructions, openSetupPage, verifyWorkspaceKey, ConnectionKeyRejectedError } from "./onboarding.js";
5
8
 
6
9
  const CLIENTS = new Set(["codex", "claude"]);
7
- const KEY_PATTERN = /^[A-Za-z0-9._-]{16,256}$/;
8
10
 
9
11
  export function registrationCommand(client, apiKey, apiUrl = "https://api.caelario.com", platform = process.platform) {
10
12
  if (!CLIENTS.has(client)) throw new Error("client must be codex or claude");
11
- if (!KEY_PATTERN.test(apiKey)) throw new Error("the Caelario API key format is invalid");
12
- const origin = new URL(apiUrl);
13
- if (!["http:", "https:"].includes(origin.protocol)) throw new Error("the Caelario API URL requires HTTP or HTTPS");
14
- if (/[&|<>^%!()\r\n]/.test(origin.origin)) throw new Error("the Caelario API origin contains unsafe launcher characters");
15
- if (origin.protocol !== "https:" && !["localhost", "127.0.0.1", "[::1]"].includes(origin.hostname)) {
16
- throw new Error("the Caelario API URL must use HTTPS");
17
- }
18
- if (origin.pathname !== "/" || origin.search || origin.hash || origin.username || origin.password) {
19
- throw new Error("the Caelario API URL must contain only an origin");
20
- }
21
-
22
- const launcher = platform === "win32"
23
- ? ["cmd", "/c", "npx", "-y", "caelario-mcp", "serve"]
24
- : ["npx", "-y", "caelario-mcp", "serve"];
13
+ const connection = connectionConfiguration(apiKey, apiUrl, platform);
14
+ const launcher = [connection.command, ...connection.args];
25
15
  const common = [
26
16
  "mcp", "add",
27
17
  ...(client === "claude" ? ["--scope", "user"] : []),
28
18
  "caelario",
29
- "--env", `CAELARIO_API_URL=${origin.origin}`,
19
+ "--env", `CAELARIO_API_URL=${connection.env.CAELARIO_API_URL}`,
30
20
  "--env", `CAELARIO_API_KEY=${apiKey}`,
31
21
  "--",
32
22
  ...launcher,
@@ -41,6 +31,8 @@ export async function installClient(
41
31
  apiUrl = process.env.CAELARIO_API_URL || "https://api.caelario.com",
42
32
  platform = process.platform,
43
33
  spawn = spawnSync,
34
+ resolveClient = resolveClientExecutable,
35
+ configureDesktop = configureClaudeDesktop,
44
36
  openBrowser = openSetupPage,
45
37
  prompt = promptSecret,
46
38
  verifyKey = verifyWorkspaceKey,
@@ -48,26 +40,67 @@ export async function installClient(
48
40
  interactive = Boolean(process.stdin.isTTY && process.stderr.isTTY),
49
41
  } = {},
50
42
  ) {
51
- if (!CLIENTS.has(client)) throw new Error("client must be codex or claude");
43
+ if (!CLIENTS.has(client) && client !== "claude-desktop") throw new Error("client must be codex, claude or claude-desktop");
44
+ write(`Finding ${client === "codex" ? "Codex" : "Claude"}...\n`);
45
+ const executable = resolveClient(client, { platform });
46
+ if (executable.desktop) {
47
+ checkClaudeDesktopConfiguration(executable.configPath);
48
+ write("Found Claude desktop. Connecting without a separate Claude Code CLI.\n");
49
+ }
52
50
  let key = apiKey?.trim();
53
- if (!key) {
54
- write(`${setupInstructions(client)}\n\n`);
55
- if (interactive) {
56
- write("Opening your browser setup page...\n");
57
- openBrowser();
51
+ let setupShown = false;
52
+ let registration;
53
+ if (key) write("Found CAELARIO_API_KEY in your environment.\n");
54
+ while (true) {
55
+ if (!key) {
56
+ if (!setupShown) {
57
+ write(`${setupInstructions(executable.desktop ? "claude-desktop" : client)}\n\n`);
58
+ if (interactive) {
59
+ write("Opening your browser setup page...\n");
60
+ openBrowser();
61
+ }
62
+ setupShown = true;
63
+ }
64
+ if (!interactive) {
65
+ throw new Error(`Open ${SETUP_URL} to create your account and connection key. Run the installer in an interactive terminal, or set CAELARIO_API_KEY in your private MCP configuration.`);
66
+ }
67
+ key = (await prompt("Finish setup in your browser, then paste your connection key here: ")).trim();
68
+ }
69
+ if (!KEY_PATTERN.test(key)) {
70
+ if (!interactive) throw new Error(`The connection key format is invalid. Get your full key at ${SETUP_URL}.`);
71
+ write("That connection key is incomplete or has an invalid format. Paste the full key from browser setup.\n");
72
+ key = "";
73
+ continue;
58
74
  }
59
- key = await prompt("Finish setup in your browser, then paste your connection key here: ");
75
+ // Validate the origin before sending a key, even when setup needs a retry.
76
+ registration = registrationCommand(client === "claude-desktop" ? "claude" : client, key, apiUrl, platform);
77
+ write("Checking your Caelario connection key...\n");
78
+ try {
79
+ await verifyKey(key, apiUrl);
80
+ break;
81
+ } catch (error) {
82
+ if (!(error instanceof ConnectionKeyRejectedError) || !interactive) throw error;
83
+ write("Caelario did not accept that key. Let's connect with a current key from browser setup.\n");
84
+ key = "";
85
+ }
86
+ }
87
+ if (executable.desktop) {
88
+ configureDesktop(key, apiUrl, { configPath: executable.configPath, platform });
89
+ write("Caelario is configured for Claude desktop, including local Code sessions. Quit Claude completely and reopen it, approve the Caelario connection if asked, then ask it to use Caelario.\n");
90
+ return;
60
91
  }
61
- const registration = registrationCommand(client, key, apiUrl, platform);
62
- write("Checking your Caelario connection key...\n");
63
- await verifyKey(key, apiUrl);
64
- const completed = spawn(registration.command, registration.args, {
65
- stdio: "inherit",
92
+ const completed = spawn(executable.command, registration.args, {
93
+ stdio: "pipe",
94
+ encoding: "utf8",
66
95
  windowsHide: true,
67
- shell: platform === "win32",
96
+ timeout: 30_000,
97
+ shell: executable.shell,
68
98
  });
99
+ for (const output of [completed.stdout, completed.stderr]) {
100
+ if (output) write(output.replaceAll(key, "[redacted]"));
101
+ }
69
102
  if (completed.error?.code === "ENOENT") {
70
- throw new Error(`${client === "codex" ? "Codex" : "Claude Code"} CLI was not found. Install it, then run this command again.`);
103
+ throw new Error(`${client === "codex" ? "Codex" : "Claude Code"} was not found. Reopen your terminal and run this command again.`);
71
104
  }
72
105
  if (completed.error) throw new Error("The assistant client could not be started. Check its installation and run this command again.");
73
106
  if (completed.status !== 0) {
@@ -113,7 +146,8 @@ export function printHelp() {
113
146
  "Caelario MCP",
114
147
  "",
115
148
  " npx -y caelario-mcp install codex Register for Codex (user-wide)",
116
- " npx -y caelario-mcp install claude Register for Claude Code (user-wide)",
149
+ " npx -y caelario-mcp install claude Connect Claude Code or detect Claude desktop",
150
+ " npx -y caelario-mcp install claude-desktop Connect Claude desktop explicitly",
117
151
  " npx -y caelario-mcp serve Run the stdio server",
118
152
  "",
119
153
  setupInstructions(),
package/src/onboarding.js CHANGED
@@ -4,7 +4,7 @@ export const SETUP_URL = "https://app.caelario.com/connect";
4
4
  export const SIGNUP_URL = "https://app.caelario.com/sign-up";
5
5
 
6
6
  export function setupInstructions(client = "codex") {
7
- const label = client === "claude" ? "Claude Code" : "Codex";
7
+ const label = client === "claude-desktop" ? "Claude desktop" : client === "claude" ? "Claude Code" : "Codex";
8
8
  return [
9
9
  "Caelario connects social media data to your AI assistant.",
10
10
  "",
@@ -27,6 +27,13 @@ export function openSetupPage() {
27
27
  } catch { /* The printed URL remains usable when a browser cannot be opened. */ }
28
28
  }
29
29
 
30
+ export class ConnectionKeyRejectedError extends Error {
31
+ constructor() {
32
+ super(`Caelario did not accept that key. Open ${SETUP_URL}, copy your full connection key and try again.`);
33
+ this.name = "ConnectionKeyRejectedError";
34
+ }
35
+ }
36
+
30
37
  export async function verifyWorkspaceKey(apiKey, apiUrl) {
31
38
  let response;
32
39
  try {
@@ -39,7 +46,7 @@ export async function verifyWorkspaceKey(apiKey, apiUrl) {
39
46
  throw new Error("Could not reach Caelario to check the key. Check your connection and run the installer again.");
40
47
  }
41
48
  if (response.status === 401 || response.status === 403) {
42
- throw new Error(`Caelario did not accept that key. Open ${SETUP_URL}, copy your full connection key and try again.`);
49
+ throw new ConnectionKeyRejectedError();
43
50
  }
44
51
  if (!response.ok) throw new Error("Caelario could not verify the key right now. Please try again shortly.");
45
52
  const account = await response.json().catch(() => null);