@codeconductorai/harmony-mcp 1.0.17 → 1.0.18

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.17`) 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.18`) 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.17
35
+ claude mcp add harmony -- npx -y @codeconductorai/harmony-mcp@1.0.18
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.17"]
50
+ "args": ["-y", "@codeconductorai/harmony-mcp@1.0.18"]
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.17
61
+ codex mcp add harmony -- npx -y @codeconductorai/harmony-mcp@1.0.18
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.17"]
69
+ args = ["-y", "@codeconductorai/harmony-mcp@1.0.18"]
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.17"]
81
+ "args": ["-y", "@codeconductorai/harmony-mcp@1.0.18"]
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.17"]
98
+ "args": ["-y", "@codeconductorai/harmony-mcp@1.0.18"]
99
99
  }
100
100
  }
101
101
  }
@@ -176,6 +176,12 @@ Given a natural-language query, returns lightweight file path and architectural
176
176
  - `limit` (optional): max results (default 30).
177
177
  - `workspaceId` (optional): target a specific workspace instead of the local project's. Defaults to the local `setup_workspace` workspace.
178
178
 
179
+ ## Observability (OpenObserve)
180
+
181
+ The server ships its own logs, traces, and metrics over OTLP/HTTP using OpenTelemetry, and forwards the active trace id to every request it makes to the harmony backend (as a W3C `traceparent` header plus a plain `X-Trace-Id` header) so backend-side logs can be correlated with the MCP session that triggered them.
182
+
183
+ Telemetry is exported to the harmony backend's `/api/v1/otel/{traces,metrics,logs}` endpoints rather than straight to [OpenObserve](https://openobserve.codeconductor.ai/) — the backend forwards it on to OpenObserve using a server-side-only ingestion credential. This package holds no OpenObserve credential of its own: it authenticates to the backend with whichever Bearer session or workspace token it already uses for every other API call, so nothing extra needs to be configured, and a plain `npx` install never needs (or can leak) an ingestion secret. If neither token is available yet (e.g. before `login`/`setup_workspace`), export calls simply fail unauthenticated against the backend and are logged, without affecting normal server operation.
184
+
179
185
  ## Local development
180
186
 
181
187
  ```bash
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeconductorai/harmony-mcp",
3
- "version": "1.0.17",
3
+ "version": "1.0.18",
4
4
  "type": "module",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -30,6 +30,16 @@
30
30
  "license": "MIT",
31
31
  "dependencies": {
32
32
  "@modelcontextprotocol/sdk": "^1.29.0",
33
+ "@opentelemetry/api": "^1.9.1",
34
+ "@opentelemetry/api-logs": "^0.221.0",
35
+ "@opentelemetry/exporter-logs-otlp-http": "^0.221.0",
36
+ "@opentelemetry/exporter-metrics-otlp-http": "^0.221.0",
37
+ "@opentelemetry/exporter-trace-otlp-http": "^0.221.0",
38
+ "@opentelemetry/resources": "^2.10.0",
39
+ "@opentelemetry/sdk-logs": "^0.221.0",
40
+ "@opentelemetry/sdk-metrics": "^2.10.0",
41
+ "@opentelemetry/sdk-node": "^0.221.0",
42
+ "@opentelemetry/semantic-conventions": "^1.43.0",
33
43
  "archiver": "^7.0.0",
34
44
  "form-data": "^4.0.0",
35
45
  "jose": "^6.2.3",
package/src/deviceAuth.js CHANGED
@@ -1,11 +1,11 @@
1
- import fetch from "node-fetch";
2
1
  import fs from "fs";
3
2
  import os from "os";
4
3
  import path from "path";
5
4
 
6
5
  import { log } from "./log.js";
6
+ import { tracedFetch as fetch } from "./telemetry.js";
7
7
 
8
- const API_URL = (process.env.API_URL || "https://harmony.codeconductor.ai/").replace(/\/+$/, "");
8
+ export const API_URL = (process.env.API_URL || "https://harmony.codeconductor.ai/").replace(/\/+$/, "");
9
9
 
10
10
  let userToken = null;
11
11
  let userTokenExpiresAt = 0;
@@ -3,9 +3,9 @@ import path from "path";
3
3
  import crypto from "crypto";
4
4
  import archiver from "archiver";
5
5
  import FormData from "form-data";
6
- import fetch from "node-fetch";
7
6
 
8
7
  import { log } from "./log.js";
8
+ import { tracedFetch as fetch } from "./telemetry.js";
9
9
  import {
10
10
  getSessionToken,
11
11
  getWorkspaceToken,
package/src/index.js CHANGED
@@ -1,18 +1,22 @@
1
1
  #!/usr/bin/env node
2
+ import "./telemetry.js";
2
3
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
4
 
4
5
  import { log } from "./log.js";
6
+ import { shutdownTelemetry } from "./telemetry.js";
5
7
  import { getCurrentUsername } from "./workspaceIdentity.js";
6
8
  import { startFileWatcher, stopFileWatcher } from "./fileWatcher.js";
7
9
  import { buildMcpServer } from "./server.js";
8
10
 
9
11
  process.on("exit", stopFileWatcher);
10
- process.on("SIGINT", () => {
12
+ process.on("SIGINT", async () => {
11
13
  stopFileWatcher();
14
+ await shutdownTelemetry();
12
15
  process.exit(0);
13
16
  });
14
- process.on("SIGTERM", () => {
17
+ process.on("SIGTERM", async () => {
15
18
  stopFileWatcher();
19
+ await shutdownTelemetry();
16
20
  process.exit(0);
17
21
  });
18
22
 
package/src/log.js CHANGED
@@ -1,12 +1,22 @@
1
1
  import fs from "fs";
2
2
  import os from "os";
3
3
  import path from "path";
4
+ import { logs, SeverityNumber } from "@opentelemetry/api-logs";
4
5
 
5
6
  const LOG_FILE = path.join(os.tmpdir(), "harmony-mcp.log");
6
7
  const logStream = fs.createWriteStream(LOG_FILE, { flags: "a" });
7
8
 
9
+ // No-op until telemetry.js starts the SDK and registers the real LoggerProvider.
10
+ const otelLogger = logs.getLogger("harmony-mcp");
11
+
8
12
  export function log(...args) {
9
- const line = `[${new Date().toISOString()}] ${args.join(" ")}\n`;
13
+ const message = args.join(" ");
14
+ const line = `[${new Date().toISOString()}] ${message}\n`;
10
15
  logStream.write(line);
11
16
  process.stderr.write(line);
17
+ try {
18
+ otelLogger.emit({ severityNumber: SeverityNumber.INFO, body: message });
19
+ } catch {
20
+ // best-effort only — never let telemetry export break local logging
21
+ }
12
22
  }
package/src/server.js CHANGED
@@ -1,10 +1,12 @@
1
1
  import { Server } from "@modelcontextprotocol/sdk/server/index.js";
2
2
  import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
3
3
  import { createRequire } from "module";
4
+ import { SpanStatusCode } from "@opentelemetry/api";
4
5
 
5
6
  const packageJson = createRequire(import.meta.url)("../package.json");
6
7
 
7
8
  import { log } from "./log.js";
9
+ import { tracer, toolCallCounter, toolCallDuration, getActiveTraceId } from "./telemetry.js";
8
10
  import {
9
11
  initiateDeviceLogin,
10
12
  pollDeviceLogin,
@@ -310,10 +312,30 @@ export function buildMcpServer() {
310
312
  if (!handler) {
311
313
  throw new Error(`Unknown tool: ${name}`);
312
314
  }
313
- if (!AUTH_EXEMPT_TOOLS.has(name) && !isAuthenticated(args)) {
314
- return NOT_AUTHENTICATED;
315
- }
316
- return handler(args, extra);
315
+
316
+ return tracer.startActiveSpan(`mcp.tool/${name}`, async (span) => {
317
+ span.setAttribute("mcp.tool.name", name);
318
+ log(`[mcp] trace id ${getActiveTraceId()} for tool call "${name}"`);
319
+ const startedAt = Date.now();
320
+ try {
321
+ if (!AUTH_EXEMPT_TOOLS.has(name) && !isAuthenticated(args)) {
322
+ span.setAttribute("mcp.tool.authenticated", false);
323
+ return NOT_AUTHENTICATED;
324
+ }
325
+ const result = await handler(args, extra);
326
+ if (result?.isError) span.setStatus({ code: SpanStatusCode.ERROR });
327
+ return result;
328
+ } catch (error) {
329
+ span.recordException(error);
330
+ span.setStatus({ code: SpanStatusCode.ERROR, message: error?.message });
331
+ throw error;
332
+ } finally {
333
+ const durationMs = Date.now() - startedAt;
334
+ toolCallDuration.record(durationMs, { "mcp.tool.name": name });
335
+ toolCallCounter.add(1, { "mcp.tool.name": name });
336
+ span.end();
337
+ }
338
+ });
317
339
  });
318
340
 
319
341
  return server;
@@ -0,0 +1,144 @@
1
+ import { createRequire } from "module";
2
+ import fetch from "node-fetch";
3
+ import { diag, DiagLogLevel, trace, context, propagation, metrics, SpanStatusCode } from "@opentelemetry/api";
4
+ import { NodeSDK } from "@opentelemetry/sdk-node";
5
+ import { resourceFromAttributes } from "@opentelemetry/resources";
6
+ import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION } from "@opentelemetry/semantic-conventions";
7
+ import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
8
+ import { OTLPMetricExporter } from "@opentelemetry/exporter-metrics-otlp-http";
9
+ import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
10
+ import { PeriodicExportingMetricReader } from "@opentelemetry/sdk-metrics";
11
+ import { BatchLogRecordProcessor } from "@opentelemetry/sdk-logs";
12
+
13
+ import { log } from "./log.js";
14
+ import { API_URL, getSessionToken, getWorkspaceToken } from "./deviceAuth.js";
15
+ import { readMarker } from "./workspaceMarker.js";
16
+
17
+ const packageJson = createRequire(import.meta.url)("../package.json");
18
+
19
+ const OTLP_BASE = `${API_URL}/api/v1/otel`;
20
+
21
+ async function backendAuthHeaders() {
22
+ const token = (await getSessionToken()) || getWorkspaceToken(readMarker()?.workspaceId);
23
+ return token ? { Authorization: `Bearer ${token}` } : {};
24
+ }
25
+
26
+ diag.setLogger(
27
+ {
28
+ error: (msg, ...args) => log("[otel:error]", msg, ...args),
29
+ warn: (msg, ...args) => log("[otel:warn]", msg, ...args),
30
+ info: () => {},
31
+ debug: () => {},
32
+ verbose: () => {},
33
+ },
34
+ DiagLogLevel.WARN
35
+ );
36
+
37
+ const resource = resourceFromAttributes({
38
+ [ATTR_SERVICE_NAME]: "harmony-mcp",
39
+ [ATTR_SERVICE_VERSION]: packageJson.version,
40
+ });
41
+
42
+ const traceExporter = new OTLPTraceExporter({
43
+ url: `${OTLP_BASE}/traces`,
44
+ headers: backendAuthHeaders,
45
+ });
46
+
47
+ const metricExporter = new OTLPMetricExporter({
48
+ url: `${OTLP_BASE}/metrics`,
49
+ headers: backendAuthHeaders,
50
+ });
51
+
52
+ const logExporter = new OTLPLogExporter({
53
+ url: `${OTLP_BASE}/logs`,
54
+ headers: backendAuthHeaders,
55
+ });
56
+
57
+ const sdk = new NodeSDK({
58
+ resource,
59
+ traceExporter,
60
+ metricReaders: [new PeriodicExportingMetricReader({ exporter: metricExporter, exportIntervalMillis: 30_000 })],
61
+ logRecordProcessors: [new BatchLogRecordProcessor({ exporter: logExporter })],
62
+ });
63
+
64
+ let started = false;
65
+ try {
66
+ sdk.start();
67
+ started = true;
68
+ log(`[telemetry] OpenTelemetry started — exporting via backend proxy at ${OTLP_BASE}`);
69
+ } catch (err) {
70
+ log(`[telemetry] Failed to start OpenTelemetry SDK: ${err?.message || err}`);
71
+ }
72
+
73
+ export async function shutdownTelemetry() {
74
+ if (!started) return;
75
+ try {
76
+ await sdk.shutdown();
77
+ } catch (err) {
78
+ log(`[telemetry] Shutdown error: ${err?.message || err}`);
79
+ }
80
+ }
81
+
82
+ export const tracer = trace.getTracer("harmony-mcp");
83
+ export const meter = metrics.getMeter("harmony-mcp");
84
+
85
+ export const toolCallCounter = meter.createCounter("harmony_mcp.tool_calls", {
86
+ description: "Count of MCP tool invocations",
87
+ });
88
+ export const toolCallDuration = meter.createHistogram("harmony_mcp.tool_call_duration_ms", {
89
+ description: "Duration of MCP tool invocations",
90
+ unit: "ms",
91
+ });
92
+ export const backendRequestDuration = meter.createHistogram("harmony_mcp.backend_request_duration_ms", {
93
+ description: "Duration of HTTP requests to the harmony backend",
94
+ unit: "ms",
95
+ });
96
+ export const backendRequestErrors = meter.createCounter("harmony_mcp.backend_request_errors", {
97
+ description: "Count of failed HTTP requests to the harmony backend",
98
+ });
99
+
100
+ // The trace id of whichever span is active on the current async context, if any.
101
+ export function getActiveTraceId() {
102
+ return trace.getActiveSpan()?.spanContext().traceId;
103
+ }
104
+
105
+ export function injectTraceHeaders(headers = {}) {
106
+ const traceHeaders = {};
107
+ propagation.inject(context.active(), traceHeaders);
108
+ const traceId = getActiveTraceId();
109
+ if (traceId) traceHeaders["X-Trace-Id"] = traceId;
110
+ return { ...headers, ...traceHeaders };
111
+ }
112
+
113
+ export async function tracedFetch(url, options = {}) {
114
+ return tracer.startActiveSpan("harmony.http.request", async (span) => {
115
+ const path = (() => {
116
+ try {
117
+ return new URL(url).pathname;
118
+ } catch {
119
+ return url;
120
+ }
121
+ })();
122
+ span.setAttribute("http.request.method", options.method || "GET");
123
+ span.setAttribute("url.full", url);
124
+ log(`[telemetry] trace id ${getActiveTraceId()} for ${options.method || "GET"} ${path}`);
125
+ const startedAt = Date.now();
126
+ try {
127
+ const response = await fetch(url, { ...options, headers: injectTraceHeaders(options.headers || {}) });
128
+ span.setAttribute("http.response.status_code", response.status);
129
+ if (!response.ok) {
130
+ span.setStatus({ code: SpanStatusCode.ERROR, message: `HTTP ${response.status}` });
131
+ backendRequestErrors.add(1, { "url.path": path, "http.response.status_code": response.status });
132
+ }
133
+ return response;
134
+ } catch (error) {
135
+ span.recordException(error);
136
+ span.setStatus({ code: SpanStatusCode.ERROR, message: error?.message });
137
+ backendRequestErrors.add(1, { "url.path": path });
138
+ throw error;
139
+ } finally {
140
+ backendRequestDuration.record(Date.now() - startedAt, { "url.path": path });
141
+ span.end();
142
+ }
143
+ });
144
+ }