@codeconductorai/harmony-mcp 1.0.3 → 1.0.5
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/package.json +20 -4
- package/src/deviceAuth.js +3 -22
- package/src/index.js +9 -8
- package/hooks.json +0 -33
package/package.json
CHANGED
|
@@ -1,17 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeconductorai/harmony-mcp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"license": "MIT",
|
|
6
5
|
"main": "src/index.js",
|
|
7
6
|
"bin": {
|
|
8
7
|
"harmony-mcp": "./src/index.js"
|
|
9
8
|
},
|
|
9
|
+
"files": [
|
|
10
|
+
"src"
|
|
11
|
+
],
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=18"
|
|
14
|
+
},
|
|
10
15
|
"scripts": {
|
|
11
16
|
"start": "node src/index.js",
|
|
12
|
-
"start:stdio": "node src/index.js"
|
|
13
|
-
"start:http": "node --env-file=.env src/index.js --http"
|
|
17
|
+
"start:stdio": "node src/index.js"
|
|
14
18
|
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"mcp",
|
|
21
|
+
"model-context-protocol",
|
|
22
|
+
"claude",
|
|
23
|
+
"claude-code",
|
|
24
|
+
"harmony",
|
|
25
|
+
"codeconductor",
|
|
26
|
+
"context-bundle",
|
|
27
|
+
"codeconductorai"
|
|
28
|
+
],
|
|
29
|
+
"author": "CodeConductor",
|
|
30
|
+
"license": "MIT",
|
|
15
31
|
"dependencies": {
|
|
16
32
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
17
33
|
"archiver": "^7.0.0",
|
package/src/deviceAuth.js
CHANGED
|
@@ -3,11 +3,9 @@ import fs from "fs";
|
|
|
3
3
|
import os from "os";
|
|
4
4
|
import path from "path";
|
|
5
5
|
|
|
6
|
-
// The harmony backend proxies the Keycloak device-flow login — it holds the
|
|
7
|
-
// Keycloak client id/secret (from Vault) so this MCP server never needs to.
|
|
8
6
|
const API_URL = (process.env.API_URL || "https://harmony.codeconductor.ai/").replace(/\/+$/, "");
|
|
9
7
|
|
|
10
|
-
const LOG_FILE = path.join(os.tmpdir(), "
|
|
8
|
+
const LOG_FILE = path.join(os.tmpdir(), "harmony-mcp.log");
|
|
11
9
|
const logStream = fs.createWriteStream(LOG_FILE, { flags: "a" });
|
|
12
10
|
|
|
13
11
|
function log(...args) {
|
|
@@ -21,12 +19,9 @@ let userTokenExpiresAt = 0;
|
|
|
21
19
|
let loggedInUser = null;
|
|
22
20
|
|
|
23
21
|
let pendingDeviceCode = null;
|
|
24
|
-
let pendingPollInterval = 5;
|
|
22
|
+
let pendingPollInterval = 5;
|
|
25
23
|
let loginInitiatedAt = 0;
|
|
26
24
|
|
|
27
|
-
// The user needs real wall-clock time to open a browser and complete the
|
|
28
|
-
// Keycloak login — anything faster than this is the assistant chaining
|
|
29
|
-
// straight into confirm_login instead of waiting for the user.
|
|
30
25
|
const MIN_SECONDS_BEFORE_CONFIRM = 10;
|
|
31
26
|
|
|
32
27
|
export function secondsSinceLoginInitiated() {
|
|
@@ -54,19 +49,10 @@ function sleep(ms) {
|
|
|
54
49
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
55
50
|
}
|
|
56
51
|
|
|
57
|
-
/*
|
|
58
|
-
* The harmony backend has shipped both a raw Keycloak-shaped (snake_case)
|
|
59
|
-
* response and a camelCase DTO response for these endpoints at different
|
|
60
|
-
* times. Accept either so this doesn't silently break again on a deploy.
|
|
61
|
-
*/
|
|
62
52
|
function field(data, camelKey, snakeKey) {
|
|
63
53
|
return data?.[camelKey] ?? data?.[snakeKey];
|
|
64
54
|
}
|
|
65
55
|
|
|
66
|
-
/*
|
|
67
|
-
* Step 1 — ask harmony to start a Keycloak device-flow login session.
|
|
68
|
-
* Returns the URL the user must visit and the user_code to enter.
|
|
69
|
-
*/
|
|
70
56
|
export async function initiateDeviceLogin() {
|
|
71
57
|
const res = await fetch(`${API_URL}/api/apps/public/auth/login`, { method: "POST" });
|
|
72
58
|
log(`[deviceAuth] initiateDeviceLogin URL: ${API_URL}/api/apps/public/auth/login`);
|
|
@@ -89,10 +75,6 @@ export async function initiateDeviceLogin() {
|
|
|
89
75
|
};
|
|
90
76
|
}
|
|
91
77
|
|
|
92
|
-
/*
|
|
93
|
-
* Step 2 — poll harmony until the user completes login or the session expires.
|
|
94
|
-
* Blocks for up to `timeoutSeconds` (default 5 min).
|
|
95
|
-
*/
|
|
96
78
|
export async function pollDeviceLogin(timeoutSeconds = 300) {
|
|
97
79
|
if (!pendingDeviceCode) {
|
|
98
80
|
throw new Error("No pending login session. Call login first.");
|
|
@@ -152,7 +134,6 @@ export async function pollDeviceLogin(timeoutSeconds = 300) {
|
|
|
152
134
|
throw new Error("Login session expired. Call login again to start a new one.");
|
|
153
135
|
}
|
|
154
136
|
|
|
155
|
-
// data.status === "error"
|
|
156
137
|
throw new Error(`Login failed: ${data.message || "unknown error"}`);
|
|
157
138
|
}
|
|
158
139
|
|
|
@@ -164,7 +145,7 @@ export function isLoggedIn() {
|
|
|
164
145
|
}
|
|
165
146
|
|
|
166
147
|
export async function getAccessToken() {
|
|
167
|
-
if (process.env.
|
|
148
|
+
if (process.env.AUTH_ACCESS_TOKEN) return process.env.AUTH_ACCESS_TOKEN;
|
|
168
149
|
if (isLoggedIn()) return userToken;
|
|
169
150
|
throw new Error("Not authenticated. Call the login tool, then confirm_login, before retrying.");
|
|
170
151
|
}
|
package/src/index.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import packageJson from "../package.json" with { type: "json" };
|
|
2
3
|
|
|
3
4
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
4
5
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
5
6
|
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
6
7
|
|
|
7
8
|
import fs from "fs";
|
|
8
|
-
import path from "path";
|
|
9
9
|
import os from "os";
|
|
10
|
+
import path from "path";
|
|
10
11
|
import crypto from "crypto";
|
|
11
12
|
import archiver from "archiver";
|
|
12
13
|
import FormData from "form-data";
|
|
@@ -19,7 +20,7 @@ const WORKSPACE_MARKER = ".harmony_workspace.json";
|
|
|
19
20
|
|
|
20
21
|
let fileWatcher = null;
|
|
21
22
|
|
|
22
|
-
const LOG_FILE = path.join(os.tmpdir(), "
|
|
23
|
+
const LOG_FILE = path.join(os.tmpdir(), "harmony-mcp.log");
|
|
23
24
|
const logStream = fs.createWriteStream(LOG_FILE, { flags: "a" });
|
|
24
25
|
|
|
25
26
|
function log(...args) {
|
|
@@ -105,7 +106,7 @@ function writeMarker(data) {
|
|
|
105
106
|
*/
|
|
106
107
|
async function zipWorkspace() {
|
|
107
108
|
const workspacePath = process.cwd();
|
|
108
|
-
const zipPath =
|
|
109
|
+
const zipPath = `/tmp/workspace-${Date.now()}.zip`;
|
|
109
110
|
return new Promise((resolve, reject) => {
|
|
110
111
|
const output = fs.createWriteStream(zipPath);
|
|
111
112
|
const archive = archiver("zip", { zlib: { level: 9 } });
|
|
@@ -375,7 +376,7 @@ function startFileWatcher() {
|
|
|
375
376
|
*/
|
|
376
377
|
function buildMcpServer() {
|
|
377
378
|
const server = new Server(
|
|
378
|
-
{ name: "
|
|
379
|
+
{ name: "harmony-mcp-server", version: packageJson.version },
|
|
379
380
|
{ capabilities: { tools: {} } }
|
|
380
381
|
);
|
|
381
382
|
|
|
@@ -538,7 +539,7 @@ function buildMcpServer() {
|
|
|
538
539
|
}
|
|
539
540
|
|
|
540
541
|
} else if (name === "setup_workspace") {
|
|
541
|
-
if (!process.env.
|
|
542
|
+
if (!process.env.AUTH_ACCESS_TOKEN && !isLoggedIn()) return NOT_AUTHENTICATED;
|
|
542
543
|
const language = args.language;
|
|
543
544
|
const buildTool = args.buildTool;
|
|
544
545
|
if (!language || !buildTool) {
|
|
@@ -594,7 +595,7 @@ function buildMcpServer() {
|
|
|
594
595
|
};
|
|
595
596
|
|
|
596
597
|
} else if (name === "upload_workspace") {
|
|
597
|
-
if (!process.env.
|
|
598
|
+
if (!process.env.AUTH_ACCESS_TOKEN && !isLoggedIn()) return NOT_AUTHENTICATED;
|
|
598
599
|
const marker = readMarker();
|
|
599
600
|
if (!marker?.language || !marker?.buildTool) {
|
|
600
601
|
throw new Error("Workspace not initialized. Call setup_workspace with language and buildTool first.");
|
|
@@ -620,7 +621,7 @@ function buildMcpServer() {
|
|
|
620
621
|
};
|
|
621
622
|
|
|
622
623
|
} else if (name === "get_context_bundle") {
|
|
623
|
-
if (!process.env.
|
|
624
|
+
if (!process.env.AUTH_ACCESS_TOKEN && !isLoggedIn()) return NOT_AUTHENTICATED;
|
|
624
625
|
const marker = readMarker();
|
|
625
626
|
if (!marker?.workspaceId) {
|
|
626
627
|
throw new Error("Workspace not set up yet. Call setup_workspace first.");
|
|
@@ -688,7 +689,7 @@ function buildMcpServer() {
|
|
|
688
689
|
const transport = new StdioServerTransport();
|
|
689
690
|
const server = buildMcpServer();
|
|
690
691
|
await server.connect(transport);
|
|
691
|
-
log(`
|
|
692
|
+
log(`Harmony MCP started (stdio) | user: ${getCurrentUsername()}`);
|
|
692
693
|
|
|
693
694
|
try {
|
|
694
695
|
startFileWatcher();
|
package/hooks.json
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"hooks": {
|
|
3
|
-
"PreToolUse": [
|
|
4
|
-
{
|
|
5
|
-
"matcher": "Read",
|
|
6
|
-
"hooks": [
|
|
7
|
-
{
|
|
8
|
-
"type": "command",
|
|
9
|
-
"command": "f=$(jq -r '.tool_input.file_path // \"the requested file\"'); jq -n --arg f \"$f\" '{hookSpecificOutput:{hookEventName:\"PreToolUse\",permissionDecision:\"deny\",permissionDecisionReason:(\"Do not use Read on \" + $f + \". Use the get_context_bundle tool from the axiomem-mcp MCP server instead: call it with a prompt describing what you need from \" + $f + \", then use the returned context instead of reading the file yourself.\")}}'"
|
|
10
|
-
}
|
|
11
|
-
]
|
|
12
|
-
},
|
|
13
|
-
{
|
|
14
|
-
"matcher": "Grep",
|
|
15
|
-
"hooks": [
|
|
16
|
-
{
|
|
17
|
-
"type": "command",
|
|
18
|
-
"command": "p=$(jq -r '.tool_input.pattern // \"the search\"'); jq -n --arg p \"$p\" '{hookSpecificOutput:{hookEventName:\"PreToolUse\",permissionDecision:\"deny\",permissionDecisionReason:(\"Do not use Grep for \\\"\" + $p + \"\\\". Use the get_context_bundle tool from the axiomem-mcp MCP server instead: call it with a prompt describing what you are looking for, then use the returned context instead of grepping files yourself.\")}}'"
|
|
19
|
-
}
|
|
20
|
-
]
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
"matcher": "Bash",
|
|
24
|
-
"hooks": [
|
|
25
|
-
{
|
|
26
|
-
"type": "command",
|
|
27
|
-
"command": "cmd=$(jq -r '.tool_input.command // \"\"'); if echo \"$cmd\" | grep -Eq '(^|[;&|(]|[[:space:]])(cat|head|tail)([[:space:]]|$)'; then jq -n --arg cmd \"$cmd\" '{hookSpecificOutput:{hookEventName:\"PreToolUse\",permissionDecision:\"deny\",permissionDecisionReason:(\"Blocked bash command: \" + $cmd + \". Do not read files via cat/head/tail. Use the get_context_bundle tool from the axiomem-mcp MCP server instead: call it with a prompt describing what you need, then use the returned context instead of reading the file yourself.\")}}'; else exit 0; fi"
|
|
28
|
-
}
|
|
29
|
-
]
|
|
30
|
-
}
|
|
31
|
-
]
|
|
32
|
-
}
|
|
33
|
-
}
|