@codeconductorai/harmony-mcp 1.0.26 → 1.0.27

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
@@ -27,12 +27,12 @@ Re-run `node -v` afterwards to confirm before continuing.
27
27
 
28
28
  ## Installation
29
29
 
30
- The server is published as `@codeconductorai/harmony-mcp` and run via `npx`, so no local build step is required. The commands below pin an exact version (`@1.0.26`) rather than a floating tag — this lets `npx` reuse its local cache instead of re-resolving the package from the registry on every agent startup, which otherwise makes MCP initialization noticeably slower (and occasionally hang). Bump the pinned version deliberately when you want to upgrade.
30
+ The server is published as `@codeconductorai/harmony-mcp` and run via `npx`, so no local build step is required. The commands below pin an exact version (`@1.0.27`) rather than a floating tag — this lets `npx` reuse its local cache instead of re-resolving the package from the registry on every agent startup, which otherwise makes MCP initialization noticeably slower (and occasionally hang). Bump the pinned version deliberately when you want to upgrade.
31
31
 
32
32
  ### Claude Code
33
33
 
34
34
  ```bash
35
- claude mcp add harmony -- npx -y @codeconductorai/harmony-mcp@1.0.26
35
+ claude mcp add harmony -- npx -y @codeconductorai/harmony-mcp@1.0.27
36
36
  ```
37
37
 
38
38
  ### Antigravity
@@ -47,7 +47,7 @@ Open **MCP Servers → Manage MCP Servers → View raw config** from the agent p
47
47
  "mcpServers": {
48
48
  "harmony": {
49
49
  "command": "npx",
50
- "args": ["-y", "@codeconductorai/harmony-mcp@1.0.26"]
50
+ "args": ["-y", "@codeconductorai/harmony-mcp@1.0.27"]
51
51
  }
52
52
  }
53
53
  }
@@ -58,7 +58,7 @@ Restart Antigravity (or reload MCP servers) after saving.
58
58
  ### Codex CLI
59
59
 
60
60
  ```bash
61
- codex mcp add harmony -- npx -y @codeconductorai/harmony-mcp@1.0.26
61
+ codex mcp add harmony -- npx -y @codeconductorai/harmony-mcp@1.0.27
62
62
  ```
63
63
 
64
64
  This writes the entry to `~/.codex/config.toml`. To add it by hand instead:
@@ -66,7 +66,7 @@ This writes the entry to `~/.codex/config.toml`. To add it by hand instead:
66
66
  ```toml
67
67
  [mcp_servers.harmony]
68
68
  command = "npx"
69
- args = ["-y", "@codeconductorai/harmony-mcp@1.0.26"]
69
+ args = ["-y", "@codeconductorai/harmony-mcp@1.0.27"]
70
70
  ```
71
71
 
72
72
  ### Aria
@@ -78,7 +78,7 @@ In the Aria Code panel, click the settings icon → **MCP Servers**, then scroll
78
78
  "mcpServers": {
79
79
  "harmony": {
80
80
  "command": "npx",
81
- "args": ["-y", "@codeconductorai/harmony-mcp@1.0.26"]
81
+ "args": ["-y", "@codeconductorai/harmony-mcp@1.0.27"]
82
82
  }
83
83
  }
84
84
  }
@@ -95,7 +95,7 @@ Any client that reads a `command`/`args` style config (e.g. Claude Desktop's `cl
95
95
  "mcpServers": {
96
96
  "harmony": {
97
97
  "command": "npx",
98
- "args": ["-y", "@codeconductorai/harmony-mcp@1.0.26"]
98
+ "args": ["-y", "@codeconductorai/harmony-mcp@1.0.27"]
99
99
  }
100
100
  }
101
101
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeconductorai/harmony-mcp",
3
- "version": "1.0.26",
3
+ "version": "1.0.27",
4
4
  "type": "module",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -347,18 +347,6 @@ export async function callHarmonyPathBetween(args, workspaceId) {
347
347
  return body;
348
348
  }
349
349
 
350
- // An empty list is ambiguous (no matches vs. index not ready vs. failed query) — flag it.
351
- const EMPTY_LIST_PATTERN = /^\s*<List\s*\/?>\s*(<\/List>\s*)?$/i;
352
- const EMPTY_HITS_PATTERN = /<Hits\s*\/>|<Hits>\s*<\/Hits>/i;
353
-
354
- export function annotateIfEmptyList(toolName, body) {
355
- if (!EMPTY_LIST_PATTERN.test(body) && !EMPTY_HITS_PATTERN.test(body)) return body;
356
- return `${body}\n\n` +
357
- `[harmony-mcp note: ${toolName} returned an empty result. The backend does not distinguish ` +
358
- `"no matches" from "index not ready" or a silently failed query here — if this is unexpected, ` +
359
- `verify with local search (rg/grep) rather than concluding nothing exists.]`;
360
- }
361
-
362
350
  // POST /api/v1/index/files — used by the file watcher for incremental updates.
363
351
  export async function sendFileUpdate(filePath, workspaceId, language, buildTool) {
364
352
  try {
package/src/log.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import fs from "fs";
2
2
  import os from "os";
3
3
  import path from "path";
4
+ import { randomUUID } from "crypto";
4
5
  import { logs, SeverityNumber } from "@opentelemetry/api-logs";
5
6
 
6
7
  const LOG_FILE = path.join(os.tmpdir(), "harmony-mcp.log");
@@ -9,14 +10,75 @@ const logStream = fs.createWriteStream(LOG_FILE, { flags: "a" });
9
10
  // No-op until telemetry.js starts the SDK and registers the real LoggerProvider.
10
11
  const otelLogger = logs.getLogger("harmony-mcp");
11
12
 
12
- export function log(...args) {
13
- const message = args.join(" ");
14
- const line = `[${new Date().toISOString()}] ${message}\n`;
13
+ // Groups one server process's records together in OpenObserve.
14
+ export const SESSION_ID = randomUUID();
15
+
16
+ // The log backend is for inspecting what happened, not for storing payloads; the local copy is
17
+ // read by eye, so it is cut harder still.
18
+ const MAX_ATTR_CHARS = Number(process.env.HARMONY_LOG_MAX_ATTR_CHARS) || 8000;
19
+ const MAX_LOCAL_ATTR_CHARS = 300;
20
+
21
+ function truncate(value, limit) {
22
+ if (typeof value !== "string" || value.length <= limit) return value;
23
+ return `${value.slice(0, limit)}…[truncated ${value.length - limit} chars]`;
24
+ }
25
+
26
+ // OTLP carries primitives reliably and little else, so anything richer is JSON-encoded here
27
+ // rather than left for the exporter to drop silently.
28
+ function normalizeAttributes(attributes) {
29
+ const out = {};
30
+ for (const [key, value] of Object.entries(attributes || {})) {
31
+ if (value === undefined || value === null) continue;
32
+ let normalized = value;
33
+ if (typeof value === "object") {
34
+ try {
35
+ normalized = JSON.stringify(value);
36
+ } catch {
37
+ normalized = String(value);
38
+ }
39
+ } else if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") {
40
+ normalized = String(value);
41
+ }
42
+ out[key] = truncate(normalized, MAX_ATTR_CHARS);
43
+ }
44
+ return out;
45
+ }
46
+
47
+ function writeLocal(line) {
15
48
  logStream.write(line);
16
49
  process.stderr.write(line);
50
+ }
51
+
52
+ export function log(...args) {
53
+ const message = args.join(" ");
54
+ writeLocal(`[${new Date().toISOString()}] ${message}\n`);
17
55
  try {
18
56
  otelLogger.emit({ severityNumber: SeverityNumber.INFO, body: message });
19
57
  } catch {
20
58
  // best-effort only — never let telemetry export break local logging
21
59
  }
22
60
  }
61
+
62
+ // Structured counterpart to log(): attributes become queryable fields in OpenObserve instead of
63
+ // text to be grepped, and the active span stamps the record with its trace id.
64
+ export function logEvent(eventName, attributes = {}, { severity = SeverityNumber.INFO, summary } = {}) {
65
+ const body = summary || eventName;
66
+ const attrs = normalizeAttributes({
67
+ "event.name": eventName,
68
+ "session.id": SESSION_ID,
69
+ ...attributes,
70
+ });
71
+
72
+ const local = Object.fromEntries(
73
+ Object.entries(attrs).map(([key, value]) => [key, truncate(value, MAX_LOCAL_ATTR_CHARS)])
74
+ );
75
+ writeLocal(`[${new Date().toISOString()}] [${eventName}] ${body} ${JSON.stringify(local)}\n`);
76
+
77
+ try {
78
+ otelLogger.emit({ severityNumber: severity, body, attributes: attrs });
79
+ } catch {
80
+ // best-effort only — never let telemetry export break local logging
81
+ }
82
+ }
83
+
84
+ export { SeverityNumber };
package/src/server.js CHANGED
@@ -5,7 +5,7 @@ import { SpanStatusCode } from "@opentelemetry/api";
5
5
 
6
6
  const packageJson = createRequire(import.meta.url)("../package.json");
7
7
 
8
- import { log } from "./log.js";
8
+ import { log, logEvent, SESSION_ID, SeverityNumber } from "./log.js";
9
9
  import { tracer, toolCallCounter, toolCallDuration, getActiveTraceId } from "./telemetry.js";
10
10
  import {
11
11
  initiateDeviceLogin,
@@ -16,7 +16,7 @@ import {
16
16
  minSecondsBeforeConfirm,
17
17
  getWorkspaceToken,
18
18
  } from "./deviceAuth.js";
19
- import { getGitCommitHash, getProjectName } from "./repoIdentity.js";
19
+ import { getGitBranch, getGitCommitHash, getProjectName } from "./repoIdentity.js";
20
20
  import { getCurrentUsername, REPO_ID, REPO_IDENTITY } from "./workspaceIdentity.js";
21
21
  import { readMarker, writeMarker } from "./workspaceMarker.js";
22
22
  import { startFileWatcher, isFileWatcherActive } from "./fileWatcher.js";
@@ -25,7 +25,6 @@ import {
25
25
  pollWorkspaceStatus,
26
26
  callHarmonySearchEndpoint,
27
27
  callHarmonyPathBetween,
28
- annotateIfEmptyList,
29
28
  } from "./harmonyClient.js";
30
29
  import { buildServerInstructions } from "./serverInstructions.js";
31
30
  import { TOOLS } from "./toolSchemas.js";
@@ -270,13 +269,15 @@ function makeSearchHandler(endpointPath, toolName) {
270
269
  return async (args) => {
271
270
  const workspaceId = resolveWorkspaceId(args);
272
271
  const body = await callHarmonySearchEndpoint(endpointPath, args, workspaceId);
273
- return textContent(annotateIfEmptyList(toolName, body));
272
+ log(`[${toolName}] response ${body.length} chars`);
273
+ return textContent(body);
274
274
  };
275
275
  }
276
276
 
277
277
  async function handlePathBetween(args) {
278
278
  const workspaceId = resolveWorkspaceId(args);
279
279
  const body = await callHarmonyPathBetween(args, workspaceId);
280
+ log(`[path_between] response ${body.length} chars`);
280
281
  return textContent(body);
281
282
  }
282
283
 
@@ -293,6 +294,94 @@ const TOOL_HANDLERS = {
293
294
 
294
295
  const AUTH_EXEMPT_TOOLS = new Set(["login", "confirm_login", "setup_workspace"]);
295
296
 
297
+ // Every tool call emits exactly one structured log record — mcp.tool.response, or mcp.tool.error
298
+ // when the handler throws — so a call can be reconstructed from OpenObserve without the local log
299
+ // file. Attribute names mirror the span attributes so a record and its trace line up.
300
+
301
+ // Max characters of the tool's own output kept on the log record. The full response still goes to
302
+ // the agent — this only bounds what is shipped to the log backend.
303
+ const MAX_LOGGED_RESPONSE_CHARS = Number(process.env.HARMONY_LOG_RESPONSE_CHARS) || 4000;
304
+
305
+ // Never throws: logging must not be able to fail a tool call that otherwise succeeded.
306
+ function workspaceIdForLog(args) {
307
+ try {
308
+ return args?.workspaceId || readMarker()?.workspaceId;
309
+ } catch {
310
+ return undefined;
311
+ }
312
+ }
313
+
314
+ // The agent-supplied intent behind the call, whatever the tool names it — path_between has no
315
+ // single prompt field, so its two endpoints stand in for one.
316
+ function userPromptForLog(args) {
317
+ if (typeof args?.prompt === "string") return args.prompt;
318
+ if (args?.from && args?.to) return `${args.from} → ${args.to}`;
319
+ return undefined;
320
+ }
321
+
322
+ function responseTextForLog(result) {
323
+ const parts = Array.isArray(result?.content) ? result.content : [];
324
+ return parts
325
+ .filter((part) => part?.type === "text" && typeof part.text === "string")
326
+ .map((part) => part.text)
327
+ .join("\n");
328
+ }
329
+
330
+ // Arguments minus the prompt, which is logged on its own field.
331
+ function toolArgsForLog(args) {
332
+ const { prompt, from, to, ...rest } = args || {};
333
+ return Object.keys(rest).length ? rest : undefined;
334
+ }
335
+
336
+ function baseToolLogAttributes(name, args) {
337
+ return {
338
+ "mcp.tool.name": name,
339
+ "mcp.workspace.id": workspaceIdForLog(args),
340
+ "mcp.tool.prompt": userPromptForLog(args),
341
+ "mcp.tool.arguments": toolArgsForLog(args),
342
+ "mcp.server.version": packageJson.version,
343
+ "trace.id": getActiveTraceId(),
344
+ "session.id": SESSION_ID,
345
+ "user.name": getCurrentUsername(),
346
+ "repo.id": REPO_ID,
347
+ "project.name": getProjectName(),
348
+ "vcs.branch": getGitBranch(),
349
+ "vcs.commit": getGitCommitHash(),
350
+ };
351
+ }
352
+
353
+ function logToolResponse(name, args, result, durationMs) {
354
+ const responseText = responseTextForLog(result);
355
+ const isError = result?.isError === true;
356
+ logEvent("mcp.tool.response", {
357
+ ...baseToolLogAttributes(name, args),
358
+ "mcp.tool.status": isError ? "error" : "ok",
359
+ "mcp.tool.is_error": isError,
360
+ "mcp.tool.duration_ms": durationMs,
361
+ "mcp.tool.response": responseText.slice(0, MAX_LOGGED_RESPONSE_CHARS),
362
+ "mcp.tool.response.chars": responseText.length,
363
+ "mcp.tool.response.truncated": responseText.length > MAX_LOGGED_RESPONSE_CHARS,
364
+ }, {
365
+ severity: isError ? SeverityNumber.ERROR : SeverityNumber.INFO,
366
+ summary: `tool ${name} ${isError ? "returned an error" : "responded"} in ${durationMs}ms`,
367
+ });
368
+ }
369
+
370
+ function logToolError(name, args, error, durationMs) {
371
+ logEvent("mcp.tool.error", {
372
+ ...baseToolLogAttributes(name, args),
373
+ "mcp.tool.status": "exception",
374
+ "mcp.tool.is_error": true,
375
+ "mcp.tool.duration_ms": durationMs,
376
+ "error.type": error?.name || "Error",
377
+ "error.message": error?.message || String(error),
378
+ "error.stack": error?.stack,
379
+ }, {
380
+ severity: SeverityNumber.ERROR,
381
+ summary: `tool ${name} threw after ${durationMs}ms: ${error?.message || error}`,
382
+ });
383
+ }
384
+
296
385
  // Build the MCP server: tool listing, and the tools/call dispatcher.
297
386
  export function buildMcpServer() {
298
387
  const server = new Server(
@@ -313,22 +402,31 @@ export function buildMcpServer() {
313
402
 
314
403
  return tracer.startActiveSpan(`mcp.tool/${name}`, async (span) => {
315
404
  span.setAttribute("mcp.tool.name", name);
405
+ const workspaceId = workspaceIdForLog(args);
406
+ const userPrompt = userPromptForLog(args);
407
+ if (workspaceId) span.setAttribute("mcp.workspace.id", workspaceId);
408
+ if (userPrompt) span.setAttribute("mcp.tool.prompt", userPrompt);
316
409
  log(`[mcp] trace id ${getActiveTraceId()} for tool call "${name}"`);
317
410
  const startedAt = Date.now();
411
+ let result;
318
412
  try {
319
413
  if (!AUTH_EXEMPT_TOOLS.has(name) && !isAuthenticated(args)) {
320
414
  span.setAttribute("mcp.tool.authenticated", false);
321
- return NOT_AUTHENTICATED;
415
+ result = NOT_AUTHENTICATED;
416
+ return result;
322
417
  }
323
- const result = await handler(args, extra);
418
+ result = await handler(args, extra);
324
419
  if (result?.isError) span.setStatus({ code: SpanStatusCode.ERROR });
325
420
  return result;
326
421
  } catch (error) {
327
422
  span.recordException(error);
328
423
  span.setStatus({ code: SpanStatusCode.ERROR, message: error?.message });
424
+ logToolError(name, args, error, Date.now() - startedAt);
329
425
  throw error;
330
426
  } finally {
331
427
  const durationMs = Date.now() - startedAt;
428
+ // A thrown call already logged mcp.tool.error above; only responses land here.
429
+ if (result) logToolResponse(name, args, result, durationMs);
332
430
  toolCallDuration.record(durationMs, { "mcp.tool.name": name });
333
431
  toolCallCounter.add(1, { "mcp.tool.name": name });
334
432
  span.end();
@@ -84,20 +84,7 @@ export const TOOLS = [
84
84
  "each time one arises, not just once. Whenever you do fall back to locate, don't " +
85
85
  "discard what this call already found: carry its matched symbols, identifiers, and file paths forward " +
86
86
  "and combine them with the user's original query to build that tool's input, rather than re-issuing " +
87
- "the raw query alone.\n\n" +
88
- "RESPONSE SHAPE: the XML response has two separate top-level parts. <Hits><Hit>...</Hit></Hits> is the " +
89
- "location index — each Hit's <codeSnippet> is a compact table of contents for that file (one line per " +
90
- "symbol: decorators, kind, name, and its exact lines{start:end} range), and <lineNumbers> pins the " +
91
- "specific symbol this Hit matched to its own exact range. NEITHER field contains real source lines. " +
92
- "Once you've decided which hit(s) actually matter, use your own file-read tool on the given file path " +
93
- "and line range to see the real code — do not answer the user's question from <codeSnippet> alone, " +
94
- "and never present a lines{a:b} header line as if it were the method body. The sibling " +
95
- "<harmony_telemetry> block (filesBundledCount, graphEdgesResolved, processingTimeMs, " +
96
- "estimatedSecondsSaved, estimatedLoopsBypassed, estimatedTokensSaved) is just an operational efficiency " +
97
- "snapshot of the search itself — not a search result and not code context. Never merge, count, or cite " +
98
- "<harmony_telemetry> fields as if they were part of <Hits>. If you mention telemetry at all, present it " +
99
- "separately and clearly labeled (e.g. as a short aside/footnote about how the search performed), and " +
100
- "only when it's actually relevant to what the user asked — don't surface it by default on every call.",
87
+ "the raw query alone.",
101
88
  inputSchema: {
102
89
  type: "object",
103
90
  properties: {
@@ -125,7 +112,7 @@ export const TOOLS = [
125
112
  description:
126
113
  "Given a natural language query or exact identifier, returns ultra-light symbol coordinate anchors " +
127
114
  "(file path, symbol name, symbol kind/type, whether it's a definition, line numbers, primary role) — " +
128
- "no code snippets or documentation. Use this to find WHICH FILE(S) and exact line(s) to look at or " +
115
+ "plus the declaration's own decorator — never source code. Use this to find WHICH FILE(S) and exact line(s) to look at or " +
129
116
  "edit for a task, e.g. every occurrence of a name across the codebase, or (scoped with file_path) " +
130
117
  "exact line numbers within a file you already know. It does not return full file content — Read() the " +
131
118
  "file once you have the line numbers if you need surrounding context beyond what the anchor tells you. " +