@codeconductorai/harmony-mcp 1.0.7 → 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.
- package/README.md +117 -25
- package/package.json +1 -1
- package/src/index.js +244 -62
package/README.md
CHANGED
|
@@ -1,19 +1,78 @@
|
|
|
1
1
|
# harmony-mcp
|
|
2
2
|
|
|
3
|
-
An MCP server that
|
|
3
|
+
An MCP (Model Context Protocol) server that connects your local workspace to the Harmony backend for codebase indexing and context retrieval. It exposes tools over stdio that let an MCP-compatible coding agent authenticate, index your project, and pull back precise, ranked code context instead of blindly reading or grepping the whole repo.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Requirements
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- Node.js >= 18 (ships with `npx`, which is how the server is run below)
|
|
8
8
|
|
|
9
|
-
**
|
|
9
|
+
**Check whether you have it:**
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
node -v
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
If this prints `v18.x.x` or higher, you're set. If you see `command not found` or a lower version, install/upgrade Node first:
|
|
16
|
+
|
|
17
|
+
- **macOS**: `brew install node` (or `brew upgrade node` if already installed)
|
|
18
|
+
- **Windows/macOS**: download the LTS installer from [nodejs.org](https://nodejs.org/)
|
|
19
|
+
- **Linux**: use your distro's package manager (e.g. `sudo apt install nodejs npm` on Debian/Ubuntu), or [NodeSource](https://github.com/nodesource/distributions) for a newer version
|
|
20
|
+
- **Any OS (recommended for managing multiple versions)**: install [nvm](https://github.com/nvm-sh/nvm), then run:
|
|
21
|
+
```bash
|
|
22
|
+
nvm install --lts
|
|
23
|
+
nvm use --lts
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Re-run `node -v` afterwards to confirm before continuing.
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
The server is published as `@codeconductorai/harmony-mcp` and run via `npx`, so no local build step is required.
|
|
31
|
+
|
|
32
|
+
### Claude Code
|
|
10
33
|
|
|
11
|
-
For Claude Code, run:
|
|
12
34
|
```bash
|
|
13
35
|
claude mcp add harmony -- npx -y @codeconductorai/harmony-mcp
|
|
14
36
|
```
|
|
15
37
|
|
|
16
|
-
|
|
38
|
+
### Antigravity
|
|
39
|
+
|
|
40
|
+
Open **MCP Servers → Manage MCP Servers → View raw config** from the agent panel, or edit the config file directly:
|
|
41
|
+
|
|
42
|
+
- Global: `~/.gemini/config/mcp_config.json`
|
|
43
|
+
- Workspace-local: `.agents/mcp_config.json`
|
|
44
|
+
|
|
45
|
+
```json
|
|
46
|
+
{
|
|
47
|
+
"mcpServers": {
|
|
48
|
+
"harmony": {
|
|
49
|
+
"command": "npx",
|
|
50
|
+
"args": ["-y", "@codeconductorai/harmony-mcp"]
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Restart Antigravity (or reload MCP servers) after saving.
|
|
57
|
+
|
|
58
|
+
### Codex CLI
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
codex mcp add harmony -- npx -y @codeconductorai/harmony-mcp
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
This writes the entry to `~/.codex/config.toml`. To add it by hand instead:
|
|
65
|
+
|
|
66
|
+
```toml
|
|
67
|
+
[mcp_servers.harmony]
|
|
68
|
+
command = "npx"
|
|
69
|
+
args = ["-y", "@codeconductorai/harmony-mcp"]
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### Aria
|
|
73
|
+
|
|
74
|
+
In the Aria Code panel, click the settings icon → **MCP Servers**, then scroll down and click **Edit Global MCP** (applies everywhere, via `mcp_settings.json`) or **Edit Project MCP** (this project only, writes `.Aria/mcp.json`). Add:
|
|
75
|
+
|
|
17
76
|
```json
|
|
18
77
|
{
|
|
19
78
|
"mcpServers": {
|
|
@@ -25,38 +84,71 @@ Or add it directly to your client's config file (e.g., `~/.claude/claude_desktop
|
|
|
25
84
|
}
|
|
26
85
|
```
|
|
27
86
|
|
|
28
|
-
|
|
87
|
+
Save the file — Aria Code picks up the new server automatically, no restart needed.
|
|
29
88
|
|
|
30
|
-
|
|
89
|
+
### Other MCP clients
|
|
31
90
|
|
|
32
|
-
|
|
91
|
+
Any client that reads a `command`/`args` style config (e.g. Claude Desktop's `claude_desktop_config.json`) can use the same shape:
|
|
33
92
|
|
|
34
|
-
|
|
93
|
+
```json
|
|
94
|
+
{
|
|
95
|
+
"mcpServers": {
|
|
96
|
+
"harmony": {
|
|
97
|
+
"command": "npx",
|
|
98
|
+
"args": ["-y", "@codeconductorai/harmony-mcp"]
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Getting started
|
|
105
|
+
|
|
106
|
+
After adding the server and restarting your client:
|
|
107
|
+
|
|
108
|
+
1. **`login`** — starts a device-flow login and returns a URL to open in your browser.
|
|
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 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.
|
|
112
|
+
|
|
113
|
+
Workspace state (workspace ID, language, build tool, setup/upload status) is cached in a `.harmony_workspace.json` marker file in the project root.
|
|
35
114
|
|
|
36
115
|
## Tools
|
|
37
116
|
|
|
38
117
|
### `login`
|
|
39
|
-
Starts a
|
|
118
|
+
Starts a device-flow login session and returns a `loginUrl` to open in the browser plus a `userCode`.
|
|
40
119
|
|
|
41
120
|
### `confirm_login`
|
|
42
|
-
|
|
43
|
-
- `timeout` (optional):
|
|
121
|
+
Completes authentication after the browser login. Requires `userConfirmed: true`, which must only be set after the user has explicitly confirmed (in chat) that they finished logging in.
|
|
122
|
+
- `timeout` (optional): max seconds to wait (default 300).
|
|
44
123
|
|
|
45
124
|
### `setup_workspace`
|
|
46
|
-
Registers
|
|
47
|
-
- `language` (required):
|
|
48
|
-
- `buildTool` (required
|
|
49
|
-
|
|
50
|
-
### `upload_workspace`
|
|
51
|
-
Zips the current working directory (excluding common folders like `node_modules` and `.git`) and indexes it on the cloud. Automatically runs `setup_workspace` if not already initialized.
|
|
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`.
|
|
52
128
|
|
|
53
129
|
### `get_context_bundle`
|
|
54
|
-
Retrieves a ranked XML context bundle
|
|
55
|
-
- `prompt` (required):
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
130
|
+
Retrieves a ranked XML context bundle of the most relevant code for a prompt.
|
|
131
|
+
- `prompt` (required): natural-language question or instruction.
|
|
132
|
+
|
|
133
|
+
### `locate`
|
|
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).
|
|
150
|
+
|
|
151
|
+
## Local development
|
|
60
152
|
|
|
61
153
|
```bash
|
|
62
154
|
npm install
|
package/package.json
CHANGED
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
|
-
*
|
|
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
|
|
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
|
|
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:
|
|
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: {
|
|
424
|
-
|
|
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
|
},
|
|
@@ -449,6 +545,90 @@ function buildMcpServer() {
|
|
|
449
545
|
required: ["prompt"],
|
|
450
546
|
},
|
|
451
547
|
},
|
|
548
|
+
{
|
|
549
|
+
name: "locate",
|
|
550
|
+
description:
|
|
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'.",
|
|
558
|
+
inputSchema: {
|
|
559
|
+
type: "object",
|
|
560
|
+
properties: {
|
|
561
|
+
prompt: {
|
|
562
|
+
type: "string",
|
|
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.",
|
|
573
|
+
},
|
|
574
|
+
limit: {
|
|
575
|
+
type: "number",
|
|
576
|
+
description: "Maximum number of results to return (default 40). The result list is never padded to this size.",
|
|
577
|
+
},
|
|
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: {
|
|
592
|
+
type: "string",
|
|
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).",
|
|
627
|
+
},
|
|
628
|
+
},
|
|
629
|
+
required: ["prompt"],
|
|
630
|
+
},
|
|
631
|
+
},
|
|
452
632
|
],
|
|
453
633
|
}));
|
|
454
634
|
|
|
@@ -543,38 +723,35 @@ function buildMcpServer() {
|
|
|
543
723
|
if (!process.env.AUTH_ACCESS_TOKEN && !isLoggedIn()) return NOT_AUTHENTICATED;
|
|
544
724
|
const language = args.language;
|
|
545
725
|
const buildTool = args.buildTool;
|
|
546
|
-
if (!language || !buildTool) {
|
|
547
|
-
throw new Error("language and buildTool are required.");
|
|
548
|
-
}
|
|
549
726
|
|
|
550
|
-
|
|
551
|
-
if (
|
|
727
|
+
const existingMarker = readMarker();
|
|
728
|
+
if (existingMarker?.setupDone && existingMarker?.uploadDone) {
|
|
729
|
+
startFileWatcher();
|
|
552
730
|
return {
|
|
553
731
|
content: [{
|
|
554
732
|
type: "text",
|
|
555
733
|
text: JSON.stringify({
|
|
556
|
-
response: `Workspace for project "${getProjectName()}" is already set up (workspaceId: ${
|
|
557
|
-
workspaceId:
|
|
734
|
+
response: `Workspace for project "${getProjectName()}" is already set up and indexed (workspaceId: ${existingMarker.workspaceId}). No action taken.`,
|
|
735
|
+
workspaceId: existingMarker.workspaceId,
|
|
558
736
|
projectName: getProjectName(),
|
|
559
|
-
language:
|
|
560
|
-
buildTool:
|
|
561
|
-
note: "Setup already performed for this workspace.",
|
|
562
|
-
setupResult: marker.setupResult,
|
|
737
|
+
language: existingMarker.language,
|
|
738
|
+
buildTool: existingMarker.buildTool,
|
|
739
|
+
note: "Setup and indexing already performed for this workspace.",
|
|
563
740
|
user: getCurrentUsername(),
|
|
564
741
|
}),
|
|
565
742
|
}],
|
|
566
743
|
};
|
|
567
744
|
}
|
|
568
745
|
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
746
|
+
try {
|
|
747
|
+
await ensureWorkspaceUploaded(language, buildTool);
|
|
748
|
+
} catch (error) {
|
|
572
749
|
return {
|
|
573
750
|
content: [{
|
|
574
751
|
type: "text",
|
|
575
752
|
text: JSON.stringify({
|
|
576
753
|
error: "setup_workspace_failed",
|
|
577
|
-
message:
|
|
754
|
+
message: error?.message || "Unknown setup error",
|
|
578
755
|
user: getCurrentUsername(),
|
|
579
756
|
}),
|
|
580
757
|
}],
|
|
@@ -582,40 +759,21 @@ function buildMcpServer() {
|
|
|
582
759
|
};
|
|
583
760
|
}
|
|
584
761
|
|
|
585
|
-
marker = { setupDone: true, workspaceId, language, buildTool, setupResult, uploadDone: false };
|
|
586
|
-
writeMarker(marker);
|
|
587
|
-
return {
|
|
588
|
-
content: [{
|
|
589
|
-
type: "text",
|
|
590
|
-
text: JSON.stringify({
|
|
591
|
-
response: `Workspace for project "${getProjectName()}" successfully created. workspaceId: ${workspaceId}. Call upload_workspace to index the codebase.`,
|
|
592
|
-
...setupResult,
|
|
593
|
-
user: getCurrentUsername(),
|
|
594
|
-
}),
|
|
595
|
-
}],
|
|
596
|
-
};
|
|
597
|
-
|
|
598
|
-
} else if (name === "upload_workspace") {
|
|
599
|
-
if (!process.env.AUTH_ACCESS_TOKEN && !isLoggedIn()) return NOT_AUTHENTICATED;
|
|
600
762
|
const marker = readMarker();
|
|
601
|
-
if (!marker?.language || !marker?.buildTool) {
|
|
602
|
-
throw new Error("Workspace not initialized. Call setup_workspace with language and buildTool first.");
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
await ensureWorkspaceUploaded(marker.language, marker.buildTool);
|
|
606
|
-
const updated = readMarker();
|
|
607
763
|
startFileWatcher();
|
|
608
764
|
|
|
609
765
|
return {
|
|
610
766
|
content: [{
|
|
611
767
|
type: "text",
|
|
612
768
|
text: JSON.stringify({
|
|
613
|
-
response: `Workspace for project "${getProjectName()}"
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
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,
|
|
619
777
|
user: getCurrentUsername(),
|
|
620
778
|
}),
|
|
621
779
|
}],
|
|
@@ -665,13 +823,37 @@ function buildMcpServer() {
|
|
|
665
823
|
return {
|
|
666
824
|
content: [{
|
|
667
825
|
type: "text",
|
|
668
|
-
text:
|
|
669
|
-
response: `Context bundle retrieved successfully for prompt: "${prompt}".`,
|
|
670
|
-
toolResponse: body,
|
|
671
|
-
}),
|
|
826
|
+
text: body,
|
|
672
827
|
}],
|
|
673
828
|
};
|
|
674
829
|
|
|
830
|
+
} else if (name === "locate") {
|
|
831
|
+
if (!process.env.AUTH_ACCESS_TOKEN && !isLoggedIn()) return NOT_AUTHENTICATED;
|
|
832
|
+
const marker = readMarker();
|
|
833
|
+
if (!marker?.workspaceId) {
|
|
834
|
+
throw new Error("Workspace not set up yet. Call setup_workspace first.");
|
|
835
|
+
}
|
|
836
|
+
const body = await callHarmonySearchEndpoint("locate-symbol", args, marker);
|
|
837
|
+
return { content: [{ type: "text", text: body }] };
|
|
838
|
+
|
|
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 }] };
|
|
847
|
+
|
|
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.");
|
|
853
|
+
}
|
|
854
|
+
const body = await callHarmonySearchEndpoint("find-files", args, marker);
|
|
855
|
+
return { content: [{ type: "text", text: body }] };
|
|
856
|
+
|
|
675
857
|
} else {
|
|
676
858
|
throw new Error(`Unknown tool: ${name}`);
|
|
677
859
|
}
|