@codeconductorai/harmony-mcp 1.0.14 → 1.0.16

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 CHANGED
@@ -27,12 +27,12 @@ Re-run `node -v` afterwards to confirm before continuing.
27
27
 
28
28
  ## Installation
29
29
 
30
- The server is published as `@codeconductorai/harmony-mcp` and run via `npx`, so no local build step is required. The commands below pin an exact version (`@1.0.14`) rather than a floating tag — this lets `npx` reuse its local cache instead of re-resolving the package from the registry on every agent startup, which otherwise makes MCP initialization noticeably slower (and occasionally hang). Bump the pinned version deliberately when you want to upgrade.
30
+ The server is published as `@codeconductorai/harmony-mcp` and run via `npx`, so no local build step is required. The commands below pin an exact version (`@1.0.16`) rather than a floating tag — this lets `npx` reuse its local cache instead of re-resolving the package from the registry on every agent startup, which otherwise makes MCP initialization noticeably slower (and occasionally hang). Bump the pinned version deliberately when you want to upgrade.
31
31
 
32
32
  ### Claude Code
33
33
 
34
34
  ```bash
35
- claude mcp add harmony -- npx -y @codeconductorai/harmony-mcp@1.0.14
35
+ claude mcp add harmony -- npx -y @codeconductorai/harmony-mcp@1.0.16
36
36
  ```
37
37
 
38
38
  ### Antigravity
@@ -47,7 +47,7 @@ Open **MCP Servers → Manage MCP Servers → View raw config** from the agent p
47
47
  "mcpServers": {
48
48
  "harmony": {
49
49
  "command": "npx",
50
- "args": ["-y", "@codeconductorai/harmony-mcp@1.0.14"]
50
+ "args": ["-y", "@codeconductorai/harmony-mcp@1.0.16"]
51
51
  }
52
52
  }
53
53
  }
@@ -58,7 +58,7 @@ Restart Antigravity (or reload MCP servers) after saving.
58
58
  ### Codex CLI
59
59
 
60
60
  ```bash
61
- codex mcp add harmony -- npx -y @codeconductorai/harmony-mcp@1.0.14
61
+ codex mcp add harmony -- npx -y @codeconductorai/harmony-mcp@1.0.16
62
62
  ```
63
63
 
64
64
  This writes the entry to `~/.codex/config.toml`. To add it by hand instead:
@@ -66,7 +66,7 @@ This writes the entry to `~/.codex/config.toml`. To add it by hand instead:
66
66
  ```toml
67
67
  [mcp_servers.harmony]
68
68
  command = "npx"
69
- args = ["-y", "@codeconductorai/harmony-mcp@1.0.14"]
69
+ args = ["-y", "@codeconductorai/harmony-mcp@1.0.16"]
70
70
  ```
71
71
 
72
72
  ### Aria
@@ -78,7 +78,7 @@ In the Aria Code panel, click the settings icon → **MCP Servers**, then scroll
78
78
  "mcpServers": {
79
79
  "harmony": {
80
80
  "command": "npx",
81
- "args": ["-y", "@codeconductorai/harmony-mcp@1.0.14"]
81
+ "args": ["-y", "@codeconductorai/harmony-mcp@1.0.16"]
82
82
  }
83
83
  }
84
84
  }
@@ -95,7 +95,7 @@ Any client that reads a `command`/`args` style config (e.g. Claude Desktop's `cl
95
95
  "mcpServers": {
96
96
  "harmony": {
97
97
  "command": "npx",
98
- "args": ["-y", "@codeconductorai/harmony-mcp@1.0.14"]
98
+ "args": ["-y", "@codeconductorai/harmony-mcp@1.0.16"]
99
99
  }
100
100
  }
101
101
  }
@@ -105,13 +105,19 @@ Any client that reads a `command`/`args` style config (e.g. Claude Desktop's `cl
105
105
 
106
106
  After adding the server and restarting your client:
107
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.
108
+ 1. **`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. Call this first, even before logging in: some backend deployments authenticate the workspace internally with no login involved at all, so this can succeed on its own. 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.
109
+ 2. If `setup_workspace` (or any tool below) fails with a "not authenticated" error, this deployment requires login: call **`login`**, which starts a device-flow login and returns a URL to open in your browser.
110
+ 3. 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. Call `setup_workspace` again afterward.
111
111
  4. Use **`context_search`** first to pull relevant code context for a prompt — it's Harmony's newest, best-ranked search endpoint, always available as the default entry point for every discovery need in a task, and takes precedence over the others below. Fall back to **`locate`**, **`search_code_context`**, **`find_files`**, or **`get_context_bundle`** only if it comes up short or you need one of their specialized output shapes — and when you do, feed the fallback tool a combination of the user's original query and the symbols/identifiers/file paths `context_search` already surfaced, not the raw query on its own.
112
112
 
113
113
  Workspace state (workspace ID, language, build tool, setup/upload status) is cached in a `.harmony_workspace.json` marker file in the project root.
114
114
 
115
+ ### Workspace-token auth and refresh
116
+
117
+ On deployments that skip login entirely (step 1 above), `setup_workspace`'s first call gets back two credentials instead of one: a short-lived access token (used as the Bearer on every API call) and a long-lived refresh token. Both are stored in `~/.harmony-mcp/workspace-tokens.json` — never in the project's `.harmony_workspace.json` marker, since that file has no guarantee of staying out of version control and these are bearer credentials.
118
+
119
+ This is fully automatic — no tool call or user action needed. Before every API request, the access token's expiry is checked locally; once it's expired (or close to it), the stored refresh token is exchanged for a new access token behind the scenes and the request proceeds with it. Only if the refresh token itself is missing or has expired does a call start failing with a "not authenticated" error, at which point running `setup_workspace` again mints a fresh pair.
120
+
115
121
  ## Tools
116
122
 
117
123
  ### `login`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codeconductorai/harmony-mcp",
3
- "version": "1.0.14",
3
+ "version": "1.0.16",
4
4
  "type": "module",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/deviceAuth.js CHANGED
@@ -5,10 +5,11 @@ import path from "path";
5
5
 
6
6
  import { log } from "./log.js";
7
7
 
8
- const API_URL = (process.env.API_URL || "https://expenditure-advertisements-necessary-indianapolis.trycloudflare.com/").replace(/\/+$/, "");
8
+ const API_URL = (process.env.API_URL || "https://harmony.codeconductor.ai/").replace(/\/+$/, "");
9
9
 
10
10
  let userToken = null;
11
11
  let userTokenExpiresAt = 0;
12
+ let userRefreshToken = null;
12
13
  let loggedInUser = null;
13
14
 
14
15
  let pendingDeviceCode = null;
@@ -17,18 +18,22 @@ let loginInitiatedAt = 0;
17
18
 
18
19
  const MIN_SECONDS_BEFORE_CONFIRM = 10;
19
20
  const SESSION_FILE = path.join(os.homedir(), ".harmony-mcp", "session.json");
21
+ const WORKSPACE_TOKENS_FILE = path.join(os.homedir(), ".harmony-mcp", "workspace-tokens.json");
20
22
 
21
23
  function loadSession() {
22
24
  try {
23
25
  const data = JSON.parse(fs.readFileSync(SESSION_FILE, "utf8"));
26
+ loggedInUser = data.user || null;
27
+ userRefreshToken = data.refreshToken || null;
24
28
  if (data.accessToken && data.expiresAt > Math.floor(Date.now() / 1000)) {
25
29
  userToken = data.accessToken;
26
30
  userTokenExpiresAt = data.expiresAt;
27
- loggedInUser = data.user || null;
28
31
  log(`[deviceAuth] Restored session for ${loggedInUser?.username || "unknown"} from ${SESSION_FILE}`);
32
+ } else if (userRefreshToken) {
33
+ log(`[deviceAuth] Restored expired session for ${loggedInUser?.username || "unknown"} — will refresh on next use.`);
29
34
  }
30
35
  } catch {
31
- // No saved session yet, or it's invalid/expired — fall through to requiring login.
36
+ // No saved session yet, or it's invalid — fall through to requiring login.
32
37
  }
33
38
  }
34
39
 
@@ -37,7 +42,12 @@ function saveSession() {
37
42
  fs.mkdirSync(path.dirname(SESSION_FILE), { recursive: true });
38
43
  fs.writeFileSync(
39
44
  SESSION_FILE,
40
- JSON.stringify({ accessToken: userToken, expiresAt: userTokenExpiresAt, user: loggedInUser }),
45
+ JSON.stringify({
46
+ accessToken: userToken,
47
+ expiresAt: userTokenExpiresAt,
48
+ refreshToken: userRefreshToken,
49
+ user: loggedInUser,
50
+ }),
41
51
  { mode: 0o600 }
42
52
  );
43
53
  } catch (err) {
@@ -131,6 +141,7 @@ export async function pollDeviceLogin(timeoutSeconds = 300) {
131
141
  const now = Math.floor(Date.now() / 1000);
132
142
  userToken = accessToken;
133
143
  userTokenExpiresAt = now + (expiresIn || 300);
144
+ userRefreshToken = field(data, "refreshToken", "refresh_token") || userRefreshToken;
134
145
  pendingDeviceCode = null;
135
146
 
136
147
  const claims = decodeJwtPayload(accessToken);
@@ -173,8 +184,82 @@ export function isLoggedIn() {
173
184
  return !!userToken && userTokenExpiresAt > Math.floor(Date.now() / 1000);
174
185
  }
175
186
 
176
- export async function getAccessToken() {
187
+ export function hasSessionCredential() {
188
+ return Boolean(userToken || userRefreshToken);
189
+ }
190
+
191
+ async function refreshSessionToken() {
192
+ if (!userRefreshToken) return null;
193
+ try {
194
+ const res = await fetch(`${API_URL}/api/apps/public/auth/refresh`, {
195
+ method: "POST",
196
+ headers: { "Content-Type": "application/json" },
197
+ body: JSON.stringify({ refreshToken: userRefreshToken }),
198
+ });
199
+ const data = await res.json();
200
+ if (!res.ok || data.status !== "complete" || !data.accessToken) {
201
+ log(`[deviceAuth] Session refresh failed: ${data.message || res.status}`);
202
+ return null;
203
+ }
204
+ userToken = data.accessToken;
205
+ userTokenExpiresAt = Math.floor(Date.now() / 1000) + (data.expiresIn || 300);
206
+ if (data.refreshToken) userRefreshToken = data.refreshToken;
207
+ saveSession();
208
+ log(`[deviceAuth] Session refreshed for ${loggedInUser?.username || "unknown"}`);
209
+ return userToken;
210
+ } catch (error) {
211
+ log(`[deviceAuth] Session refresh request failed: ${error.message}`);
212
+ return null;
213
+ }
214
+ }
215
+
216
+ export async function getSessionToken() {
177
217
  if (process.env.AUTH_ACCESS_TOKEN) return process.env.AUTH_ACCESS_TOKEN;
178
218
  if (isLoggedIn()) return userToken;
179
- throw new Error("Not authenticated. Call the login tool, then confirm_login, before retrying.");
219
+ return refreshSessionToken();
220
+ }
221
+
222
+ function loadWorkspaceTokens() {
223
+ try {
224
+ return JSON.parse(fs.readFileSync(WORKSPACE_TOKENS_FILE, "utf8"));
225
+ } catch {
226
+ return {};
227
+ }
228
+ }
229
+
230
+ function normalizeTokenRecord(record) {
231
+ if (!record) return null;
232
+ return typeof record === "string" ? { accessToken: record, refreshToken: null } : record;
233
+ }
234
+
235
+ export function isJwtExpired(token, skewSeconds = 30) {
236
+ const claims = decodeJwtPayload(token);
237
+ if (!claims?.exp) return false;
238
+ return claims.exp * 1000 <= Date.now() + skewSeconds * 1000;
239
+ }
240
+
241
+ export function getWorkspaceToken(workspaceId) {
242
+ if (!workspaceId) return null;
243
+ return normalizeTokenRecord(loadWorkspaceTokens()[workspaceId])?.accessToken || null;
244
+ }
245
+
246
+ export function getWorkspaceRefreshToken(workspaceId) {
247
+ if (!workspaceId) return null;
248
+ return normalizeTokenRecord(loadWorkspaceTokens()[workspaceId])?.refreshToken || null;
249
+ }
250
+
251
+ export function saveWorkspaceToken(workspaceId, accessToken, refreshToken) {
252
+ if (!workspaceId || !accessToken) return;
253
+ try {
254
+ const tokens = loadWorkspaceTokens();
255
+ const existing = normalizeTokenRecord(tokens[workspaceId]);
256
+ tokens[workspaceId] = {
257
+ accessToken,
258
+ refreshToken: refreshToken || existing?.refreshToken || null,
259
+ };
260
+ fs.mkdirSync(path.dirname(WORKSPACE_TOKENS_FILE), { recursive: true });
261
+ fs.writeFileSync(WORKSPACE_TOKENS_FILE, JSON.stringify(tokens, null, 2), { mode: 0o600 });
262
+ } catch (err) {
263
+ log(`[deviceAuth] Failed to persist workspace token: ${err.message}`);
264
+ }
180
265
  }
@@ -6,13 +6,59 @@ import FormData from "form-data";
6
6
  import fetch from "node-fetch";
7
7
 
8
8
  import { log } from "./log.js";
9
- import { getAccessToken } from "./deviceAuth.js";
9
+ import {
10
+ getSessionToken,
11
+ getWorkspaceToken,
12
+ getWorkspaceRefreshToken,
13
+ saveWorkspaceToken,
14
+ isJwtExpired,
15
+ } from "./deviceAuth.js";
10
16
  import { buildWorkspaceMetadata, PRODUCT_ID, APP_ID, REPO_ID } from "./workspaceIdentity.js";
11
17
  import { readMarker, writeMarker } from "./workspaceMarker.js";
12
18
  import { getGitCommitHash } from "./repoIdentity.js";
13
19
  import { buildZipIgnoreGlobs } from "./fileFilters.js";
14
20
 
15
- export const API_URL = (process.env.API_URL || "https://expenditure-advertisements-necessary-indianapolis.trycloudflare.com/").replace(/\/+$/, "");
21
+ export const API_URL = (process.env.API_URL || "https://harmony.codeconductor.ai/").replace(/\/+$/, "");
22
+
23
+ async function refreshWorkspaceToken(workspaceId, refreshToken) {
24
+ const response = await fetch(`${API_URL}/api/code-workspace/${workspaceId}/refresh-token`, {
25
+ method: "POST",
26
+ headers: { "X-Workspace-Refresh-Token": refreshToken },
27
+ });
28
+ const body = await response.text();
29
+ if (!response.ok) {
30
+ throw new Error(`Workspace token refresh failed: ${response.status} ${body}`);
31
+ }
32
+ const newAccessToken = response.headers.get("x-workspace-token");
33
+ if (!newAccessToken) {
34
+ throw new Error("Workspace token refresh succeeded but no X-Workspace-Token header was returned.");
35
+ }
36
+ saveWorkspaceToken(workspaceId, newAccessToken);
37
+ return newAccessToken;
38
+ }
39
+
40
+ async function resolveToken(workspaceId) {
41
+ const sessionToken = await getSessionToken();
42
+ if (sessionToken) return sessionToken;
43
+
44
+ const accessToken = getWorkspaceToken(workspaceId);
45
+ if (accessToken && !isJwtExpired(accessToken)) return accessToken;
46
+
47
+ const refreshToken = getWorkspaceRefreshToken(workspaceId);
48
+ if (!refreshToken) return accessToken;
49
+
50
+ try {
51
+ return await refreshWorkspaceToken(workspaceId, refreshToken);
52
+ } catch (error) {
53
+ log(`[auth] Workspace token refresh failed: ${error.message}`);
54
+ return accessToken;
55
+ }
56
+ }
57
+
58
+ async function authHeader(workspaceId) {
59
+ const token = await resolveToken(workspaceId);
60
+ return token ? { Authorization: `Bearer ${token}` } : {};
61
+ }
16
62
 
17
63
  // Zip the working directory, excluding whatever the backend's WorkspaceFileFilter would discard anyway.
18
64
  async function zipWorkspace() {
@@ -43,20 +89,24 @@ export async function setupWorkspace(workspaceId, language, buildTool) {
43
89
  url.searchParams.set("language", language);
44
90
  if (buildTool) url.searchParams.set("buildTool", buildTool);
45
91
 
46
- const token = await getAccessToken();
47
92
  const response = await fetch(url.toString(), {
48
93
  method: "POST",
49
- headers: { Authorization: `Bearer ${token}` },
94
+ headers: await authHeader(workspaceId),
50
95
  });
51
96
  const body = await response.text();
52
97
  log("Setup status:", response.status);
53
98
  log("Setup response:", body);
54
99
  if (!response.ok) {
55
- throw new Error(`Setup failed: ${response.status} ${body}`);
100
+ const hint = response.status === 401
101
+ ? " (this deployment requires login — call the login tool first)"
102
+ : "";
103
+ throw new Error(`Setup failed: ${response.status} ${body}${hint}`);
56
104
  }
57
105
  return {
58
106
  status: response.status,
59
107
  response: body,
108
+ workspaceToken: response.headers.get("x-workspace-token") || undefined,
109
+ workspaceRefreshToken: response.headers.get("x-workspace-refresh-token") || undefined,
60
110
  };
61
111
  } catch (error) {
62
112
  return {
@@ -86,11 +136,10 @@ export async function uploadWorkspace(zipPath, workspaceId, language, buildTool)
86
136
  const url = `${API_URL}/api/v1/index/zip`;
87
137
  log("Uploading to:", url);
88
138
 
89
- const token = await getAccessToken();
90
139
  const response = await fetch(url, {
91
140
  method: "POST",
92
141
  body: form,
93
- headers: { ...form.getHeaders(), Authorization: `Bearer ${token}` },
142
+ headers: { ...form.getHeaders(), ...(await authHeader(workspaceId)) },
94
143
  });
95
144
  const body = await response.text();
96
145
  log("Upload status:", response.status);
@@ -138,6 +187,9 @@ export async function ensureWorkspaceUploaded(language, buildTool) {
138
187
  upload: { done: false },
139
188
  };
140
189
  writeMarker(marker);
190
+ if (setupResult.workspaceToken) {
191
+ saveWorkspaceToken(workspaceId, setupResult.workspaceToken, setupResult.workspaceRefreshToken);
192
+ }
141
193
  } else {
142
194
  workspaceId = marker.workspaceId;
143
195
  }
@@ -170,13 +222,12 @@ const TERMINAL_STATUSES = new Set([
170
222
  ]);
171
223
 
172
224
  async function fetchWorkspaceStatus(workspaceId) {
173
- const token = await getAccessToken();
174
225
  const url = new URL(`/api/code-workspace/${workspaceId}/status`, API_URL);
175
226
  url.searchParams.set("productId", PRODUCT_ID);
176
227
  url.searchParams.set("appId", APP_ID);
177
228
  url.searchParams.set("repoId", REPO_ID);
178
229
  const response = await fetch(url.toString(), {
179
- headers: { Accept: "application/xml", Authorization: `Bearer ${token}` },
230
+ headers: { Accept: "application/xml", ...(await authHeader(workspaceId)) },
180
231
  });
181
232
  if (response.status === 404) return null;
182
233
  const body = await response.text();
@@ -228,13 +279,12 @@ export async function callHarmonySearchEndpoint(endpointPath, args, workspaceId)
228
279
 
229
280
  log(`[${endpointPath}] Request body:`, JSON.stringify(requestBody, null, 2));
230
281
 
231
- const token = await getAccessToken();
232
282
  const response = await fetch(`${API_URL}/api/code-workspace/${workspaceId}/${endpointPath}`, {
233
283
  method: "POST",
234
284
  headers: {
235
285
  "Content-Type": "application/json",
236
286
  Accept: "application/xml",
237
- Authorization: `Bearer ${token}`,
287
+ ...(await authHeader(workspaceId)),
238
288
  },
239
289
  body: JSON.stringify(requestBody),
240
290
  });
@@ -255,13 +305,12 @@ export async function fetchContextBundle(workspaceId, prompt) {
255
305
 
256
306
  log("[bundle] Request body:", JSON.stringify(requestBody, null, 2));
257
307
 
258
- const token = await getAccessToken();
259
308
  const response = await fetch(`${API_URL}/api/code-workspace/${workspaceId}/bundle`, {
260
309
  method: "POST",
261
310
  headers: {
262
311
  "Content-Type": "application/json",
263
312
  Accept: "application/xml",
264
- Authorization: `Bearer ${token}`,
313
+ ...(await authHeader(workspaceId)),
265
314
  },
266
315
  body: JSON.stringify(requestBody),
267
316
  });
@@ -313,11 +362,10 @@ export async function sendFileUpdate(filePath, workspaceId, language, buildTool)
313
362
  form.append("files", fs.createReadStream(filePath), { filename: path.basename(filePath) });
314
363
  form.append("paths", path.relative(workspacePath, filePath));
315
364
 
316
- const token = await getAccessToken();
317
365
  const response = await fetch(`${API_URL}/api/v1/index/files`, {
318
366
  method: "POST",
319
367
  body: form,
320
- headers: { ...form.getHeaders(), Authorization: `Bearer ${token}` },
368
+ headers: { ...form.getHeaders(), ...(await authHeader(workspaceId)) },
321
369
  });
322
370
  const body = await response.text();
323
371
  log(`[fileWatcher] ${path.relative(process.cwd(), filePath)} -> ${response.status}`);
package/src/server.js CHANGED
@@ -8,10 +8,11 @@ import { log } from "./log.js";
8
8
  import {
9
9
  initiateDeviceLogin,
10
10
  pollDeviceLogin,
11
- isLoggedIn,
11
+ hasSessionCredential,
12
12
  getLoggedInUser,
13
13
  secondsSinceLoginInitiated,
14
14
  minSecondsBeforeConfirm,
15
+ getWorkspaceToken,
15
16
  } from "./deviceAuth.js";
16
17
  import { getGitCommitHash, getProjectName } from "./repoIdentity.js";
17
18
  import { getCurrentUsername, REPO_ID, REPO_IDENTITY } from "./workspaceIdentity.js";
@@ -55,8 +56,9 @@ function resolveWorkspaceId(args) {
55
56
  return workspaceId;
56
57
  }
57
58
 
58
- function isAuthenticated() {
59
- return Boolean(process.env.AUTH_ACCESS_TOKEN || isLoggedIn());
59
+ function isAuthenticated(args) {
60
+ if (process.env.AUTH_ACCESS_TOKEN || hasSessionCredential()) return true;
61
+ return Boolean(getWorkspaceToken(args?.workspaceId || readMarker()?.workspaceId));
60
62
  }
61
63
 
62
64
  async function handleLogin() {
@@ -289,7 +291,7 @@ const TOOL_HANDLERS = {
289
291
  find_files: makeSearchHandler("find-files", "find_files"),
290
292
  };
291
293
 
292
- const AUTH_EXEMPT_TOOLS = new Set(["login", "confirm_login"]);
294
+ const AUTH_EXEMPT_TOOLS = new Set(["login", "confirm_login", "setup_workspace"]);
293
295
 
294
296
  // Build the MCP server: tool listing, and the tools/call dispatcher.
295
297
  export function buildMcpServer() {
@@ -308,7 +310,7 @@ export function buildMcpServer() {
308
310
  if (!handler) {
309
311
  throw new Error(`Unknown tool: ${name}`);
310
312
  }
311
- if (!AUTH_EXEMPT_TOOLS.has(name) && !isAuthenticated()) {
313
+ if (!AUTH_EXEMPT_TOOLS.has(name) && !isAuthenticated(args)) {
312
314
  return NOT_AUTHENTICATED;
313
315
  }
314
316
  return handler(args, extra);
@@ -1,4 +1,4 @@
1
- import { isLoggedIn } from "./deviceAuth.js";
1
+ import { hasSessionCredential, getWorkspaceToken } from "./deviceAuth.js";
2
2
  import { readMarker } from "./workspaceMarker.js";
3
3
 
4
4
  const QUERY_REFINEMENT = `
@@ -144,9 +144,13 @@ Workspace setup — before the first search/locate/context call in a project:
144
144
  `.trim();
145
145
 
146
146
  const AUTH_INSTRUCTIONS = `
147
- Auth gate — setup_workspace, get_context_bundle, context_search, locate, search_code_context and find_files all return a "not
148
- authenticated" error until login has succeeded. Do not attempt to work around this by
149
- guessing tokens or skipping the tool; just run the login flow below.
147
+ Auth gate — get_context_bundle, context_search, locate, search_code_context and find_files all
148
+ return a "not authenticated" error until login has succeeded; run the login flow below before
149
+ using them. setup_workspace is the one exception: call it directly even before logging in — it
150
+ uses the login session when one exists, but some deployments authenticate the workspace
151
+ internally instead, with no login involved at all, so it can succeed on its own. It will fail
152
+ with a clear message telling you to log in if this deployment actually requires it. Do not
153
+ attempt to work around a real auth failure by guessing tokens or skipping the tool.
150
154
  - Call \`login\`, show the returned loginUrl to the user verbatim, and ask them to complete it in
151
155
  their browser.
152
156
  - Wait for the user's own explicit confirmation in chat that they've finished. Never call
@@ -156,8 +160,8 @@ guessing tokens or skipping the tool; just run the login flow below.
156
160
 
157
161
  // Build the server's `instructions` string from current auth/workspace state.
158
162
  export function buildServerInstructions() {
159
- const authed = Boolean(process.env.AUTH_ACCESS_TOKEN || isLoggedIn());
160
163
  const marker = readMarker();
164
+ const authed = Boolean(process.env.AUTH_ACCESS_TOKEN || hasSessionCredential() || getWorkspaceToken(marker?.workspaceId));
161
165
  const ready = Boolean(authed && marker?.setup?.done && marker?.upload?.done);
162
166
 
163
167
  const sections = [