@codeconductorai/harmony-mcp 1.0.6 → 1.0.8
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 +105 -21
- package/package.json +1 -1
- package/src/deviceAuth.js +31 -0
- package/src/index.js +85 -15
package/README.md
CHANGED
|
@@ -1,19 +1,95 @@
|
|
|
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
|
+
|
|
76
|
+
```json
|
|
77
|
+
{
|
|
78
|
+
"mcpServers": {
|
|
79
|
+
"harmony": {
|
|
80
|
+
"command": "npx",
|
|
81
|
+
"args": ["-y", "@codeconductorai/harmony-mcp"]
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Save the file — Aria Code picks up the new server automatically, no restart needed.
|
|
88
|
+
|
|
89
|
+
### Other MCP clients
|
|
90
|
+
|
|
91
|
+
Any client that reads a `command`/`args` style config (e.g. Claude Desktop's `claude_desktop_config.json`) can use the same shape:
|
|
92
|
+
|
|
17
93
|
```json
|
|
18
94
|
{
|
|
19
95
|
"mcpServers": {
|
|
@@ -25,38 +101,46 @@ Or add it directly to your client's config file (e.g., `~/.claude/claude_desktop
|
|
|
25
101
|
}
|
|
26
102
|
```
|
|
27
103
|
|
|
28
|
-
|
|
104
|
+
## Getting started
|
|
29
105
|
|
|
30
|
-
|
|
106
|
+
After adding the server and restarting your client:
|
|
31
107
|
|
|
32
|
-
|
|
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).
|
|
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.
|
|
33
113
|
|
|
34
|
-
|
|
114
|
+
Workspace state (workspace ID, language, build tool, setup/upload status) is cached in a `.harmony_workspace.json` marker file in the project Ariat.
|
|
35
115
|
|
|
36
116
|
## Tools
|
|
37
117
|
|
|
38
118
|
### `login`
|
|
39
|
-
Starts a
|
|
119
|
+
Starts a device-flow login session and returns a `loginUrl` to open in the browser plus a `userCode`.
|
|
40
120
|
|
|
41
121
|
### `confirm_login`
|
|
42
|
-
|
|
43
|
-
- `timeout` (optional):
|
|
122
|
+
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.
|
|
123
|
+
- `timeout` (optional): max seconds to wait (default 300).
|
|
44
124
|
|
|
45
125
|
### `setup_workspace`
|
|
46
|
-
Registers
|
|
47
|
-
- `language` (required):
|
|
48
|
-
- `buildTool` (required):
|
|
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`.
|
|
49
129
|
|
|
50
130
|
### `upload_workspace`
|
|
51
|
-
Zips the
|
|
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.
|
|
52
132
|
|
|
53
133
|
### `get_context_bundle`
|
|
54
|
-
Retrieves a ranked XML context bundle
|
|
55
|
-
- `prompt` (required):
|
|
134
|
+
Retrieves a ranked XML context bundle of the most relevant code for a prompt.
|
|
135
|
+
- `prompt` (required): natural-language question or instruction.
|
|
56
136
|
|
|
57
|
-
|
|
137
|
+
### `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.
|
|
58
142
|
|
|
59
|
-
## Local
|
|
143
|
+
## Local development
|
|
60
144
|
|
|
61
145
|
```bash
|
|
62
146
|
npm install
|
package/package.json
CHANGED
package/src/deviceAuth.js
CHANGED
|
@@ -23,6 +23,36 @@ let pendingPollInterval = 5;
|
|
|
23
23
|
let loginInitiatedAt = 0;
|
|
24
24
|
|
|
25
25
|
const MIN_SECONDS_BEFORE_CONFIRM = 10;
|
|
26
|
+
const SESSION_FILE = path.join(os.homedir(), ".harmony-mcp", "session.json");
|
|
27
|
+
|
|
28
|
+
function loadSession() {
|
|
29
|
+
try {
|
|
30
|
+
const data = JSON.parse(fs.readFileSync(SESSION_FILE, "utf8"));
|
|
31
|
+
if (data.accessToken && data.expiresAt > Math.floor(Date.now() / 1000)) {
|
|
32
|
+
userToken = data.accessToken;
|
|
33
|
+
userTokenExpiresAt = data.expiresAt;
|
|
34
|
+
loggedInUser = data.user || null;
|
|
35
|
+
log(`[deviceAuth] Restored session for ${loggedInUser?.username || "unknown"} from ${SESSION_FILE}`);
|
|
36
|
+
}
|
|
37
|
+
} catch {
|
|
38
|
+
// No saved session yet, or it's invalid/expired — fall through to requiring login.
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function saveSession() {
|
|
43
|
+
try {
|
|
44
|
+
fs.mkdirSync(path.dirname(SESSION_FILE), { recursive: true });
|
|
45
|
+
fs.writeFileSync(
|
|
46
|
+
SESSION_FILE,
|
|
47
|
+
JSON.stringify({ accessToken: userToken, expiresAt: userTokenExpiresAt, user: loggedInUser }),
|
|
48
|
+
{ mode: 0o600 }
|
|
49
|
+
);
|
|
50
|
+
} catch (err) {
|
|
51
|
+
log(`[deviceAuth] Failed to persist session: ${err.message}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
loadSession();
|
|
26
56
|
|
|
27
57
|
export function secondsSinceLoginInitiated() {
|
|
28
58
|
if (!loginInitiatedAt) return Infinity;
|
|
@@ -116,6 +146,7 @@ export async function pollDeviceLogin(timeoutSeconds = 300) {
|
|
|
116
146
|
name: claims?.name || claims?.preferred_username || "unknown",
|
|
117
147
|
email: claims?.email || null,
|
|
118
148
|
};
|
|
149
|
+
saveSession();
|
|
119
150
|
|
|
120
151
|
return {
|
|
121
152
|
expiresIn,
|
package/src/index.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import packageJson from "../package.json" with { type: "json" };
|
|
3
|
-
|
|
4
2
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
5
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
6
4
|
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
@@ -12,6 +10,9 @@ import crypto from "crypto";
|
|
|
12
10
|
import archiver from "archiver";
|
|
13
11
|
import FormData from "form-data";
|
|
14
12
|
import fetch from "node-fetch";
|
|
13
|
+
import { createRequire } from "module";
|
|
14
|
+
|
|
15
|
+
const packageJson = createRequire(import.meta.url)("../package.json");
|
|
15
16
|
|
|
16
17
|
import { getAccessToken, initiateDeviceLogin, pollDeviceLogin, isLoggedIn, getLoggedInUser, secondsSinceLoginInitiated, minSecondsBeforeConfirm } from "./deviceAuth.js";
|
|
17
18
|
|
|
@@ -183,7 +184,7 @@ async function uploadWorkspace(zipPath, workspaceId, language, buildTool) {
|
|
|
183
184
|
form.append("projectName", projectName);
|
|
184
185
|
|
|
185
186
|
// buildIndex check - setting it to false so that scip-ns is used.
|
|
186
|
-
form.append("buildIndex", "
|
|
187
|
+
form.append("buildIndex", "false");
|
|
187
188
|
|
|
188
189
|
// Indexing params
|
|
189
190
|
form.append("language", language);
|
|
@@ -282,7 +283,7 @@ async function sendFileUpdate(filePath, workspaceId, language, buildTool) {
|
|
|
282
283
|
form.append("workspaceAlias", getWorkspaceAlias(projectName));
|
|
283
284
|
|
|
284
285
|
// buildIndex check - setting it to false so that scip-ns is used.
|
|
285
|
-
form.append("buildIndex", "
|
|
286
|
+
form.append("buildIndex", "false");
|
|
286
287
|
|
|
287
288
|
// Indexing params
|
|
288
289
|
form.append("language", language);
|
|
@@ -448,6 +449,36 @@ function buildMcpServer() {
|
|
|
448
449
|
required: ["prompt"],
|
|
449
450
|
},
|
|
450
451
|
},
|
|
452
|
+
{
|
|
453
|
+
name: "locate",
|
|
454
|
+
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).",
|
|
463
|
+
inputSchema: {
|
|
464
|
+
type: "object",
|
|
465
|
+
properties: {
|
|
466
|
+
prompt: {
|
|
467
|
+
type: "string",
|
|
468
|
+
description: "Natural language query describing what to find (e.g. \"winner email\").",
|
|
469
|
+
},
|
|
470
|
+
limit: {
|
|
471
|
+
type: "number",
|
|
472
|
+
description: "Maximum number of ranked results to return (default 10, max 25).",
|
|
473
|
+
},
|
|
474
|
+
scope: {
|
|
475
|
+
type: "string",
|
|
476
|
+
description: "Optional path prefix/substring to restrict the search to a subdirectory or module.",
|
|
477
|
+
},
|
|
478
|
+
},
|
|
479
|
+
required: ["prompt"],
|
|
480
|
+
},
|
|
481
|
+
},
|
|
451
482
|
],
|
|
452
483
|
}));
|
|
453
484
|
|
|
@@ -643,13 +674,6 @@ function buildMcpServer() {
|
|
|
643
674
|
workspacePath: process.cwd(),
|
|
644
675
|
projectName: getProjectName(),
|
|
645
676
|
},
|
|
646
|
-
|
|
647
|
-
//tokenBudgetingEnabled: args.tokenBudgetingEnabled ?? true,
|
|
648
|
-
tokenBudgetingEnabled: false,
|
|
649
|
-
|
|
650
|
-
//maxTokenBudget: args.maxTokenBudget ?? 4000,
|
|
651
|
-
maxTokenBudget: 200000,
|
|
652
|
-
activeLandmarkLineCount: args.activeLandmarkLineCount ?? 15,
|
|
653
677
|
};
|
|
654
678
|
|
|
655
679
|
log("[bundle] Request body:", JSON.stringify(requestBody, null, 2));
|
|
@@ -671,10 +695,56 @@ function buildMcpServer() {
|
|
|
671
695
|
return {
|
|
672
696
|
content: [{
|
|
673
697
|
type: "text",
|
|
674
|
-
text:
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
698
|
+
text: body,
|
|
699
|
+
}],
|
|
700
|
+
};
|
|
701
|
+
|
|
702
|
+
} else if (name === "locate") {
|
|
703
|
+
if (!process.env.AUTH_ACCESS_TOKEN && !isLoggedIn()) return NOT_AUTHENTICATED;
|
|
704
|
+
const marker = readMarker();
|
|
705
|
+
if (!marker?.workspaceId) {
|
|
706
|
+
throw new Error("Workspace not set up yet. Call setup_workspace first.");
|
|
707
|
+
}
|
|
708
|
+
|
|
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));
|
|
729
|
+
|
|
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}`);
|
|
743
|
+
}
|
|
744
|
+
return {
|
|
745
|
+
content: [{
|
|
746
|
+
type: "text",
|
|
747
|
+
text: body,
|
|
678
748
|
}],
|
|
679
749
|
};
|
|
680
750
|
|