@codeconductorai/harmony-mcp 1.0.9 → 1.0.11
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 +14 -8
- package/package.json +2 -1
- package/src/deviceAuth.js +2 -9
- package/src/fileFilters.js +139 -0
- package/src/fileWatcher.js +113 -0
- package/src/harmonyClient.js +330 -0
- package/src/index.js +15 -861
- package/src/log.js +12 -0
- package/src/repoIdentity.js +167 -0
- package/src/server.js +318 -0
- package/src/serverInstructions.js +89 -0
- package/src/toolSchemas.js +178 -0
- package/src/workspaceIdentity.js +39 -0
- package/src/workspaceMarker.js +18 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
// Shared `workspaceId` property, reused by every tool that queries a workspace (as opposed to
|
|
2
|
+
// setting one up), so the description can't drift between them.
|
|
3
|
+
const WORKSPACE_ID_PROPERTY = {
|
|
4
|
+
type: "string",
|
|
5
|
+
description:
|
|
6
|
+
"Optional: target a specific workspace instead of the local project's. Defaults to the " +
|
|
7
|
+
"local workspace set up by setup_workspace.",
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const TOOLS = [
|
|
11
|
+
{
|
|
12
|
+
name: "login",
|
|
13
|
+
description:
|
|
14
|
+
"Start a auth device-flow login session. Returns a loginUrl the user must open in their browser. " +
|
|
15
|
+
"IMPORTANT: after calling this tool you MUST (1) display the full loginUrl to the user clearly, " +
|
|
16
|
+
"(2) explicitly ask the user to open it and complete the login in their browser, and " +
|
|
17
|
+
"(3) wait for the user to confirm they have finished logging in before calling confirm_login. " +
|
|
18
|
+
"Do NOT call confirm_login automatically — the user must act first.",
|
|
19
|
+
inputSchema: { type: "object", properties: {}, required: [] },
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: "confirm_login",
|
|
23
|
+
description:
|
|
24
|
+
"Poll auth until the user's browser login is complete. Do NOT call this in the same turn as login. " +
|
|
25
|
+
"You must first show the loginUrl to the user and get an explicit reply from them (in the chat, in their " +
|
|
26
|
+
"own words) saying they've finished logging in. Only then call this tool with userConfirmed set to true. " +
|
|
27
|
+
"Calling this without a genuine reply from the user, or right after login, will be rejected.",
|
|
28
|
+
inputSchema: {
|
|
29
|
+
type: "object",
|
|
30
|
+
properties: {
|
|
31
|
+
userConfirmed: {
|
|
32
|
+
type: "boolean",
|
|
33
|
+
description:
|
|
34
|
+
"Set to true ONLY after the user has explicitly told you, in the conversation, that they completed " +
|
|
35
|
+
"the browser login. Never set this based on your own assumption or immediately after calling login.",
|
|
36
|
+
},
|
|
37
|
+
timeout: { type: "number", description: "Max seconds to wait for login (default: 300)." },
|
|
38
|
+
},
|
|
39
|
+
required: ["userConfirmed"],
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: "setup_workspace",
|
|
44
|
+
description:
|
|
45
|
+
"Set up AND fully index the current workspace on the backend in a single call (creates the workspace " +
|
|
46
|
+
"if needed, then zips and uploads the codebase). Safe to call repeatedly — already-completed steps are " +
|
|
47
|
+
"skipped, so calling it again after it has already succeeded is a cheap no-op. Required once per " +
|
|
48
|
+
"project before locate or get_context_bundle will work. If it fails partway (e.g. the upload step " +
|
|
49
|
+
"times out) after the workspace was already created, just call it again — language/buildTool can be " +
|
|
50
|
+
"omitted on that retry, since they're remembered from the first call.",
|
|
51
|
+
inputSchema: {
|
|
52
|
+
type: "object",
|
|
53
|
+
properties: {
|
|
54
|
+
language: {
|
|
55
|
+
type: "string",
|
|
56
|
+
description:
|
|
57
|
+
"Programming language (e.g. JAVA, JAVASCRIPT, TYPESCRIPT, PYTHON). Required the first time; can " +
|
|
58
|
+
"be omitted on a retry, since it's remembered from the workspace's prior setup call.",
|
|
59
|
+
},
|
|
60
|
+
buildTool: {
|
|
61
|
+
type: "string",
|
|
62
|
+
description:
|
|
63
|
+
"Build tool (e.g. MAVEN, GRADLE, NPM). Required the first time; can be omitted on a retry, since " +
|
|
64
|
+
"it's remembered from the workspace's prior setup call.",
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
required: [],
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: "get_context_bundle",
|
|
72
|
+
description: "Retrieve a coding context bundle for a prompt from the backend. Returns XML context.",
|
|
73
|
+
inputSchema: {
|
|
74
|
+
type: "object",
|
|
75
|
+
properties: {
|
|
76
|
+
prompt: {
|
|
77
|
+
type: "string",
|
|
78
|
+
description: "The natural language instruction or question to retrieve context for.",
|
|
79
|
+
},
|
|
80
|
+
workspaceId: WORKSPACE_ID_PROPERTY,
|
|
81
|
+
},
|
|
82
|
+
required: ["prompt"],
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: "locate",
|
|
87
|
+
description:
|
|
88
|
+
"Given a natural language query or exact identifier, returns ultra-light symbol coordinate anchors " +
|
|
89
|
+
"(file path, symbol name, symbol kind/type, whether it's a definition, line numbers, primary role) — " +
|
|
90
|
+
"no code snippets or documentation. Use this to find WHICH FILE(S) and exact line(s) to look at or " +
|
|
91
|
+
"edit for a task, e.g. every occurrence of a name across the codebase, or (scoped with file_path) " +
|
|
92
|
+
"exact line numbers within a file you already know. It does not return full file content — Read() the " +
|
|
93
|
+
"file once you have the line numbers if you need surrounding context beyond what the anchor tells you. " +
|
|
94
|
+
"A missing/blank prompt returns an empty result list rather than an error or 'match everything'.",
|
|
95
|
+
inputSchema: {
|
|
96
|
+
type: "object",
|
|
97
|
+
properties: {
|
|
98
|
+
prompt: {
|
|
99
|
+
type: "string",
|
|
100
|
+
description:
|
|
101
|
+
"REQUIRED. WHAT to find — a natural language query or a unique identifier such as a symbol name, " +
|
|
102
|
+
"class name, endpoint route, or API path (e.g. \"CrudController\", \"POST /api/v1/index/zip\", " +
|
|
103
|
+
"\"where is the retry logic\"). This is the only field the search text goes in, even when that " +
|
|
104
|
+
"text looks like a path (e.g. an API route or URL) — do not put it in file_path. Must be " +
|
|
105
|
+
"non-blank; an empty or whitespace-only prompt yields no results.",
|
|
106
|
+
},
|
|
107
|
+
file_path: {
|
|
108
|
+
type: "string",
|
|
109
|
+
description:
|
|
110
|
+
"OPTIONAL filter, not a query. Use ONLY to narrow results to a subdirectory, module, or specific " +
|
|
111
|
+
"source file already known to be on disk in THIS workspace (e.g. \"src/controllers\" or " +
|
|
112
|
+
"\"CrudController.java\") — matched as a case-insensitive substring against the indexed file path, " +
|
|
113
|
+
"not an exact-path or prefix match. Never put the search subject here: API routes/endpoints " +
|
|
114
|
+
"(\"/api/v1/index/zip\"), URLs, or anything you're trying to find belongs in `prompt` instead. " +
|
|
115
|
+
"Leave this empty unless you already know the specific file/folder to restrict to.",
|
|
116
|
+
},
|
|
117
|
+
limit: {
|
|
118
|
+
type: "number",
|
|
119
|
+
description: "Maximum number of results to return (default 40). The result list is never padded to this size.",
|
|
120
|
+
},
|
|
121
|
+
workspaceId: WORKSPACE_ID_PROPERTY,
|
|
122
|
+
},
|
|
123
|
+
required: ["prompt"],
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
name: "search_code_context",
|
|
128
|
+
description:
|
|
129
|
+
"Given a natural language query, returns rich Q&A context: matching symbols along with their code " +
|
|
130
|
+
"snippets, documentation, and decorators. Use this when you need to understand or explain how " +
|
|
131
|
+
"something works, not when you're about to make a targeted edit (use locate for that).",
|
|
132
|
+
inputSchema: {
|
|
133
|
+
type: "object",
|
|
134
|
+
properties: {
|
|
135
|
+
prompt: {
|
|
136
|
+
type: "string",
|
|
137
|
+
description: "Natural language query describing what to find context for or unique identifier describing what to search (e.g. CrudController).",
|
|
138
|
+
},
|
|
139
|
+
file_path: {
|
|
140
|
+
type: "string",
|
|
141
|
+
description: "Optional path substring to restrict results to a subdirectory, module, or specific file.",
|
|
142
|
+
},
|
|
143
|
+
limit: {
|
|
144
|
+
type: "number",
|
|
145
|
+
description: "Maximum number of results to return (default 15).",
|
|
146
|
+
},
|
|
147
|
+
workspaceId: WORKSPACE_ID_PROPERTY,
|
|
148
|
+
},
|
|
149
|
+
required: ["prompt"],
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
name: "find_files",
|
|
154
|
+
description:
|
|
155
|
+
"Given a natural language query, returns lightweight file path and architectural role/tag matches — " +
|
|
156
|
+
"no symbols or code content. Use this for broad file/module discovery (e.g. \"find all the " +
|
|
157
|
+
"controllers\") rather than pinpointing a specific edit location.",
|
|
158
|
+
inputSchema: {
|
|
159
|
+
type: "object",
|
|
160
|
+
properties: {
|
|
161
|
+
prompt: {
|
|
162
|
+
type: "string",
|
|
163
|
+
description: "Natural language query describing the kind of file to find.",
|
|
164
|
+
},
|
|
165
|
+
file_path: {
|
|
166
|
+
type: "string",
|
|
167
|
+
description: "Optional path substring to restrict results to a subdirectory, module, or specific file.",
|
|
168
|
+
},
|
|
169
|
+
limit: {
|
|
170
|
+
type: "number",
|
|
171
|
+
description: "Maximum number of results to return (default 30).",
|
|
172
|
+
},
|
|
173
|
+
workspaceId: WORKSPACE_ID_PROPERTY,
|
|
174
|
+
},
|
|
175
|
+
required: ["prompt"],
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
];
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { getLoggedInUser } from "./deviceAuth.js";
|
|
2
|
+
import { getGitBranch, getProjectName, resolveRepoId } from "./repoIdentity.js";
|
|
3
|
+
|
|
4
|
+
export function getCurrentUsername() {
|
|
5
|
+
return getLoggedInUser()?.username || "unknown";
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// Human-readable workspace alias: <username>_<projectName>_workspace.
|
|
9
|
+
export function getWorkspaceAlias(projectName) {
|
|
10
|
+
return `${getCurrentUsername()}_${projectName}_workspace`;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function stableId(str) {
|
|
14
|
+
let hash = 0;
|
|
15
|
+
for (let i = 0; i < str.length; i++) {
|
|
16
|
+
hash = Math.imul(31, hash) + str.charCodeAt(i) | 0;
|
|
17
|
+
}
|
|
18
|
+
return Math.abs(hash);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const PRODUCT_ID = stableId(getProjectName());
|
|
22
|
+
export const APP_ID = stableId(process.cwd());
|
|
23
|
+
export const REPO_IDENTITY = resolveRepoId();
|
|
24
|
+
export const REPO_ID = REPO_IDENTITY.repoId;
|
|
25
|
+
|
|
26
|
+
// WorkspaceMetadata fields sent with uploads and search/bundle requests.
|
|
27
|
+
export function buildWorkspaceMetadata(workspaceId) {
|
|
28
|
+
const projectName = getProjectName();
|
|
29
|
+
return {
|
|
30
|
+
workspaceId,
|
|
31
|
+
productId: PRODUCT_ID,
|
|
32
|
+
appId: APP_ID,
|
|
33
|
+
repoId: REPO_ID,
|
|
34
|
+
branchName: getGitBranch(),
|
|
35
|
+
workspaceAlias: getWorkspaceAlias(projectName),
|
|
36
|
+
workspacePath: process.cwd(),
|
|
37
|
+
projectName,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
|
|
4
|
+
export const WORKSPACE_MARKER = ".harmony_workspace.json";
|
|
5
|
+
|
|
6
|
+
// Read and parse the workspace marker file; null if missing or invalid.
|
|
7
|
+
export function readMarker() {
|
|
8
|
+
try {
|
|
9
|
+
return JSON.parse(fs.readFileSync(path.join(process.cwd(), WORKSPACE_MARKER), "utf8"));
|
|
10
|
+
} catch {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Write workspace state to the marker file.
|
|
16
|
+
export function writeMarker(data) {
|
|
17
|
+
fs.writeFileSync(path.join(process.cwd(), WORKSPACE_MARKER), JSON.stringify(data, null, 2));
|
|
18
|
+
}
|