@omnidim-ai/mcp-server 0.2.8 → 0.3.1

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.
@@ -4,17 +4,37 @@ export declare function telemetryStatus(): {
4
4
  disabled: boolean;
5
5
  reason: string;
6
6
  };
7
+ export interface SanitizedError {
8
+ error_class: string;
9
+ error_code: string;
10
+ }
11
+ export declare function sanitizeError(error: unknown): SanitizedError;
7
12
  export declare function emitInstall(): Promise<void>;
8
13
  export declare function emitSessionStart(): Promise<void>;
9
- interface SessionEndPayload {
10
- duration_s: number;
11
- tools_called: Array<{
12
- tool: string;
14
+ export type SetupKeyOutcome = "reused" | "entered" | "rejected_401" | "network_error" | "server_error" | "aborted";
15
+ export declare function emitSetupStarted(): Promise<void>;
16
+ export declare function emitSetupKeyResult(outcome: SetupKeyOutcome): Promise<void>;
17
+ export declare function emitSetupClientResult(client: string, outcome: "installed" | "failed", error?: SanitizedError & {
18
+ exit_code?: number;
19
+ }): Promise<void>;
20
+ export declare function emitSetupFinished(clientsInstalled: number, clientsFailed: number): Promise<void>;
21
+ interface ToolUsage {
22
+ tool: string;
23
+ count: number;
24
+ ok: number;
25
+ errors: Array<{
26
+ code: string;
13
27
  count: number;
14
28
  }>;
15
29
  }
16
- export declare function emitSessionEnd(payload: SessionEndPayload): Promise<void>;
17
- export declare function recordToolCall(name: string): void;
30
+ export interface SessionSummary {
31
+ duration_s: number;
32
+ tools_called: ToolUsage[];
33
+ tool_errors_total: number;
34
+ }
35
+ export declare function recordToolResult(name: string, outcome: string): void;
18
36
  export declare function beginSession(): void;
19
- export declare function endSession(): SessionEndPayload;
37
+ export declare function endSession(): SessionSummary;
38
+ export declare function emitSessionEnd(payload: SessionSummary): Promise<void>;
39
+ export declare function emitSessionCrash(error: unknown): Promise<void>;
20
40
  export {};
@@ -95,29 +95,103 @@ async function send(event, extra = {}) {
95
95
  clearTimeout(timer);
96
96
  }
97
97
  }
98
+ // Reduce any thrown value to two low-cardinality, non-identifying fields.
99
+ // Never returns a message, stack, path, or payload, since those can carry
100
+ // usernames and file paths. Node's documented errno strings (ENOENT,
101
+ // EACCES, ...) and the error constructor name are safe to keep.
102
+ export function sanitizeError(error) {
103
+ if (error && typeof error === "object") {
104
+ const e = error;
105
+ const rawName = typeof e.name === "string" && e.name ? e.name : e.constructor?.name ?? "Error";
106
+ const error_class = /^[A-Za-z][A-Za-z0-9]{0,39}$/.test(rawName) ? rawName : "Error";
107
+ const error_code = typeof e.code === "string" && /^[A-Z][A-Z0-9_]{1,31}$/.test(e.code) ? e.code : "unknown";
108
+ return { error_class, error_code };
109
+ }
110
+ return { error_class: "Error", error_code: "unknown" };
111
+ }
98
112
  export async function emitInstall() {
99
113
  await send("install");
100
114
  }
101
115
  export async function emitSessionStart() {
102
116
  await send("session_start");
103
117
  }
104
- export async function emitSessionEnd(payload) {
105
- await send("session_end", { ...payload });
118
+ export async function emitSetupStarted() {
119
+ await send("setup_started");
120
+ }
121
+ export async function emitSetupKeyResult(outcome) {
122
+ await send("setup_key_result", { outcome });
106
123
  }
107
- const toolCounts = new Map();
124
+ export async function emitSetupClientResult(client, outcome, error) {
125
+ await send("setup_client_result", { client, outcome, ...(error ?? {}) });
126
+ }
127
+ export async function emitSetupFinished(clientsInstalled, clientsFailed) {
128
+ await send("setup_finished", {
129
+ clients_installed: clientsInstalled,
130
+ clients_failed: clientsFailed,
131
+ });
132
+ }
133
+ const toolStats = new Map();
108
134
  let sessionStartMs = null;
109
- export function recordToolCall(name) {
110
- toolCounts.set(name, (toolCounts.get(name) ?? 0) + 1);
135
+ // Guards against one session reporting twice (a crash racing graceful
136
+ // shutdown), which would otherwise log an empty ghost event.
137
+ let terminated = false;
138
+ // outcome is "ok" for a successful call, otherwise a category code
139
+ // ("http_401", "network", "timeout", "validation", "upstream_html",
140
+ // "no_api_key", "unknown"). Never a tool's input or output.
141
+ export function recordToolResult(name, outcome) {
142
+ let stat = toolStats.get(name);
143
+ if (!stat) {
144
+ stat = { count: 0, ok: 0, errors: new Map() };
145
+ toolStats.set(name, stat);
146
+ }
147
+ stat.count += 1;
148
+ if (outcome === "ok") {
149
+ stat.ok += 1;
150
+ }
151
+ else {
152
+ stat.errors.set(outcome, (stat.errors.get(outcome) ?? 0) + 1);
153
+ }
111
154
  }
112
155
  export function beginSession() {
113
156
  sessionStartMs = Date.now();
157
+ terminated = false;
114
158
  void emitSessionStart();
115
159
  }
116
- export function endSession() {
160
+ function drainSession() {
117
161
  const duration_s = sessionStartMs ? Math.round((Date.now() - sessionStartMs) / 1000) : 0;
118
- const tools_called = Array.from(toolCounts.entries()).map(([tool, count]) => ({ tool, count }));
162
+ let tool_errors_total = 0;
163
+ const tools_called = Array.from(toolStats.entries()).map(([tool, stat]) => {
164
+ const errors = Array.from(stat.errors.entries()).map(([code, count]) => {
165
+ tool_errors_total += count;
166
+ return { code, count };
167
+ });
168
+ return { tool, count: stat.count, ok: stat.ok, errors };
169
+ });
119
170
  sessionStartMs = null;
120
- toolCounts.clear();
121
- return { duration_s, tools_called };
171
+ toolStats.clear();
172
+ return { duration_s, tools_called, tool_errors_total };
173
+ }
174
+ export function endSession() {
175
+ return drainSession();
176
+ }
177
+ export async function emitSessionEnd(payload) {
178
+ if (terminated)
179
+ return;
180
+ terminated = true;
181
+ await send("session_end", { ...payload });
182
+ }
183
+ // Fires on a crash so the session still terminates with a record carrying
184
+ // its tool-call summary; a clean session_end never runs on a crash path.
185
+ export async function emitSessionCrash(error) {
186
+ if (terminated)
187
+ return;
188
+ terminated = true;
189
+ const active = sessionStartMs !== null;
190
+ const summary = drainSession();
191
+ await send("session_crash", {
192
+ phase: active ? "runtime" : "startup",
193
+ ...sanitizeError(error),
194
+ ...summary,
195
+ });
122
196
  }
123
197
  //# sourceMappingURL=telemetry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,Y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QAC3B,CAAC,CAAC,CAAC;QACH,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC;IAC5D,CAAC,CAAC,CAAC;IACH,cAAc,GAAG,IAAI,CAAC;IACtB,SAAS,CAAC,KAAK,EAAE,CAAC;IAClB,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,iBAAiB,EAAE,CAAC;AAC3D,CAAC;AAED,MAAM,UAAU,UAAU;IACtB,OAAO,YAAY,EAAE,CAAC;AAC1B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,OAAuB;IACxD,IAAI,UAAU;QAAE,OAAO;IACvB,UAAU,GAAG,IAAI,CAAC;IAClB,MAAM,IAAI,CAAC,aAAa,EAAE,EAAE,GAAG,OAAO,EAAE,CAAC,CAAC;AAC9C,CAAC;AAED,0EAA0E;AAC1E,yEAAyE;AACzE,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,KAAc;IACjD,IAAI,UAAU;QAAE,OAAO;IACvB,UAAU,GAAG,IAAI,CAAC;IAClB,MAAM,MAAM,GAAG,cAAc,KAAK,IAAI,CAAC;IACvC,MAAM,OAAO,GAAG,YAAY,EAAE,CAAC;IAC/B,MAAM,IAAI,CAAC,eAAe,EAAE;QACxB,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;QACrC,GAAG,aAAa,CAAC,KAAK,CAAC;QACvB,GAAG,OAAO;KACb,CAAC,CAAC;AACP,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnidim-ai/mcp-server",
3
- "version": "0.2.8",
3
+ "version": "0.3.1",
4
4
  "description": "Official MCP server for OmniDimension. Drive voice agents, dispatch calls, and manage knowledge bases from Claude, Cursor, Windsurf, and any MCP client.",
5
5
  "type": "module",
6
6
  "main": "build/index.js",
package/src/banner.ts ADDED
@@ -0,0 +1,48 @@
1
+ // Branded "OMNIDIMENSION" wordmark shown at the top of `setup`. The ANSI
2
+ // Shadow art is baked in (generated once with figlet) so the package ships
3
+ // no figlet dependency. OMNI uses the brand cyan, DIMENSION the light slate.
4
+ const OMNI_ROWS = [
5
+ " ██████╗ ███╗ ███╗███╗ ██╗██╗",
6
+ "██╔═══██╗████╗ ████║████╗ ██║██║",
7
+ "██║ ██║██╔████╔██║██╔██╗ ██║██║",
8
+ "██║ ██║██║╚██╔╝██║██║╚██╗██║██║",
9
+ "╚██████╔╝██║ ╚═╝ ██║██║ ╚████║██║",
10
+ " ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═══╝╚═╝",
11
+ ];
12
+ const DIM_ROWS = [
13
+ "██████╗ ██╗███╗ ███╗███████╗███╗ ██╗███████╗██╗ ██████╗ ███╗ ██╗",
14
+ "██╔══██╗██║████╗ ████║██╔════╝████╗ ██║██╔════╝██║██╔═══██╗████╗ ██║",
15
+ "██║ ██║██║██╔████╔██║█████╗ ██╔██╗ ██║███████╗██║██║ ██║██╔██╗ ██║",
16
+ "██║ ██║██║██║╚██╔╝██║██╔══╝ ██║╚██╗██║╚════██║██║██║ ██║██║╚██╗██║",
17
+ "██████╔╝██║██║ ╚═╝ ██║███████╗██║ ╚████║███████║██║╚██████╔╝██║ ╚████║",
18
+ "╚═════╝ ╚═╝╚═╝ ╚═╝╚══════╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═════╝ ╚═╝ ╚═══╝",
19
+ ];
20
+
21
+ export const WORDMARK_WIDTH = OMNI_ROWS[0].length + DIM_ROWS[0].length;
22
+
23
+ const OMNI_RGB: [number, number, number] = [19, 180, 174]; // #13B4AE
24
+ const DIM_RGB: [number, number, number] = [192, 210, 216]; // #C0D2D8
25
+ const OMNI_256 = 37;
26
+ const DIM_256 = 152;
27
+
28
+ function supportsTrueColor(): boolean {
29
+ const ct = (process.env.COLORTERM || "").toLowerCase();
30
+ return ct.includes("truecolor") || ct.includes("24bit");
31
+ }
32
+
33
+ // One colorizer for a block of rows, picking 24-bit or 256-color up front.
34
+ function painter(rgb: [number, number, number], code256: number): (s: string) => string {
35
+ const open = supportsTrueColor()
36
+ ? `\x1b[38;2;${rgb[0]};${rgb[1]};${rgb[2]}m`
37
+ : `\x1b[38;5;${code256}m`;
38
+ return (s) => `${open}${s}\x1b[0m`;
39
+ }
40
+
41
+ // The colored multi-line wordmark, or null when the terminal is too narrow
42
+ // to render it without wrapping (the caller falls back to the compact line).
43
+ export function renderWordmark(columns: number | undefined): string | null {
44
+ if (!columns || columns < WORDMARK_WIDTH + 2) return null;
45
+ const omni = painter(OMNI_RGB, OMNI_256);
46
+ const dimn = painter(DIM_RGB, DIM_256);
47
+ return OMNI_ROWS.map((row, i) => ` ${omni(row)}${dimn(DIM_ROWS[i])}`).join("\n");
48
+ }
package/src/clients.ts ADDED
@@ -0,0 +1,246 @@
1
+ import { execFileSync } from "node:child_process";
2
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
3
+ import { homedir } from "node:os";
4
+ import { dirname, join } from "node:path";
5
+
6
+ import { sanitizeError, type SanitizedError } from "./telemetry.js";
7
+
8
+ const PKG = "@omnidim-ai/mcp-server";
9
+ const NPX_ARGS = ["-y", PKG];
10
+
11
+ // The host paths targets are resolved against. Injected (rather than read
12
+ // from the process at import time) so tests can simulate any OS and a clean
13
+ // machine without touching the real one.
14
+ export interface HostEnv {
15
+ platform: NodeJS.Platform;
16
+ home: string;
17
+ appData: string; // Windows %APPDATA%
18
+ xdgConfig: string; // Linux ~/.config
19
+ }
20
+
21
+ export function currentHostEnv(): HostEnv {
22
+ const home = homedir();
23
+ return {
24
+ platform: process.platform,
25
+ home,
26
+ appData: process.env.APPDATA || join(home, "AppData", "Roaming"),
27
+ xdgConfig: process.env.XDG_CONFIG_HOME || join(home, ".config"),
28
+ };
29
+ }
30
+
31
+ export interface ClientTarget {
32
+ name: string;
33
+ id: string;
34
+ // App is considered installed when this returns true. Keyed off the
35
+ // app's own directory/binary, not its MCP config file: a fresh install
36
+ // has the app but no config file yet, and we create the file ourselves.
37
+ detect: () => boolean;
38
+ install: (apiKey: string) => void;
39
+ }
40
+
41
+ // Carries a sanitized failure category so the setup funnel can report why a
42
+ // client install failed without shipping the raw message (which holds paths).
43
+ class ClientInstallError extends Error {
44
+ readonly errorCode: string;
45
+ readonly errorClass: string;
46
+ readonly exitCode?: number;
47
+ constructor(message: string, errorCode: string, errorClass: string, exitCode?: number) {
48
+ super(message);
49
+ this.name = "ClientInstallError";
50
+ this.errorCode = errorCode;
51
+ this.errorClass = errorClass;
52
+ this.exitCode = exitCode;
53
+ }
54
+ }
55
+
56
+ // Reduce a caught install error to the sanitized fields the funnel reports.
57
+ export function describeInstallError(e: unknown): SanitizedError & { exit_code?: number } {
58
+ if (e instanceof ClientInstallError) {
59
+ return { error_class: e.errorClass, error_code: e.errorCode, exit_code: e.exitCode };
60
+ }
61
+ return sanitizeError(e);
62
+ }
63
+
64
+ // Most clients read `mcpServers`; VS Code reads `servers` and wants an
65
+ // explicit transport `type`. Both take the same npx command shape.
66
+ function mcpServersEntry(apiKey: string): Record<string, unknown> {
67
+ return { command: "npx", args: NPX_ARGS, env: { OMNIDIM_API_KEY: apiKey } };
68
+ }
69
+ function vscodeEntry(apiKey: string): Record<string, unknown> {
70
+ return { type: "stdio", command: "npx", args: NPX_ARGS, env: { OMNIDIM_API_KEY: apiKey } };
71
+ }
72
+
73
+ // Filesystem errno -> a specific, PII-free error category. Lets telemetry say
74
+ // "permission denied" vs "disk full" vs "read-only" instead of one vague code.
75
+ const FS_ERROR_CODES: Record<string, string> = {
76
+ EACCES: "config_permission_denied",
77
+ EPERM: "config_permission_denied",
78
+ EROFS: "config_readonly_fs",
79
+ ENOSPC: "config_no_space",
80
+ };
81
+
82
+ function fsError(e: unknown, fallback: string): ClientInstallError {
83
+ const code = (e as { code?: string }).code;
84
+ const errorCode = (typeof code === "string" && FS_ERROR_CODES[code]) || fallback;
85
+ return new ClientInstallError(
86
+ e instanceof Error ? e.message : String(e),
87
+ errorCode,
88
+ e instanceof Error ? e.name : "Error",
89
+ );
90
+ }
91
+
92
+ // Read a client's existing config. A missing OR empty/whitespace-only file is
93
+ // treated as a fresh `{}` rather than an error: a created-but-unwritten config
94
+ // file is a common state (the cause of "Unexpected end of JSON input"). A file
95
+ // holding valid JSON that isn't an object is also reset, since we can't merge
96
+ // a server map into it. Only genuinely malformed JSON is a hard failure.
97
+ function readConfig(configPath: string): Record<string, unknown> {
98
+ if (!existsSync(configPath)) return {};
99
+ let raw: string;
100
+ try {
101
+ raw = readFileSync(configPath, "utf8");
102
+ } catch (e) {
103
+ throw fsError(e, "config_read_error");
104
+ }
105
+ if (!raw.trim()) return {};
106
+ try {
107
+ const parsed = JSON.parse(raw) as unknown;
108
+ return parsed && typeof parsed === "object" && !Array.isArray(parsed)
109
+ ? (parsed as Record<string, unknown>)
110
+ : {};
111
+ } catch (e) {
112
+ throw new ClientInstallError(
113
+ e instanceof Error ? e.message : String(e),
114
+ "config_invalid_json",
115
+ e instanceof Error ? e.name : "Error",
116
+ );
117
+ }
118
+ }
119
+
120
+ // Merge our server entry into a JSON config under `topKey`, creating the file
121
+ // and parent directory if absent and preserving any other servers already
122
+ // there. Failures surface as a sanitized category for the setup funnel.
123
+ function upsertConfig(configPath: string, topKey: string, entry: Record<string, unknown>): void {
124
+ const config = readConfig(configPath);
125
+ const servers = ((config[topKey] as Record<string, unknown>) ?? {}) as Record<string, unknown>;
126
+ servers.omnidim = entry;
127
+ config[topKey] = servers;
128
+ try {
129
+ mkdirSync(dirname(configPath), { recursive: true });
130
+ writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
131
+ } catch (e) {
132
+ throw fsError(e, "config_write_error");
133
+ }
134
+ }
135
+
136
+ function installClaudeCode(apiKey: string): void {
137
+ try {
138
+ execFileSync("claude", ["mcp", "remove", "omnidim", "--scope", "user"], { stdio: "ignore" });
139
+ } catch {
140
+ // not registered, fine
141
+ }
142
+ try {
143
+ // Name before the variadic -e so commander doesn't gobble it as an env value.
144
+ execFileSync(
145
+ "claude",
146
+ [
147
+ "mcp", "add", "omnidim",
148
+ "--scope", "user",
149
+ "-e", `OMNIDIM_API_KEY=${apiKey}`,
150
+ "--", "npx", "-y", PKG,
151
+ ],
152
+ { stdio: ["ignore", "pipe", "pipe"] },
153
+ );
154
+ } catch (e) {
155
+ const err = e as { stderr?: Buffer; stdout?: Buffer; message: string; code?: string; status?: number };
156
+ const detail = (err.stderr ?? err.stdout ?? Buffer.from("")).toString().trim();
157
+ if (err.code === "ENOENT") {
158
+ throw new ClientInstallError("Claude Code CLI not found on PATH", "claude_cli_not_found", "Error");
159
+ }
160
+ const exitCode = typeof err.status === "number" ? err.status : undefined;
161
+ throw new ClientInstallError(detail || err.message, "claude_cli_error", "Error", exitCode);
162
+ }
163
+ }
164
+
165
+ // Claude Code is present if it has written its config or the CLI resolves.
166
+ function hasClaudeCli(env: HostEnv): boolean {
167
+ if (existsSync(join(env.home, ".claude.json"))) return true;
168
+ try {
169
+ execFileSync("claude", ["--version"], { stdio: "ignore" });
170
+ return true;
171
+ } catch {
172
+ return false;
173
+ }
174
+ }
175
+
176
+ // macOS / Windows app-support dir for Claude Desktop (no official Linux build).
177
+ function claudeDesktopDir(env: HostEnv): string | null {
178
+ if (env.platform === "darwin") {
179
+ return join(env.home, "Library", "Application Support", "Claude");
180
+ }
181
+ if (env.platform === "win32") {
182
+ return join(env.appData, "Claude");
183
+ }
184
+ return null;
185
+ }
186
+
187
+ function vscodeUserDir(env: HostEnv): string {
188
+ if (env.platform === "darwin") {
189
+ return join(env.home, "Library", "Application Support", "Code", "User");
190
+ }
191
+ if (env.platform === "win32") {
192
+ return join(env.appData, "Code", "User");
193
+ }
194
+ return join(env.xdgConfig, "Code", "User");
195
+ }
196
+
197
+ // Resolve the install targets for the given host. Paths differ per platform,
198
+ // so this is computed at call time rather than as a static table.
199
+ export function buildTargets(env: HostEnv = currentHostEnv()): ClientTarget[] {
200
+ const targets: ClientTarget[] = [
201
+ {
202
+ name: "Claude Code",
203
+ id: "claude_code",
204
+ detect: () => hasClaudeCli(env),
205
+ install: installClaudeCode,
206
+ },
207
+ ];
208
+
209
+ const claudeDir = claudeDesktopDir(env);
210
+ if (claudeDir) {
211
+ const configPath = join(claudeDir, "claude_desktop_config.json");
212
+ targets.push({
213
+ name: "Claude Desktop",
214
+ id: "claude_desktop",
215
+ detect: () => existsSync(claudeDir),
216
+ install: (key) => upsertConfig(configPath, "mcpServers", mcpServersEntry(key)),
217
+ });
218
+ }
219
+
220
+ const cursorDir = join(env.home, ".cursor");
221
+ targets.push({
222
+ name: "Cursor",
223
+ id: "cursor",
224
+ detect: () => existsSync(cursorDir),
225
+ install: (key) => upsertConfig(join(cursorDir, "mcp.json"), "mcpServers", mcpServersEntry(key)),
226
+ });
227
+
228
+ const windsurfDir = join(env.home, ".codeium", "windsurf");
229
+ targets.push({
230
+ name: "Windsurf",
231
+ id: "windsurf",
232
+ detect: () => existsSync(windsurfDir),
233
+ install: (key) =>
234
+ upsertConfig(join(windsurfDir, "mcp_config.json"), "mcpServers", mcpServersEntry(key)),
235
+ });
236
+
237
+ const codeUserDir = vscodeUserDir(env);
238
+ targets.push({
239
+ name: "VS Code",
240
+ id: "vscode",
241
+ detect: () => existsSync(dirname(codeUserDir)),
242
+ install: (key) => upsertConfig(join(codeUserDir, "mcp.json"), "servers", vscodeEntry(key)),
243
+ });
244
+
245
+ return targets;
246
+ }
package/src/helpers.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { renderWordmark } from "./banner.js";
2
+
1
3
  export const PACKAGE_NAME = "@omnidim-ai/mcp-server";
2
4
 
3
5
  const bold = (s: string): string => `\x1b[1m${s}\x1b[0m`;
@@ -54,6 +56,14 @@ export async function printAnimatedSetupBanner(): Promise<void> {
54
56
  printSetupBanner();
55
57
  return;
56
58
  }
59
+ // Wide TTY: show the full branded wordmark instead of the spinner line.
60
+ const wordmark = renderWordmark(process.stdout.columns);
61
+ if (wordmark) {
62
+ process.stdout.write("\n" + wordmark + "\n\n");
63
+ process.stdout.write(` ${bold("OmniDimension")} ${dim("·")} ${italic("Voice AI")}\n`);
64
+ process.stdout.write(SUBTITLE + "\n\n");
65
+ return;
66
+ }
57
67
  process.stdout.write("\n");
58
68
  process.stdout.write("\x1b[?25l");
59
69
  try {
@@ -149,3 +159,32 @@ export function trimLargeResponse(data: unknown): { text: string; note?: string
149
159
  note: `[Response truncated. Full size: ${full.length} chars.]`,
150
160
  };
151
161
  }
162
+
163
+ const NAMED_STATUSES = new Set([400, 401, 403, 404, 409, 422, 429, 500, 502, 503]);
164
+
165
+ // Map a thrown tool-call error to a low-cardinality category for telemetry.
166
+ // Duck-typed on the axios error shape so this stays testable without axios.
167
+ // Returns a status/network/timeout category, never a URL, body, or input.
168
+ export function classifyToolError(error: unknown): string {
169
+ if (error && typeof error === "object") {
170
+ const e = error as {
171
+ isAxiosError?: boolean;
172
+ code?: unknown;
173
+ name?: unknown;
174
+ response?: { status?: unknown };
175
+ };
176
+ if (e.name === "ZodError") return "validation";
177
+ if (e.isAxiosError) {
178
+ const status = e.response?.status;
179
+ if (typeof status === "number") {
180
+ if (NAMED_STATUSES.has(status)) return `http_${status}`;
181
+ if (status >= 500) return "http_5xx";
182
+ if (status >= 400) return "http_4xx";
183
+ return `http_${status}`;
184
+ }
185
+ if (e.code === "ECONNABORTED" || e.code === "ETIMEDOUT") return "timeout";
186
+ return "network";
187
+ }
188
+ }
189
+ return "unknown";
190
+ }
package/src/index.ts CHANGED
@@ -3,12 +3,12 @@
3
3
  * OmniDimension MCP server.
4
4
  */
5
5
  import { readApiKey } from "./credentials.js";
6
- import { isInteractive, printInteractiveHelp, startupBanner, trimLargeResponse } from "./helpers.js";
6
+ import { classifyToolError, isInteractive, printInteractiveHelp, startupBanner, trimLargeResponse } from "./helpers.js";
7
7
 
8
8
 
9
9
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";
10
10
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
11
- import { beginSession, endSession, emitSessionEnd, recordToolCall } from "./telemetry.js";
11
+ import { beginSession, emitSessionCrash, emitSessionEnd, endSession, recordToolResult } from "./telemetry.js";
12
12
  import {
13
13
  CallToolRequestSchema,
14
14
  ListToolsRequestSchema,
@@ -783,6 +783,7 @@ async function executeApiTool(
783
783
  const argsToParse = (typeof toolArgs === 'object' && toolArgs !== null) ? toolArgs : {};
784
784
  validatedArgs = zodSchema.parse(argsToParse);
785
785
  } catch (error: unknown) {
786
+ recordToolResult(toolName, 'validation');
786
787
  if (error instanceof ZodError) {
787
788
  const validationErrorMessage = `Invalid arguments for tool '${toolName}': ${error.errors.map(e => `${e.path.join('.')} (${e.code}): ${e.message}`).join(', ')}`;
788
789
  return { content: [{ type: 'text', text: validationErrorMessage }] };
@@ -964,6 +965,7 @@ async function executeApiTool(
964
965
  }
965
966
  }
966
967
  else if (definition.securityRequirements?.length > 0) {
968
+ recordToolResult(toolName, 'no_api_key');
967
969
  return {
968
970
  content: [{
969
971
  type: 'text',
@@ -1026,16 +1028,18 @@ async function executeApiTool(
1026
1028
  }
1027
1029
 
1028
1030
  // Return formatted response
1029
- return {
1030
- content: [
1031
- {
1032
- type: "text",
1033
- text: `API Response (Status: ${response.status}):\n${responseText}`
1034
- }
1035
- ],
1031
+ recordToolResult(toolName, 'ok');
1032
+ return {
1033
+ content: [
1034
+ {
1035
+ type: "text",
1036
+ text: `API Response (Status: ${response.status}):\n${responseText}`
1037
+ }
1038
+ ],
1036
1039
  };
1037
1040
 
1038
1041
  } catch (error: unknown) {
1042
+ recordToolResult(toolName, classifyToolError(error));
1039
1043
  // Handle errors during execution
1040
1044
  let errorMessage: string;
1041
1045
 
@@ -1083,6 +1087,7 @@ async function main() {
1083
1087
  console.error(startupBanner(SERVER_VERSION, toolDefinitionMap.size));
1084
1088
  beginSession();
1085
1089
  } catch (error) {
1090
+ try { await emitSessionCrash(error); } catch { /* telemetry must never mask the crash */ }
1086
1091
  console.error("Error during server startup:", error);
1087
1092
  process.exit(1);
1088
1093
  }
@@ -1105,8 +1110,22 @@ async function cleanup() {
1105
1110
  process.on('SIGINT', cleanup);
1106
1111
  process.on('SIGTERM', cleanup);
1107
1112
 
1113
+ // A crash never runs the graceful-shutdown path, so flush a session_crash
1114
+ // (with the session's tool-call summary) before exiting.
1115
+ process.on('uncaughtException', async (error) => {
1116
+ try { await emitSessionCrash(error); } catch { /* never mask the crash */ }
1117
+ console.error("Uncaught exception:", error);
1118
+ process.exit(1);
1119
+ });
1120
+ process.on('unhandledRejection', async (reason) => {
1121
+ try { await emitSessionCrash(reason); } catch { /* never mask the crash */ }
1122
+ console.error("Unhandled rejection:", reason);
1123
+ process.exit(1);
1124
+ });
1125
+
1108
1126
  // Start the server
1109
- main().catch((error) => {
1127
+ main().catch(async (error) => {
1128
+ try { await emitSessionCrash(error); } catch { /* never mask the crash */ }
1110
1129
  console.error("Fatal error in main execution:", error);
1111
1130
  process.exit(1);
1112
1131
  });