@codeconductorai/harmony-mcp 1.0.8 → 1.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +22 -14
  2. package/package.json +1 -1
  3. package/src/index.js +215 -109
package/README.md CHANGED
@@ -107,11 +107,10 @@ After adding the server and restarting your client:
107
107
 
108
108
  1. **`login`** — starts a device-flow login and returns a URL to open in your browser.
109
109
  2. 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.
110
- 3. **`setup_workspace`** — registers the current project (`language` and `buildTool` required).
111
- 4. **`upload_workspace`** — zips and uploads the project for indexing. Runs `setup_workspace` automatically if it hasn't been done yet. Once indexing succeeds, a background file watcher pushes incremental updates to the backend as you edit files.
112
- 5. Use **`get_context_bundle`** or **`locate`** to pull relevant code context for a prompt.
110
+ 3. **`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. 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.
111
+ 4. Use **`locate`**, **`search_code_context`**, **`find_files`**, or **`get_context_bundle`** to pull relevant code context for a prompt.
113
112
 
114
- Workspace state (workspace ID, language, build tool, setup/upload status) is cached in a `.harmony_workspace.json` marker file in the project Ariat.
113
+ Workspace state (workspace ID, language, build tool, setup/upload status) is cached in a `.harmony_workspace.json` marker file in the project root.
115
114
 
116
115
  ## Tools
117
116
 
@@ -123,22 +122,31 @@ Completes authentication after the browser login. Requires `userConfirmed: true`
123
122
  - `timeout` (optional): max seconds to wait (default 300).
124
123
 
125
124
  ### `setup_workspace`
126
- Registers the current project as a workspace on the backend. No-op if already set up.
127
- - `language` (required): e.g. `JAVA`, `JAVASCRIPT`, `TYPESCRIPT`, `PYTHON`.
128
- - `buildTool` (required): e.g. `MAVEN`, `GRADLE`, `NPM`.
129
-
130
- ### `upload_workspace`
131
- Zips the working directory (excluding `node_modules`, `.git`, `.next`, `dist`, `build`, and the workspace marker) and uploads it for indexing. Starts the file watcher for incremental re-indexing once done.
125
+ Registers the current project as a workspace on the backend and fully indexes it (zips and uploads the codebase, excluding `node_modules`, `.git`, `.next`, `dist`, `build`, and the workspace marker) in a single call. Starts the file watcher for incremental re-indexing once done. Idempotent — a `.harmony_workspace.json` marker tracks setup/upload state, so calling it again once both steps have completed is a no-op. If it fails partway (e.g. the upload step errors out after the workspace was already created), call it again — `language`/`buildTool` can be omitted on that retry since they're remembered from the marker, and only the incomplete step re-runs.
126
+ - `language` (required on first call): e.g. `JAVA`, `JAVASCRIPT`, `TYPESCRIPT`, `PYTHON`.
127
+ - `buildTool` (required on first call): e.g. `MAVEN`, `GRADLE`, `NPM`.
132
128
 
133
129
  ### `get_context_bundle`
134
130
  Retrieves a ranked XML context bundle of the most relevant code for a prompt.
135
131
  - `prompt` (required): natural-language question or instruction.
136
132
 
137
133
  ### `locate`
138
- Given a natural-language query, returns an XML response with ranked file paths, relevant symbols, call-graph-aware line anchors, and real line-numbered source excerpts around each anchor — enough to make targeted edits without a separate full-file read.
139
- - `prompt` (required): what to find, e.g. `"winner email"`.
140
- - `limit` (optional): max ranked results (default 10, max 25).
141
- - `scope` (optional): path prefix/substring to restrict the search to a subdirectory or module.
134
+ Given a natural-language query or exact identifier, returns lightweight symbol coordinate anchors (file path, symbol name, kind/type, whether it's a definition, line numbers, primary role) — no code snippets. Use it to find which file(s) and exact line(s) to look at or edit for a task.
135
+ - `prompt` (required): what to find, e.g. `"where user login is handled"` or `"CrudController"`. Must be non-blank — a missing or whitespace-only prompt returns an empty list, not an error.
136
+ - `file_path` (optional): case-insensitive substring match against the full file path (not exact-path or prefix) to restrict results to a subdirectory, module, or specific file.
137
+ - `limit` (optional): max results (default 40); the result list is never padded to this size.
138
+
139
+ ### `search_code_context`
140
+ 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).
141
+ - `prompt` (required): what to find context for.
142
+ - `file_path` (optional): path substring to restrict results to a subdirectory, module, or specific file.
143
+ - `limit` (optional): max results (default 15).
144
+
145
+ ### `find_files`
146
+ 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"`).
147
+ - `prompt` (required): what kind of file to find.
148
+ - `file_path` (optional): path substring to restrict results to a subdirectory, module, or specific file.
149
+ - `limit` (optional): max results (default 30).
142
150
 
143
151
  ## Local development
144
152
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeconductorai/harmony-mcp",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "type": "module",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/index.js CHANGED
@@ -263,6 +263,51 @@ async function ensureWorkspaceUploaded(language, buildTool) {
263
263
  }
264
264
  }
265
265
 
266
+ /*
267
+ * Shared POST caller for the three HarmonyRequest-shaped search endpoints (locate-symbol,
268
+ * search, find-files) backing the locate, search_code_context, and find_files tools — they all
269
+ * take the same {prompt, file_path, limit, workspaceMetadata} body and return the raw XML
270
+ * response body.
271
+ */
272
+ async function callHarmonySearchEndpoint(endpointPath, args, marker) {
273
+ const prompt = args.prompt || args.query;
274
+ if (!prompt) throw new Error("prompt is required.");
275
+
276
+ const requestBody = {
277
+ prompt,
278
+ file_path: args.file_path,
279
+ limit: args.limit,
280
+ workspaceMetadata: {
281
+ workspaceId: marker.workspaceId,
282
+ productId: PRODUCT_ID,
283
+ appId: APP_ID,
284
+ repoId: getGitRepoId(),
285
+ branchName: BRANCH_NAME,
286
+ workspaceAlias: getWorkspaceAlias(getProjectName()),
287
+ workspacePath: process.cwd(),
288
+ projectName: getProjectName(),
289
+ },
290
+ };
291
+
292
+ log(`[${endpointPath}] Request body:`, JSON.stringify(requestBody, null, 2));
293
+
294
+ const token = await getAccessToken();
295
+ const response = await fetch(`${API_URL}/api/code-workspace/${marker.workspaceId}/${endpointPath}`, {
296
+ method: "POST",
297
+ headers: {
298
+ "Content-Type": "application/json",
299
+ Accept: "application/xml",
300
+ Authorization: `Bearer ${token}`,
301
+ },
302
+ body: JSON.stringify(requestBody),
303
+ });
304
+ const body = await response.text();
305
+ if (!response.ok) {
306
+ throw new Error(`${endpointPath} request failed: ${response.status} ${body}`);
307
+ }
308
+ return body;
309
+ }
310
+
266
311
  /*
267
312
  * POST /api/v1/index/files — used by the file watcher for incremental updates.
268
313
  */
@@ -373,12 +418,56 @@ function startFileWatcher() {
373
418
  }
374
419
 
375
420
  /*
376
- * Build the MCP server with tool handlers for setup_workspace, upload_workspace, and get_context_bundle.
421
+ * Server-level instructions, returned to the client during MCP initialize. Clients that support
422
+ * this field (e.g. Claude Code) fold it into the model's context automatically, so the workflow
423
+ * below applies without the user having to explain it manually each session.
424
+ */
425
+ const SERVER_INSTRUCTIONS = `
426
+ Harmony MCP indexes this codebase on a remote backend and lets you retrieve targeted context or
427
+ locate edit points without reading whole files. Follow this workflow:
428
+
429
+ 1. Auth gate — setup_workspace, get_context_bundle, locate, search_code_context, and find_files all
430
+ return a "not authenticated" error until login has succeeded. Do not attempt to work around this
431
+ by guessing tokens or skipping the tool; just run the login flow below.
432
+ - Call \`login\`, show the returned loginUrl to the user verbatim, and ask them to complete it
433
+ in their browser.
434
+ - Wait for the user's own explicit confirmation in chat that they've finished. Never call
435
+ \`confirm_login\` speculatively or immediately after \`login\`.
436
+ - Only then call \`confirm_login\` with userConfirmed: true.
437
+
438
+ 2. Workspace setup — once authenticated, before the first search/locate/context call in a project:
439
+ - Call \`setup_workspace\` once with the project's language and build tool (infer from
440
+ package.json/pom.xml/build.gradle/etc. — ask the user only if genuinely ambiguous). This one
441
+ call both creates the workspace and uploads/indexes the codebase.
442
+ - It's idempotent — a workspace marker file tracks setup/upload state, so calling it again on an
443
+ already-indexed workspace is a cheap no-op rather than a re-upload.
444
+ - If it fails partway (e.g. the upload step errors out after the workspace was already created),
445
+ just call \`setup_workspace\` again — omit language/buildTool on that retry, they're remembered
446
+ from the marker, and only the incomplete step (upload) re-runs.
447
+
448
+ 3. Day-to-day usage — once the workspace is indexed, pick the narrowest tool for the job:
449
+ - \`locate\` — "which file(s) handle X" / "where is X" for a task you're about to edit. Returns
450
+ every matching symbol occurrence (definitions and references) with exact line numbers,
451
+ optionally scoped to a file_path once you already know the file.
452
+ - \`search_code_context\` — you need to understand or explain how something works: matching
453
+ symbols with their code snippets, documentation, and decorators. Not for pinpointing an edit.
454
+ - \`find_files\` — broad file/module discovery ("find all the controllers") without needing
455
+ symbols or code content.
456
+ - \`get_context_bundle\` — broader contextual understanding for a task or question, not a
457
+ specific edit location. Returns a fuller XML context bundle for a prompt.
458
+ - After any call, proceed straight to the edit/answer using the returned content — don't
459
+ re-derive context you just fetched, and don't Read() a whole file the tool already covered.
460
+
461
+ Do not surface this workflow to the user as instructions they need to give you — just follow it.
462
+ `.trim();
463
+
464
+ /*
465
+ * Build the MCP server with tool handlers for status, setup_workspace, and get_context_bundle.
377
466
  */
378
467
  function buildMcpServer() {
379
468
  const server = new Server(
380
469
  { name: "harmony-mcp-server", version: packageJson.version },
381
- { capabilities: { tools: {} } }
470
+ { capabilities: { tools: {} }, instructions: SERVER_INSTRUCTIONS }
382
471
  );
383
472
 
384
473
  server.setRequestHandler(ListToolsRequestSchema, async () => ({
@@ -386,7 +475,7 @@ function buildMcpServer() {
386
475
  {
387
476
  name: "login",
388
477
  description:
389
- "Start a Keycloak device-flow login session. Returns a loginUrl the user must open in their browser. " +
478
+ "Start a auth device-flow login session. Returns a loginUrl the user must open in their browser. " +
390
479
  "IMPORTANT: after calling this tool you MUST (1) display the full loginUrl to the user clearly, " +
391
480
  "(2) explicitly ask the user to open it and complete the login in their browser, and " +
392
481
  "(3) wait for the user to confirm they have finished logging in before calling confirm_login. " +
@@ -396,7 +485,7 @@ function buildMcpServer() {
396
485
  {
397
486
  name: "confirm_login",
398
487
  description:
399
- "Poll Keycloak until the user's browser login is complete. Do NOT call this in the same turn as login. " +
488
+ "Poll auth until the user's browser login is complete. Do NOT call this in the same turn as login. " +
400
489
  "You must first show the loginUrl to the user and get an explicit reply from them (in the chat, in their " +
401
490
  "own words) saying they've finished logging in. Only then call this tool with userConfirmed set to true. " +
402
491
  "Calling this without a genuine reply from the user, or right after login, will be rejected.",
@@ -416,22 +505,29 @@ function buildMcpServer() {
416
505
  },
417
506
  {
418
507
  name: "setup_workspace",
419
- description: "Create/prepare a workspace on the backend (POST /api/v1/workspace/{id}/create). Must be called before upload.",
508
+ description:
509
+ "Set up AND fully index the current workspace on the backend in a single call (creates the workspace " +
510
+ "if needed, then zips and uploads the codebase). Safe to call repeatedly — already-completed steps are " +
511
+ "skipped, so calling it again after it has already succeeded is a cheap no-op. Required once per " +
512
+ "project before locate or get_context_bundle will work. If it fails partway (e.g. the upload step " +
513
+ "times out) after the workspace was already created, just call it again — language/buildTool can be " +
514
+ "omitted on that retry, since they're remembered from the first call.",
420
515
  inputSchema: {
421
516
  type: "object",
422
517
  properties: {
423
- language: { type: "string", description: "Programming language (e.g. JAVA, JAVASCRIPT, TYPESCRIPT, PYTHON)." },
424
- buildTool: { type: "string", description: "Build tool (e.g. MAVEN, GRADLE, NPM)." },
518
+ language: {
519
+ type: "string",
520
+ description:
521
+ "Programming language (e.g. JAVA, JAVASCRIPT, TYPESCRIPT, PYTHON). Required the first time; can " +
522
+ "be omitted on a retry, since it's remembered from the workspace's prior setup call.",
523
+ },
524
+ buildTool: {
525
+ type: "string",
526
+ description:
527
+ "Build tool (e.g. MAVEN, GRADLE, NPM). Required the first time; can be omitted on a retry, since " +
528
+ "it's remembered from the workspace's prior setup call.",
529
+ },
425
530
  },
426
- required: ["language", "buildTool"],
427
- },
428
- },
429
- {
430
- name: "upload_workspace",
431
- description: "Zip the current working directory and index it on the backend. Runs setup first if not already done.",
432
- inputSchema: {
433
- type: "object",
434
- properties: {},
435
531
  required: [],
436
532
  },
437
533
  },
@@ -452,28 +548,82 @@ function buildMcpServer() {
452
548
  {
453
549
  name: "locate",
454
550
  description:
455
- "Given a natural language query, returns an XML response designed to let you make small, targeted " +
456
- "edits WITHOUT a separate full-file Read: ranked file paths (each with its architectural role, tags, " +
457
- "relevant symbol names, and call-graph-aware line anchors with a reason), plus a top-level 'summary' " +
458
- "element — real, line-numbered source excerpts (not just snippets) sliced directly out of each file " +
459
- "around its returned anchors, merged where anchors are close together. This is the ONLY part of the " +
460
- "file/codebase you should read for the query — do not Read() the whole file or grep the wider codebase " +
461
- "on top of this. Only fall back to Read() if the edit you need falls outside every line range shown in " +
462
- "the summary (the line numbers in the summary are exact — use them directly for the edit).",
551
+ "Given a natural language query or exact identifier, returns ultra-light symbol coordinate anchors " +
552
+ "(file path, symbol name, symbol kind/type, whether it's a definition, line numbers, primary role) — " +
553
+ "no code snippets or documentation. Use this to find WHICH FILE(S) and exact line(s) to look at or " +
554
+ "edit for a task, e.g. every occurrence of a name across the codebase, or (scoped with file_path) " +
555
+ "exact line numbers within a file you already know. It does not return full file content — Read() the " +
556
+ "file once you have the line numbers if you need surrounding context beyond what the anchor tells you. " +
557
+ "A missing/blank prompt returns an empty result list rather than an error or 'match everything'.",
463
558
  inputSchema: {
464
559
  type: "object",
465
560
  properties: {
466
561
  prompt: {
467
562
  type: "string",
468
- description: "Natural language query describing what to find (e.g. \"winner email\").",
563
+ description:
564
+ "Natural language query or unique identifier describing what to find (e.g. CrudController). " +
565
+ "Required and must be non-blank — an empty or whitespace-only prompt yields no results.",
566
+ },
567
+ file_path: {
568
+ type: "string",
569
+ description:
570
+ "Optional filter to restrict results to a subdirectory, module, or specific file. Matched as a " +
571
+ "case-insensitive substring against the full file path (e.g. \"CrudController.java\" matches any " +
572
+ "path ending in that name) — not an exact-path or prefix match.",
469
573
  },
470
574
  limit: {
471
575
  type: "number",
472
- description: "Maximum number of ranked results to return (default 10, max 25).",
576
+ description: "Maximum number of results to return (default 40). The result list is never padded to this size.",
473
577
  },
474
- scope: {
578
+ },
579
+ required: ["prompt"],
580
+ },
581
+ },
582
+ {
583
+ name: "search_code_context",
584
+ description:
585
+ "Given a natural language query, returns rich Q&A context: matching symbols along with their code " +
586
+ "snippets, documentation, and decorators. Use this when you need to understand or explain how " +
587
+ "something works, not when you're about to make a targeted edit (use locate for that).",
588
+ inputSchema: {
589
+ type: "object",
590
+ properties: {
591
+ prompt: {
475
592
  type: "string",
476
- description: "Optional path prefix/substring to restrict the search to a subdirectory or module.",
593
+ description: "Natural language query describing what to find context for or unique identifier describing what to search (e.g. CrudController).",
594
+ },
595
+ file_path: {
596
+ type: "string",
597
+ description: "Optional path substring to restrict results to a subdirectory, module, or specific file.",
598
+ },
599
+ limit: {
600
+ type: "number",
601
+ description: "Maximum number of results to return (default 15).",
602
+ },
603
+ },
604
+ required: ["prompt"],
605
+ },
606
+ },
607
+ {
608
+ name: "find_files",
609
+ description:
610
+ "Given a natural language query, returns lightweight file path and architectural role/tag matches — " +
611
+ "no symbols or code content. Use this for broad file/module discovery (e.g. \"find all the " +
612
+ "controllers\") rather than pinpointing a specific edit location.",
613
+ inputSchema: {
614
+ type: "object",
615
+ properties: {
616
+ prompt: {
617
+ type: "string",
618
+ description: "Natural language query describing the kind of file to find.",
619
+ },
620
+ file_path: {
621
+ type: "string",
622
+ description: "Optional path substring to restrict results to a subdirectory, module, or specific file.",
623
+ },
624
+ limit: {
625
+ type: "number",
626
+ description: "Maximum number of results to return (default 30).",
477
627
  },
478
628
  },
479
629
  required: ["prompt"],
@@ -573,38 +723,35 @@ function buildMcpServer() {
573
723
  if (!process.env.AUTH_ACCESS_TOKEN && !isLoggedIn()) return NOT_AUTHENTICATED;
574
724
  const language = args.language;
575
725
  const buildTool = args.buildTool;
576
- if (!language || !buildTool) {
577
- throw new Error("language and buildTool are required.");
578
- }
579
726
 
580
- let marker = readMarker();
581
- if (marker?.setupDone) {
727
+ const existingMarker = readMarker();
728
+ if (existingMarker?.setupDone && existingMarker?.uploadDone) {
729
+ startFileWatcher();
582
730
  return {
583
731
  content: [{
584
732
  type: "text",
585
733
  text: JSON.stringify({
586
- response: `Workspace for project "${getProjectName()}" is already set up (workspaceId: ${marker.workspaceId}). No action taken.`,
587
- workspaceId: marker.workspaceId,
734
+ response: `Workspace for project "${getProjectName()}" is already set up and indexed (workspaceId: ${existingMarker.workspaceId}). No action taken.`,
735
+ workspaceId: existingMarker.workspaceId,
588
736
  projectName: getProjectName(),
589
- language: marker.language,
590
- buildTool: marker.buildTool,
591
- note: "Setup already performed for this workspace.",
592
- setupResult: marker.setupResult,
737
+ language: existingMarker.language,
738
+ buildTool: existingMarker.buildTool,
739
+ note: "Setup and indexing already performed for this workspace.",
593
740
  user: getCurrentUsername(),
594
741
  }),
595
742
  }],
596
743
  };
597
744
  }
598
745
 
599
- const workspaceId = crypto.randomUUID();
600
- const setupResult = await setupWorkspace(workspaceId, language, buildTool);
601
- if (setupResult.error) {
746
+ try {
747
+ await ensureWorkspaceUploaded(language, buildTool);
748
+ } catch (error) {
602
749
  return {
603
750
  content: [{
604
751
  type: "text",
605
752
  text: JSON.stringify({
606
753
  error: "setup_workspace_failed",
607
- message: setupResult.error,
754
+ message: error?.message || "Unknown setup error",
608
755
  user: getCurrentUsername(),
609
756
  }),
610
757
  }],
@@ -612,40 +759,21 @@ function buildMcpServer() {
612
759
  };
613
760
  }
614
761
 
615
- marker = { setupDone: true, workspaceId, language, buildTool, setupResult, uploadDone: false };
616
- writeMarker(marker);
617
- return {
618
- content: [{
619
- type: "text",
620
- text: JSON.stringify({
621
- response: `Workspace for project "${getProjectName()}" successfully created. workspaceId: ${workspaceId}. Call upload_workspace to index the codebase.`,
622
- ...setupResult,
623
- user: getCurrentUsername(),
624
- }),
625
- }],
626
- };
627
-
628
- } else if (name === "upload_workspace") {
629
- if (!process.env.AUTH_ACCESS_TOKEN && !isLoggedIn()) return NOT_AUTHENTICATED;
630
762
  const marker = readMarker();
631
- if (!marker?.language || !marker?.buildTool) {
632
- throw new Error("Workspace not initialized. Call setup_workspace with language and buildTool first.");
633
- }
634
-
635
- await ensureWorkspaceUploaded(marker.language, marker.buildTool);
636
- const updated = readMarker();
637
763
  startFileWatcher();
638
764
 
639
765
  return {
640
766
  content: [{
641
767
  type: "text",
642
768
  text: JSON.stringify({
643
- response: `Workspace for project "${getProjectName()}" has been zipped and fully indexed. The codebase is ready for context retrieval via get_context_bundle.`,
644
- workspaceId: updated?.workspaceId,
645
- language: updated?.language,
646
- buildTool: updated?.buildTool,
647
- uploaded: updated?.uploadDone || false,
648
- result: updated?.uploadResult || null,
769
+ response: `Workspace for project "${getProjectName()}" successfully created and indexed. workspaceId: ${marker?.workspaceId}. ` +
770
+ `It's ready for locate, search_code_context, find_files, and get_context_bundle.`,
771
+ workspaceId: marker?.workspaceId,
772
+ projectName: getProjectName(),
773
+ language: marker?.language,
774
+ buildTool: marker?.buildTool,
775
+ setupResult: marker?.setupResult,
776
+ uploadResult: marker?.uploadResult,
649
777
  user: getCurrentUsername(),
650
778
  }),
651
779
  }],
@@ -705,48 +833,26 @@ function buildMcpServer() {
705
833
  if (!marker?.workspaceId) {
706
834
  throw new Error("Workspace not set up yet. Call setup_workspace first.");
707
835
  }
836
+ const body = await callHarmonySearchEndpoint("locate-symbol", args, marker);
837
+ return { content: [{ type: "text", text: body }] };
708
838
 
709
- const prompt = args.prompt || args.query;
710
- if (!prompt) throw new Error("prompt is required.");
711
-
712
- const requestBody = {
713
- prompt,
714
- limit: args.limit,
715
- scope: args.scope,
716
- workspaceMetadata: {
717
- workspaceId: marker.workspaceId,
718
- productId: PRODUCT_ID,
719
- appId: APP_ID,
720
- repoId: getGitRepoId(),
721
- branchName: BRANCH_NAME,
722
- workspaceAlias: getWorkspaceAlias(getProjectName()),
723
- workspacePath: process.cwd(),
724
- projectName: getProjectName(),
725
- },
726
- };
727
-
728
- log("[locate] Request body:", JSON.stringify(requestBody, null, 2));
839
+ } else if (name === "search_code_context") {
840
+ if (!process.env.AUTH_ACCESS_TOKEN && !isLoggedIn()) return NOT_AUTHENTICATED;
841
+ const marker = readMarker();
842
+ if (!marker?.workspaceId) {
843
+ throw new Error("Workspace not set up yet. Call setup_workspace first.");
844
+ }
845
+ const body = await callHarmonySearchEndpoint("search", args, marker);
846
+ return { content: [{ type: "text", text: body }] };
729
847
 
730
- const token = await getAccessToken();
731
- const response = await fetch(`${API_URL}/api/code-workspace/${marker.workspaceId}/locate`, {
732
- method: "POST",
733
- headers: {
734
- "Content-Type": "application/json",
735
- Accept: "application/xml",
736
- Authorization: `Bearer ${token}`,
737
- },
738
- body: JSON.stringify(requestBody),
739
- });
740
- const body = await response.text();
741
- if (!response.ok) {
742
- throw new Error(`Locate request failed: ${response.status} ${body}`);
848
+ } else if (name === "find_files") {
849
+ if (!process.env.AUTH_ACCESS_TOKEN && !isLoggedIn()) return NOT_AUTHENTICATED;
850
+ const marker = readMarker();
851
+ if (!marker?.workspaceId) {
852
+ throw new Error("Workspace not set up yet. Call setup_workspace first.");
743
853
  }
744
- return {
745
- content: [{
746
- type: "text",
747
- text: body,
748
- }],
749
- };
854
+ const body = await callHarmonySearchEndpoint("find-files", args, marker);
855
+ return { content: [{ type: "text", text: body }] };
750
856
 
751
857
  } else {
752
858
  throw new Error(`Unknown tool: ${name}`);