@codeconductorai/harmony-mcp 1.0.23 → 1.0.25

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.23`) 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.25`) 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.23
35
+ claude mcp add harmony -- npx -y @codeconductorai/harmony-mcp@1.0.25
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.23"]
50
+ "args": ["-y", "@codeconductorai/harmony-mcp@1.0.25"]
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.23
61
+ codex mcp add harmony -- npx -y @codeconductorai/harmony-mcp@1.0.25
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.23"]
69
+ args = ["-y", "@codeconductorai/harmony-mcp@1.0.25"]
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.23"]
81
+ "args": ["-y", "@codeconductorai/harmony-mcp@1.0.25"]
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.23"]
98
+ "args": ["-y", "@codeconductorai/harmony-mcp@1.0.25"]
99
99
  }
100
100
  }
101
101
  }
@@ -108,7 +108,7 @@ After adding the server and restarting your client:
108
108
  1. **`setup_workspace`** — registers the current project (`language` and `buildTool` required the first time) and fully indexes it (zips and uploads the codebase) in one call. Call this first, even before logging in: some backend deployments authenticate the workspace internally with no login involved at all, so this can succeed on its own. It's idempotent, so calling it again once setup and indexing have completed is a cheap no-op; if it fails partway, calling it again retries just the incomplete step. Once indexing succeeds, a background file watcher pushes incremental updates to the backend as you edit files.
109
109
  2. If `setup_workspace` (or any tool below) fails with a "not authenticated" error, this deployment requires login: call **`login`**, which starts a device-flow login and returns a URL to open in your browser.
110
110
  3. Finish logging in, then tell the agent you're done so it can call **`confirm_login`** to complete authentication. The session is cached at `~/.harmony-mcp/session.json`, so you won't need to log in again until it expires. Call `setup_workspace` again afterward.
111
- 4. Use **`context_search`** first to pull relevant code context for a prompt — it's Harmony's newest, best-ranked search endpoint, always available as the default entry point for every discovery need in a task, and takes precedence over the others below. Fall back to **`locate`**, **`search_code_context`**, **`find_files`**, or **`get_context_bundle`** only if it comes up short or you need one of their specialized output shapes — and when you do, feed the fallback tool a combination of the user's original query and the symbols/identifiers/file paths `context_search` already surfaced, not the raw query on its own.
111
+ 4. Use **`context_search`** first to pull relevant code context for a prompt — it's Harmony's newest, best-ranked search endpoint, always available as the default entry point for every discovery need in a task, and takes precedence over **`locate`** below. Fall back to `locate` only if `context_search` comes up short or you need its line-number-only anchors — and when you do, feed it a combination of the user's original query and the symbols/identifiers/file paths `context_search` already surfaced, not the raw query on its own. For a question that's inherently about a call relationship or a whole subsystem (not "find me the code for X"), reach directly for **`explain_symbol`**, **`path_between`**, or **`explain_subsystem`** instead of routing through `context_search` first.
112
112
 
113
113
  Workspace state (workspace ID, language, build tool, setup/upload status) is cached in a `.harmony_workspace.json` marker file in the project root.
114
114
 
@@ -134,20 +134,17 @@ Registers the current project as a workspace on the backend and fully indexes it
134
134
 
135
135
  Every workspace is tagged with a scheme-aware `repoId`, surfaced in the response as `repoId`/`repoIdScheme`: `git_url:<host/org/repo>` (normalized origin remote URL — the common case), falling back to `git_commit:<root sha>` (Git repo with no remote), `artifact:<ecosystem>:<name>` (no `.git` at all — read from `pom.xml`/`package.json`/`go.mod`/`Cargo.toml`/`pyproject.toml`), or `dir:<folder name>` as a last resort.
136
136
 
137
- ### `get_context_bundle`
138
- Retrieves a ranked XML context bundle of the most relevant code for a prompt — broader contextual understanding for a task or question, not a specific edit location.
139
- - `prompt` (required): natural-language question or instruction.
140
- - `workspaceId` (optional): target a specific workspace instead of the local project's. Defaults to the local `setup_workspace` workspace.
141
-
142
137
  ### `context_search`
143
138
  PREFERRED FIRST CHOICE for any code discovery/comprehension need — Harmony's newest and best-ranked
144
139
  search endpoint. Given a natural-language query or exact identifier, returns ranked matching symbols
145
- with their code snippets, file paths, and relevance. Takes precedence over `locate`,
146
- `search_code_context`, `find_files`, and `get_context_bundle`; only fall back to one of those if
147
- `context_search`'s result is empty/insufficient or you specifically need one of their specialized
148
- output shapes (e.g. `locate`'s line-number-only anchors for a targeted edit). Treat it as the
140
+ as structural facts and precise file:line locations, deliberately without embedded source code.
141
+ Takes precedence over `locate`; only fall back to it if
142
+ `context_search`'s result is empty/insufficient or you specifically need its line-number-only
143
+ anchors for a targeted edit. For a call-relationship or whole-subsystem question, reach directly for
144
+ `explain_symbol`/`path_between`/`explain_subsystem` instead — don't route through `context_search`
145
+ first. Treat it as the
149
146
  always-on default entry point for every new discovery/comprehension need that comes up during a
150
- task — call it again each time, not just once. When a fallback tool is used afterward, its input
147
+ task — call it again each time, not just once. When falling back to `locate` afterward, its input
151
148
  should combine the user's original query with the symbols/identifiers/file paths this call already
152
149
  surfaced, rather than repeating the same raw query unchanged.
153
150
  - `prompt` (required): natural-language query or exact identifier to find context for.
@@ -162,18 +159,22 @@ Given a natural-language query or exact identifier, returns lightweight symbol c
162
159
  - `limit` (optional): max results (default 40); the result list is never padded to this size.
163
160
  - `workspaceId` (optional): target a specific workspace instead of the local project's. Defaults to the local `setup_workspace` workspace.
164
161
 
165
- ### `search_code_context`
166
- Given a natural-language query, returns matching symbols along with their code snippets, documentation, and decorators. Use this to understand or explain how something works, not to pinpoint an edit (use `locate` for that).
167
- - `prompt` (required): what to find context for.
168
- - `file_path` (optional): path substring to restrict results to a subdirectory, module, or specific file.
169
- - `limit` (optional): max results (default 15).
162
+ ### `explain_symbol`
163
+ Given an exact symbol name (method, function, or class), returns what it's connected to in the persisted call graph: which symbols call it, which symbols it calls, and any call targets that couldn't be confidently resolved to a single definition. Use this to understand a symbol's role and blast radius before changing it, or to answer "who calls X" / "what does X call" directly, without falling back to reading every file that might reference it — this is the highest-leverage tool in this set for that shape of question.
164
+ - `prompt` (required): the exact symbol name to explain.
165
+ - `file_path` (optional): path substring narrowing which definition to use when the name alone is ambiguous (e.g. a common interface-method name implemented by hundreds of classes).
170
166
  - `workspaceId` (optional): target a specific workspace instead of the local project's. Defaults to the local `setup_workspace` workspace.
171
167
 
172
- ### `find_files`
173
- Given a natural-language query, returns lightweight file path and architectural role/tag matches — no symbols or code content. Use this for broad file/module discovery (e.g. `"find all the controllers"`).
174
- - `prompt` (required): what kind of file to find.
175
- - `file_path` (optional): path substring to restrict results to a subdirectory, module, or specific file.
176
- - `limit` (optional): max results (default 30).
168
+ ### `path_between`
169
+ Given two exact symbol names, finds the shortest resolved call-graph path from the first to the second (e.g. how a controller method eventually reaches a repository call several hops down). Returns `found: false` if no path exists within the search bounds — that doesn't necessarily mean no relationship exists; it can also mean a bare name was too ambiguous to resolve.
170
+ - `from` / `to` (required): the starting and target symbols' exact names.
171
+ - `from_file_path` / `to_file_path` (optional): path substrings narrowing which definition to use when a name alone is ambiguous.
172
+ - `workspaceId` (optional): target a specific workspace instead of the local project's. Defaults to the local `setup_workspace` workspace.
173
+
174
+ ### `explain_subsystem`
175
+ Given a loose subsystem/module name (e.g. `"billing"`, `"auth"`), returns every file Harmony has clustered into that subsystem via its persisted import-graph communities — a direct listing, not a ranked search. Use this for "how does the billing system work" style questions where you want the whole subsystem's files at once, rather than piecing it together from several `context_search` calls.
176
+ - `prompt` (required): loose subsystem/module name to match against detected community labels.
177
+ - `limit` (optional): max files to return (default 60).
177
178
  - `workspaceId` (optional): target a specific workspace instead of the local project's. Defaults to the local `setup_workspace` workspace.
178
179
 
179
180
  ## Observability (OpenObserve)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeconductorai/harmony-mcp",
3
- "version": "1.0.23",
3
+ "version": "1.0.25",
4
4
  "type": "module",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -324,6 +324,39 @@ export async function callHarmonySearchEndpoint(endpointPath, args, workspaceId)
324
324
  return body;
325
325
  }
326
326
 
327
+ // POST /api/code-workspace/{workspaceId}/path-between — shortest resolved call-graph path
328
+ // between two symbols. Distinct request shape from callHarmonySearchEndpoint (from/to, not prompt).
329
+ export async function callHarmonyPathBetween(args, workspaceId) {
330
+ const from = args.from;
331
+ const to = args.to;
332
+ if (!from || !to) throw new Error("Both 'from' and 'to' are required.");
333
+
334
+ const requestBody = {
335
+ from,
336
+ to,
337
+ from_file_path: args.from_file_path,
338
+ to_file_path: args.to_file_path,
339
+ workspaceMetadata: buildWorkspaceMetadata(workspaceId),
340
+ };
341
+
342
+ log(`[path-between] Request body:`, JSON.stringify(requestBody, null, 2));
343
+
344
+ const response = await fetch(`${API_URL}/api/code-workspace/${workspaceId}/path-between`, {
345
+ method: "POST",
346
+ headers: {
347
+ "Content-Type": "application/json",
348
+ Accept: "application/xml",
349
+ ...(await authHeader(workspaceId)),
350
+ },
351
+ body: JSON.stringify(requestBody),
352
+ });
353
+ const body = await response.text();
354
+ if (!response.ok) {
355
+ throw new Error(`path-between request failed: ${response.status} ${body}`);
356
+ }
357
+ return body;
358
+ }
359
+
327
360
  // POST /api/code-workspace/{workspaceId}/bundle — ranked XML context bundle for a prompt.
328
361
  export async function fetchContextBundle(workspaceId, prompt) {
329
362
  const requestBody = {
@@ -368,7 +401,7 @@ export function annotateIfFallbackBundle(body) {
368
401
  return `${body}\n\n` +
369
402
  `[harmony-mcp note: this bundle used FALLBACK_NATIVE_RECALL — the backend did not resolve a ` +
370
403
  `high-signal call graph for this prompt, so the content above is broad/generic recall rather ` +
371
- `than a precisely targeted answer. Consider locate/search_code_context for a sharper result.]`;
404
+ `than a precisely targeted answer. Consider locate or context_search for a sharper result.]`;
372
405
  }
373
406
 
374
407
  // POST /api/v1/index/files — used by the file watcher for incremental updates.
package/src/server.js CHANGED
@@ -27,6 +27,7 @@ import {
27
27
  isFailedIndexStatus,
28
28
  pollWorkspaceStatus,
29
29
  callHarmonySearchEndpoint,
30
+ callHarmonyPathBetween,
30
31
  fetchContextBundle,
31
32
  annotateIfEmptyList,
32
33
  annotateIfFallbackBundle,
@@ -159,14 +160,16 @@ function describeIndexOutcome(indexStatus, workspaceId) {
159
160
  return {
160
161
  ready: true,
161
162
  message: `Workspace ${workspaceId} is fully indexed — text and symbols are ready. ` +
162
- `It's ready for context_search, locate, search_code_context, find_files, and get_context_bundle.`,
163
+ `It's ready for context_search, locate, explain_symbol, path_between, and explain_subsystem.`,
163
164
  };
164
165
  }
165
166
  if (DEGRADED_STATUSES.has(indexStatus)) {
166
167
  return {
167
168
  ready: false,
168
169
  message: `Workspace ${workspaceId} finished indexing, but only partially (status: ${indexStatus}). ` +
169
- `find_files and get_context_bundle should still work; locate/search_code_context/context_search may return no results.`,
170
+ `Symbol-level tools (locate, explain_symbol, path_between, explain_subsystem) and possibly ` +
171
+ `context_search may return incomplete or no results until symbol indexing finishes — verify ` +
172
+ `with local search (rg/grep) if a result looks suspiciously empty.`,
170
173
  };
171
174
  }
172
175
  if (indexStatus === "CORRUPTED") {
@@ -179,7 +182,7 @@ function describeIndexOutcome(indexStatus, workspaceId) {
179
182
  ready: false,
180
183
  message: `Workspace ${workspaceId} upload succeeded, but the backend is still indexing ` +
181
184
  `(status: ${indexStatus || "unknown"}). This can take longer for large repos — call ` +
182
- `setup_workspace again shortly to check whether it's finished before relying on locate/search_code_context.`,
185
+ `setup_workspace again shortly to check whether it's finished before relying on locate/context_search results.`,
183
186
  };
184
187
  }
185
188
 
@@ -302,6 +305,12 @@ function makeSearchHandler(endpointPath, toolName) {
302
305
  };
303
306
  }
304
307
 
308
+ async function handlePathBetween(args) {
309
+ const workspaceId = resolveWorkspaceId(args);
310
+ const body = await callHarmonyPathBetween(args, workspaceId);
311
+ return textContent(body);
312
+ }
313
+
305
314
  const TOOL_HANDLERS = {
306
315
  login: handleLogin,
307
316
  confirm_login: handleConfirmLogin,
@@ -311,6 +320,9 @@ const TOOL_HANDLERS = {
311
320
  locate: makeSearchHandler("locate-symbol", "locate"),
312
321
  search_code_context: makeSearchHandler("search", "search_code_context"),
313
322
  find_files: makeSearchHandler("find-files", "find_files"),
323
+ explain_symbol: makeSearchHandler("explain-symbol", "explain_symbol"),
324
+ path_between: handlePathBetween,
325
+ explain_subsystem: makeSearchHandler("explain-subsystem", "explain_subsystem"),
314
326
  };
315
327
 
316
328
  const AUTH_EXEMPT_TOOLS = new Set(["login", "confirm_login", "setup_workspace"]);
@@ -1,13 +1,44 @@
1
1
  import { hasSessionCredential, getWorkspaceToken } from "./deviceAuth.js";
2
2
  import { readMarker } from "./workspaceMarker.js";
3
3
 
4
+ const WHEN_TO_USE = `
5
+ When Harmony helps — reach for it when the task benefits from searching or understanding this
6
+ codebase and what you already have in hand isn't enough:
7
+ - You don't yet know which file(s) or symbol(s) are relevant ("where is X handled", "how does auth
8
+ work here", "find all the controllers").
9
+ - The codebase is large or unfamiliar, or the answer likely spans multiple files you haven't read
10
+ yet, such that chaining several Read/Grep/Glob calls to triangulate it would be slower.
11
+ - You need a fuzzy/semantic match on behavior or intent rather than a literal string ("the retry
12
+ logic", "where prices get rounded") — the kind of query grep/rg would miss or over-return.
13
+ - You want one fast, ranked answer instead of manually exploring the tree.
14
+
15
+ When Harmony is not the right call — prefer your own tools, direct reasoning, or general knowledge
16
+ instead:
17
+ - Simple questions answerable from general knowledge, math, or the current conversation — no
18
+ codebase lookup needed at all.
19
+ - You already know the exact file or symbol (from the user, an earlier result, or a path you can
20
+ already see) — just Read it or Grep for the exact string; that's faster and skips network/auth/
21
+ indexing latency for no benefit.
22
+ - Small, local edits or reasoning fully contained in a file you already have open.
23
+ - The workspace isn't indexed yet, or Harmony just returned empty/stale/irrelevant results for this
24
+ specific lookup — fall back to rg/grep/Read for that lookup rather than retrying Harmony.
25
+ - Writing new code, boilerplate, or general-purpose logic that doesn't depend on this repo's
26
+ existing implementation.
27
+
28
+ These are examples, not an exhaustive checklist. Weigh cost, latency, and whether Harmony is likely
29
+ to beat your own tools for the specific thing you're about to do — the same judgment call you'd make
30
+ between Grep and Read for any other lookup. Nothing here requires calling Harmony when your own
31
+ tools are just as fast, or when the task doesn't touch this codebase at all.
32
+ `.trim();
33
+
4
34
  const QUERY_REFINEMENT = `
5
- Query refinement — before calling context_search, locate, search_code_context, or find_files, judge
6
- whether the user's own wording is already a specific enough \`prompt\`. Skip this whole section for
7
- requests that already name a concrete symbol/class/method/route/file ("find CrudController",
8
- "where is POST /api/v1/index/zip handled") — pass those straight through unchanged. Only vague or
9
- generic requests ("show all controllers", "how does auth work", "find the retry stuff") need
10
- refinement, following these steps in order:
35
+ Query refinement — once you've decided a Harmony call is the right move, before calling
36
+ context_search or locate, judge whether the user's own wording is
37
+ already a specific enough \`prompt\`. Skip this whole section for requests that already name a
38
+ concrete symbol/class/method/route/file ("find CrudController", "where is POST /api/v1/index/zip
39
+ handled") — pass those straight through unchanged. Only vague or generic requests ("show all
40
+ controllers", "how does auth work", "find the retry stuff") need refinement, following these steps
41
+ in order:
11
42
  1. Extract identifiers — scan the user's wording for anything that is or implies a concrete symbol,
12
43
  class, method, route, file, or directory name (proper nouns, CamelCase/snake_case tokens, path
13
44
  fragments, HTTP verbs+paths). If something concrete is already there, use it verbatim as (or
@@ -40,71 +71,71 @@ to act on — it doesn't replace them, and it doesn't apply to the setup/auth to
40
71
  `.trim();
41
72
 
42
73
  const ROUTING_RULES = `
43
- MANDATORY DEFAULT — Harmony before your own tools: for ANY task in this project that involves
44
- finding code, understanding how something works, discovering files/modules, or gathering context,
45
- you MUST call the narrowest matching Harmony tool below FIRST, before reaching for Read, Grep,
46
- Glob, rg, find, ls, or any other built-in search/read capability. This is not optional and not just
47
- for the "first call in a session" — it applies every time a new discovery/comprehension need comes
48
- up during the task, not just once. Local tools are the fallback for when Harmony comes up short
49
- (see Trust but verify below), never the default first move.
50
-
51
- Routing — \`context_search\` is the default first call for ANY discovery/comprehension need (finding
52
- code, understanding how something works, discovering files/modules, gathering context). It is
53
- Harmony's newest, best-ranked search endpoint and takes precedence over locate, search_code_context and
54
- find_files — call it first, then only reach for one of those narrower tools if
55
- context_search's result is empty/insufficient or you specifically need one of their specialized output
56
- shapes (e.g. locate's line-number-only anchors for a targeted edit):
57
- - \`context_search\` — try this FIRST. Ranked matching symbols with code snippets, file paths, and
58
- relevance for a natural language query or exact identifier.
59
- - \`locate\` — "which file(s) handle X" / "where is X" for a task you're about to edit. Returns
60
- every matching symbol occurrence (definitions and references) with exact line numbers,
61
- optionally scoped to a file_path once you already know the file.
62
- - \`search_code_context\` — you need to understand or explain how something works: matching
63
- symbols with their code snippets, documentation, and decorators. Not for pinpointing an edit.
64
- - \`find_files\` — broad file/module discovery ("find all the controllers") without needing
65
- symbols or code content.
66
- - \`get_context_bundle\` — broader contextual understanding for a task or question, not a specific
67
- edit location. Returns a fuller XML context bundle for a prompt.
68
-
69
- High availability: \`context_search\` is the always-on default for every discovery/comprehension need
70
- that comes up during a task — call it again each time a new one arises, not just once per session or
71
- once per task. Composing fallback input: when context_search comes up short and you drop down to one
72
- of the narrower tools above, never just resend the same raw user query — carry forward the specific
73
- symbols, identifiers, and file paths context_search's response already surfaced, and combine THOSE
74
- with the user's original query when building the fallback tool's \`prompt\` (and \`file_path\` where
75
- applicable). The fallback call should read as "user's intent, sharpened by what context_search already
76
- found," not a blind retry of the same input.
77
-
78
- Carry forward a good result: once context_search's response gives you a concrete file_path, symbol
79
- name, or other specific detail relevant to the task, treat it as ground truth for every tool call
80
- that follows in that task — don't re-search for it, re-guess it, or fall back to a vaguer version of
81
- it. This isn't limited to falling back to one of the narrower Harmony tools above: it applies equally
82
- when you next call locate/search_code_context/find_files scoped to that file_path, and when you move
83
- on to Read, an edit, or any other tool — use the exact path/identifier context_search already
84
- returned rather than deriving your own guess at that point.
85
-
86
- Populate \`file_path\` whenever it's known: context_search, locate, search_code_context, and
87
- find_files all accept the same optional \`file_path\` field to scope results to a subdirectory,
88
- module, or specific file. Whenever a file path is already known at call time — surfaced by an
89
- earlier context_search/locate/find_files result this task, stated explicitly by the user, or
90
- established earlier in the conversation — pass it into that call's \`file_path\`, don't leave it
91
- blank and rely on the \`prompt\` text alone to imply scope. Only omit \`file_path\` when no such path
92
- is actually known yet; never fill it with a guessed path (see refinement step 3 above).
74
+ Choosing among Harmony's tools — once Harmony is the right move for a lookup, pick the narrowest fit:
75
+ - \`context_search\` — usually the best starting point for open-ended discovery/comprehension: ranked
76
+ matching symbols with code snippets, file paths, and relevance for a natural language query or
77
+ exact identifier.
78
+ - \`locate\` — "which file(s) handle X" / "where is X" for a task you're about to edit. Returns every
79
+ matching symbol occurrence (definitions and references) with exact line numbers, optionally scoped
80
+ to a file_path once you already know the file.
81
+ - \`explain_symbol\` — "who calls X" / "what does X call" / understanding a symbol's blast radius
82
+ before changing it. Reads the persisted call graph directly instead of ranking a search over every
83
+ file that might reference the symbol — pick this over context_search/locate for call-relationship
84
+ questions, it's the highest-leverage tool in this set for exactly that shape of question. Requires
85
+ an exact symbol name (not a natural-language description); use context_search first if you only
86
+ have a vague description and need to find the exact name.
87
+ - \`path_between\` — "how does A eventually reach B" / tracing a multi-hop call chain (e.g. a
88
+ controller method down to a repository call several layers deep). Also reads the persisted call
89
+ graph directly; needs two exact symbol names.
90
+ - \`explain_subsystem\` — "how does the billing/auth/whatever system work" when you want a whole
91
+ module's files at once rather than piecing it together from several context_search calls. Takes a
92
+ loose subsystem name, not an exact identifier.
93
+
94
+ If context_search's result is empty or insufficient, or you specifically need locate's line-number-
95
+ only anchors, fall back to that narrower tool rather than retrying context_search. Composing that
96
+ fallback: never just resend the same raw user query — carry forward the specific symbols,
97
+ identifiers, and file paths context_search's response already surfaced, and combine THOSE with the
98
+ user's original query when building the fallback tool's \`prompt\` (and \`file_path\` where
99
+ applicable). The fallback call should read as "user's intent, sharpened by what context_search
100
+ already found," not a blind retry of the same input. explain_symbol/path_between/explain_subsystem
101
+ are different from this fallback chain — reach for them directly, as the first call, whenever the
102
+ question is inherently about a call relationship or a whole subsystem rather than "find me the code
103
+ for X"; don't route through context_search first just to warm up.
104
+
105
+ Carry forward a good result: once a Harmony response gives you a concrete file_path, symbol name, or
106
+ other specific detail relevant to the task, treat it as ground truth for every tool call that
107
+ follows in that task — don't re-search for it, re-guess it, or fall back to a vaguer version of it.
108
+ This applies equally when you next call another Harmony tool scoped to that file_path, and when you
109
+ move on to Read, an edit, or any other tool — use the exact path/identifier already returned rather
110
+ than deriving your own guess at that point.
111
+
112
+ Populate \`file_path\` whenever it's known: context_search and locate accept an optional \`file_path\`
113
+ field to scope results to a subdirectory, module, or specific file; explain_symbol takes the same
114
+ idea as \`file_path\` and path_between as \`from_file_path\`/\`to_file_path\`, used specifically to
115
+ disambiguate which definition you mean when a symbol name alone is ambiguous (e.g. a common
116
+ interface-method name implemented by hundreds of classes). Whenever a file path is already known at
117
+ call time — surfaced by an earlier context_search/locate result this task, stated explicitly by the
118
+ user, or established earlier in the conversation — pass it into that call's \`file_path\`
119
+ (or \`from_file_path\`/\`to_file_path\`), don't leave it blank and rely on the \`prompt\` text alone to
120
+ imply scope. Only omit it when no such path is actually known yet; never fill it with a guessed path
121
+ (see refinement step 3 above).
122
+ `.trim();
93
123
 
124
+ const TRUST_BUT_VERIFY = `
94
125
  Trust but verify: Harmony's index can be stale, incomplete, or briefly out of date relative to the
95
126
  working tree. If a result is empty, errors, looks stale (references code that no longer exists), or
96
- is otherwise insufficient, don't retry the same call — fall back immediately to local tools (rg,
97
- Read, etc.) for that specific lookup only; it doesn't lift the mandate for the next discovery need.
98
- After a good Harmony result, proceed straight to the edit/answer — don't re-derive context you just
99
- fetched, and don't Read() a whole file the tool already covered.
127
+ is otherwise insufficient, don't retry the same call — fall back to local tools (rg, Read, etc.) for
128
+ that specific lookup only. After a good Harmony result, proceed straight to the edit/answer — don't
129
+ re-derive context you just fetched, and don't Read() a whole file the tool already covered.
100
130
  `.trim();
101
131
 
102
132
  const EFFICIENCY_RULES = `
103
133
  Efficiency — once a query is already well-formed (after refinement above), apply these to keep tool
104
134
  calls fast and non-redundant:
105
- - Don't repeat calls — before calling context_search/locate/search_code_context/find_files, check
106
- whether this exact (prompt, file_path, workspaceId) combination was already issued earlier in this
107
- task; if so, reuse that earlier result instead of calling again.
135
+ - Don't repeat calls — before calling context_search/locate/explain_symbol/path_between/
136
+ explain_subsystem, check whether this exact (prompt or from/to, file_path, workspaceId)
137
+ combination was already issued earlier in this task; if so, reuse that earlier result instead of
138
+ calling again.
108
139
  - Fan out independent lookups in parallel — when a task needs context on two or more genuinely
109
140
  unrelated things (e.g. "how does auth work and how does logging work"), or when refinement above
110
141
  produced multiple plausible variant queries for one ambiguous category, issue those calls together
@@ -116,8 +147,8 @@ calls fast and non-redundant:
116
147
  queries, where a small limit risks cutting off the right result.
117
148
  - Skip redundant ranking on retries — if a symbol's existence and rough location were already
118
149
  confirmed by an earlier context_search/locate result this task, a later lookup for that same
119
- symbol can go straight to the specialized tool (locate for line numbers, search_code_context for
120
- full detail) instead of re-running context_search's general-purpose ranking pass again.
150
+ symbol can go straight to the specialized tool (locate for line numbers, explain_symbol for its
151
+ callers/callees) instead of re-running context_search's general-purpose ranking pass again.
121
152
  `.trim();
122
153
 
123
154
  const SETUP_INSTRUCTIONS = `
@@ -135,16 +166,17 @@ Workspace setup — before the first search/locate/context call in a project:
135
166
  HTTP request succeeded. The response's \`ready\` field is only true once the backend confirms both
136
167
  text and symbols are indexed.
137
168
  - If \`ready\` is false, read \`indexStatus\` and the \`response\` text and relay them to the user in
138
- plain language before relying on locate/search_code_context results. If it says indexing is still
169
+ plain language before relying on locate/context_search/explain_symbol/path_between/
170
+ explain_subsystem results. If it says indexing is still
139
171
  running (the common case for large repos — the time budget ran out before the backend finished),
140
172
  this is expected and not a failure: tell the user briefly, then call \`setup_workspace\` again
141
173
  after a short wait to re-check — repeat until \`ready\` is true. If it instead reports only
142
- partially finished (symbols failed/skipped — find_files and get_context_bundle still work,
143
- locate/search_code_context may not) or failed outright, relay that instead of retrying blindly.
174
+ partially finished (symbols failed/skipped — the symbol-level tools may return incomplete or no
175
+ results) or failed outright, relay that instead of retrying blindly.
144
176
  `.trim();
145
177
 
146
178
  const AUTH_INSTRUCTIONS = `
147
- Auth gate — get_context_bundle, context_search, locate, search_code_context and find_files all
179
+ Auth gate — context_search, locate, explain_symbol, path_between, and explain_subsystem all
148
180
  return a "not authenticated" error until login has succeeded; run the login flow below before
149
181
  using them. setup_workspace is the one exception: call it directly even before logging in — it
150
182
  uses the login session when one exists, but some deployments authenticate the workspace
@@ -165,18 +197,18 @@ export function buildServerInstructions() {
165
197
  const ready = Boolean(authed && marker?.setup?.done && marker?.upload?.done);
166
198
 
167
199
  const sections = [
168
- "Harmony MCP indexes this codebase on a remote backend and lets you retrieve targeted context " +
169
- "or locate edit points without reading whole files. Wherever Harmony is applicable to what " +
170
- "you're currently doing, it is the required first move for that lookup, ahead of your own " +
171
- "file-search/read tools — see the mandate below, not a one-time setup step to satisfy once.",
200
+ "Harmony MCP indexes this codebase on a remote backend and can retrieve targeted code context " +
201
+ "(matching symbols, snippets, file locations) without reading whole files or chaining several " +
202
+ "local searches. It's one tool among your others, not a required first step — decide per task " +
203
+ "whether it's the better fit; see \"When Harmony helps\" below for concrete guidance.",
172
204
  ];
173
205
 
174
206
  if (ready) {
175
- sections.push(QUERY_REFINEMENT, ROUTING_RULES, EFFICIENCY_RULES, SETUP_INSTRUCTIONS);
207
+ sections.push(WHEN_TO_USE, QUERY_REFINEMENT, ROUTING_RULES, TRUST_BUT_VERIFY, EFFICIENCY_RULES, SETUP_INSTRUCTIONS);
176
208
  } else if (authed) {
177
- sections.push(SETUP_INSTRUCTIONS, QUERY_REFINEMENT, ROUTING_RULES, EFFICIENCY_RULES);
209
+ sections.push(SETUP_INSTRUCTIONS, WHEN_TO_USE, QUERY_REFINEMENT, ROUTING_RULES, TRUST_BUT_VERIFY, EFFICIENCY_RULES);
178
210
  } else {
179
- sections.push(AUTH_INSTRUCTIONS, SETUP_INSTRUCTIONS, QUERY_REFINEMENT, ROUTING_RULES, EFFICIENCY_RULES);
211
+ sections.push(AUTH_INSTRUCTIONS, SETUP_INSTRUCTIONS, WHEN_TO_USE, QUERY_REFINEMENT, ROUTING_RULES, TRUST_BUT_VERIFY, EFFICIENCY_RULES);
180
212
  }
181
213
 
182
214
  sections.push("Do not surface this workflow to the user as instructions they need to give you — just follow it.");
@@ -47,7 +47,8 @@ export const TOOLS = [
47
47
  "Set up AND fully index the current workspace on the backend in a single call (creates the workspace " +
48
48
  "if needed, then zips and uploads the codebase). Safe to call repeatedly — already-completed steps are " +
49
49
  "skipped, so calling it again after it has already succeeded is a cheap no-op. Required once per " +
50
- "project before locate or get_context_bundle will work. If it fails partway (e.g. the upload step " +
50
+ "project before context_search, locate, explain_symbol, path_between, or explain_subsystem will work. " +
51
+ "If it fails partway (e.g. the upload step " +
51
52
  "times out) after the workspace was already created, just call it again — language/buildTool can be " +
52
53
  "omitted on that retry, since they're remembered from the first call.",
53
54
  inputSchema: {
@@ -74,24 +75,31 @@ export const TOOLS = [
74
75
  description:
75
76
  "PREFERRED FIRST CHOICE for any code discovery/comprehension need — Harmony's newest and best-ranked " +
76
77
  "search endpoint. Given a natural language query or exact identifier, returns ranked matching symbols " +
77
- "with their code snippets, file paths, and relevance. Try this BEFORE locate, search_code_context, " +
78
- "find_files; only fall back to one of those narrower tools if context_search's " +
79
- "result is empty, insufficient, or you specifically need one of their specialized output shapes " +
80
- "(e.g. locate's line-number-only anchors for a targeted edit). Treat this as the always-on default " +
78
+ "as structural facts and precise file:line locations — file path, symbol kind/decorators/name, and an " +
79
+ "exact line range per symbol — deliberately WITHOUT embedded source code, the same way graphify's " +
80
+ "query/explain primitives work. Try this BEFORE locate; only fall back to locate if context_search's " +
81
+ "result is empty, insufficient, or you specifically need its line-number-only anchors for a targeted " +
82
+ "edit. For a question that's inherently about a call relationship or a whole subsystem rather than " +
83
+ "'find me the code for X', reach directly for explain_symbol/path_between/explain_subsystem instead — " +
84
+ "don't route through context_search first just to warm up. Treat context_search as the always-on default " +
81
85
  "entry point for every new discovery/comprehension need that comes up during a task — call it again " +
82
- "each time one arises, not just once. Whenever you do fall back to one of the narrower tools, don't " +
86
+ "each time one arises, not just once. Whenever you do fall back to locate, don't " +
83
87
  "discard what this call already found: carry its matched symbols, identifiers, and file paths forward " +
84
88
  "and combine them with the user's original query to build that tool's input, rather than re-issuing " +
85
89
  "the raw query alone.\n\n" +
86
- "RESPONSE SHAPE: the XML response has two separate top-level parts — <Hits><Hit>...</Hit></Hits>, " +
87
- "which is the actual code context (the matched symbols/snippets/file paths you answer the user's " +
88
- "query with), and a sibling <harmony_telemetry> block (filesBundledCount, graphEdgesResolved, " +
89
- "processingTimeMs, estimatedSecondsSaved, estimatedLoopsBypassed, estimatedTokensSaved) which is just " +
90
- "an operational efficiency snapshot of the search itself — not a search result and not code context. " +
91
- "Never merge, count, or cite <harmony_telemetry> fields as if they were part of <Hits>. Use only <Hits> " +
92
- "to answer the user's actual question. If you mention telemetry at all, present it separately and " +
93
- "clearly labeled (e.g. as a short aside/footnote about how the search performed), and only when it's " +
94
- "actually relevant to what the user asked — don't surface it by default on every call.",
90
+ "RESPONSE SHAPE: the XML response has two separate top-level parts. <Hits><Hit>...</Hit></Hits> is the " +
91
+ "location index — each Hit's <codeSnippet> is a compact table of contents for that file (one line per " +
92
+ "symbol: decorators, kind, name, and its exact lines{start:end} range), and <lineNumbers> pins the " +
93
+ "specific symbol this Hit matched to its own exact range. NEITHER field contains real source lines. " +
94
+ "Once you've decided which hit(s) actually matter, use your own file-read tool on the given file path " +
95
+ "and line range to see the real code — do not answer the user's question from <codeSnippet> alone, " +
96
+ "and never present a lines{a:b} header line as if it were the method body. The sibling " +
97
+ "<harmony_telemetry> block (filesBundledCount, graphEdgesResolved, processingTimeMs, " +
98
+ "estimatedSecondsSaved, estimatedLoopsBypassed, estimatedTokensSaved) is just an operational efficiency " +
99
+ "snapshot of the search itself — not a search result and not code context. Never merge, count, or cite " +
100
+ "<harmony_telemetry> fields as if they were part of <Hits>. If you mention telemetry at all, present it " +
101
+ "separately and clearly labeled (e.g. as a short aside/footnote about how the search performed), and " +
102
+ "only when it's actually relevant to what the user asked — don't surface it by default on every call.",
95
103
  inputSchema: {
96
104
  type: "object",
97
105
  properties: {
@@ -179,8 +187,7 @@ export const TOOLS = [
179
187
  required: ["prompt"],
180
188
  },
181
189
  },
182
- /*
183
- {
190
+ /* {
184
191
  name: "search_code_context",
185
192
  description:
186
193
  "Given a natural language query, returns rich Q&A context: matching symbols along with their code " +
@@ -208,6 +215,98 @@ export const TOOLS = [
208
215
  required: ["prompt"],
209
216
  },
210
217
  },
218
+ */
219
+ {
220
+ name: "explain_symbol",
221
+ description:
222
+ "Given an exact symbol name (method, function, or class), returns what it's connected to in the " +
223
+ "persisted call graph: which symbols call it, which symbols it calls, and any call targets that " +
224
+ "couldn't be confidently resolved to a single definition. Use this to understand a symbol's role " +
225
+ "and blast radius before changing it, or to answer 'who calls X' / 'what does X call' directly, " +
226
+ "without falling back to reading every file that might reference it.\n\n" +
227
+ "DISAMBIGUATION: common names (e.g. an interface method like 'processCommand' implemented by " +
228
+ "hundreds of classes) can match many definitions — the response is a list, one item per match. " +
229
+ "If you already know roughly where the symbol lives, pass file_path to narrow it to the exact one " +
230
+ "you mean instead of scanning every item in the list.",
231
+ inputSchema: {
232
+ type: "object",
233
+ properties: {
234
+ prompt: {
235
+ type: "string",
236
+ description: "REQUIRED. The exact symbol name to explain (e.g. a method or class name).",
237
+ },
238
+ file_path: {
239
+ type: "string",
240
+ description:
241
+ "Optional path substring narrowing which definition to use when the name alone is ambiguous " +
242
+ "(e.g. \"DisburseWorkingCapitalLoanCommandHandler\" to pick that class's processCommand out of " +
243
+ "hundreds of others with the same name).",
244
+ },
245
+ workspaceId: WORKSPACE_ID_PROPERTY,
246
+ },
247
+ required: ["prompt"],
248
+ },
249
+ },
250
+ {
251
+ name: "path_between",
252
+ description:
253
+ "Given two exact symbol names, finds the shortest resolved call-graph path from the first to the " +
254
+ "second (e.g. how a controller method eventually reaches a repository call several hops down). " +
255
+ "Returns found: false if no path exists within the search bounds — that does not necessarily mean " +
256
+ "no relationship exists: it can also mean the bare name was too ambiguous to resolve to the specific " +
257
+ "definition you meant (common names like interface method implementations can have hundreds of " +
258
+ "matches — try again with from_file_path/to_file_path once you know roughly where each symbol " +
259
+ "lives), or that the call site was ambiguous and intentionally left unresolved at index time (see " +
260
+ "explain_symbol's unresolved_call_targets).",
261
+ inputSchema: {
262
+ type: "object",
263
+ properties: {
264
+ from: {
265
+ type: "string",
266
+ description: "REQUIRED. The starting symbol's exact name.",
267
+ },
268
+ to: {
269
+ type: "string",
270
+ description: "REQUIRED. The target symbol's exact name to find a path to.",
271
+ },
272
+ from_file_path: {
273
+ type: "string",
274
+ description: "Optional path substring narrowing which \"from\" definition to use when the name alone is ambiguous.",
275
+ },
276
+ to_file_path: {
277
+ type: "string",
278
+ description: "Optional path substring narrowing which \"to\" definition to use when the name alone is ambiguous.",
279
+ },
280
+ workspaceId: WORKSPACE_ID_PROPERTY,
281
+ },
282
+ required: ["from", "to"],
283
+ },
284
+ },
285
+ {
286
+ name: "explain_subsystem",
287
+ description:
288
+ "Given a loose subsystem/module name (e.g. 'billing', 'auth'), returns every file harmony has " +
289
+ "clustered into that subsystem via its persisted import-graph communities — a direct listing, " +
290
+ "not a ranked search. Use this for 'how does the billing system work' style questions where you " +
291
+ "want the whole subsystem's files at once, rather than piecing it together from several " +
292
+ "context_search calls.",
293
+ inputSchema: {
294
+ type: "object",
295
+ properties: {
296
+ prompt: {
297
+ type: "string",
298
+ description: "REQUIRED. Loose subsystem/module name to match against detected community labels.",
299
+ },
300
+ limit: {
301
+ type: "number",
302
+ description: "Optional maximum number of files to return (default 60).",
303
+ },
304
+ workspaceId: WORKSPACE_ID_PROPERTY,
305
+ },
306
+ required: ["prompt"],
307
+ },
308
+ },
309
+ /*
211
310
  {
212
311
  name: "find_files",
213
312
  description:
@@ -235,6 +334,6 @@ export const TOOLS = [
235
334
  },
236
335
  required: ["prompt"],
237
336
  },
238
- }
337
+ },
239
338
  */
240
339
  ];