@tacitai/mcp-server 0.6.44 → 0.6.45

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/dist/cli.js CHANGED
@@ -4,7 +4,7 @@ import * as path from 'path';
4
4
  import * as os from 'os';
5
5
  import * as readline from 'readline';
6
6
  import { spawn } from 'child_process';
7
- import { deviceAuthFlow, deriveAppUrl, workspaceNameToProfile } from './setup.js';
7
+ import { deviceAuthFlow, loginFlow, deriveAppUrl, workspaceNameToProfile } from './setup.js';
8
8
  const PROFILES_DIR = path.join(os.homedir(), '.tacit', 'profiles');
9
9
  const DEFAULT_FILE = path.join(os.homedir(), '.tacit', 'default');
10
10
  const PROFILE_REGEX = /^[a-z0-9][a-z0-9-]{0,63}$/;
@@ -163,22 +163,27 @@ async function cmdLogin(args) {
163
163
  try {
164
164
  result = await deviceAuthFlow(apiUrl);
165
165
  }
166
- catch (err) {
167
- const msg = err instanceof Error ? err.message : String(err);
166
+ catch (deviceErr) {
167
+ const msg = deviceErr instanceof Error ? deviceErr.message : String(deviceErr);
168
168
  if (msg.includes('timed out')) {
169
169
  process.stderr.write('Authentication timed out (120s). Try again or check browser.\n');
170
+ process.exit(1);
171
+ return;
170
172
  }
171
173
  else if (msg.includes('state mismatch')) {
172
174
  process.stderr.write('Authentication failed: state mismatch. Try again.\n');
175
+ process.exit(1);
176
+ return;
173
177
  }
174
178
  else if (msg.includes('EADDRINUSE')) {
175
179
  process.stderr.write('Port 9123 busy (another login running?). Try again.\n');
180
+ process.exit(1);
181
+ return;
176
182
  }
177
- else {
178
- process.stderr.write(`Authentication failed: ${msg}\n`);
179
- }
180
- process.exit(1);
181
- return;
183
+ // Device-auth not available (e.g. 404) — fall back to PIN login.
184
+ process.stderr.write(' Browser sign-in not available. Falling back to email + PIN.\n');
185
+ const loginResult = await loginFlow(apiUrl);
186
+ result = { token: loginResult.token, expiresAt: loginResult.expiresAt, workspaceName: loginResult.workspaceName };
182
187
  }
183
188
  let workspaceId;
184
189
  let displayName = result.workspaceName;
package/dist/setup.d.ts CHANGED
@@ -48,6 +48,7 @@ export declare function deriveAppUrl(apiUrl: string): string;
48
48
  /**
49
49
  * Write ~/.tacit/profiles/<profile>.json with { expires_at, api_url }.
50
50
  * Token plaintext is NEVER written here — metadata only.
51
+ * @deprecated Prefer writeV2Profile for full profile data.
51
52
  */
52
53
  export declare function writeProfileMetadata(profile: string, expiresAt: string, apiUrl: string): void;
53
54
  interface DeviceAuthResult {
@@ -71,5 +72,11 @@ interface DeviceAuthResult {
71
72
  * - Browser open fails → print URL to stdout for manual copy-paste (AC-16 fallback).
72
73
  */
73
74
  export declare function deviceAuthFlow(apiUrl: string): Promise<DeviceAuthResult>;
75
+ interface LoginResult {
76
+ token: string;
77
+ workspaceName: string;
78
+ expiresAt: string;
79
+ }
80
+ export declare function loginFlow(apiUrl: string): Promise<LoginResult>;
74
81
  export declare function setup(argv: string[]): Promise<void>;
75
82
  export {};
package/dist/setup.js CHANGED
@@ -189,10 +189,27 @@ function mergeConfig(existing, profileName, entry) {
189
189
  function configToBytes(cfg) {
190
190
  return JSON.stringify(cfg, null, 2) + '\n';
191
191
  }
192
- // ─── Metadata file ────────────────────────────────────────────────────────────
192
+ function writeV2Profile(name, data) {
193
+ if (!/^[a-z0-9][a-z0-9-]{0,63}$/.test(name)) {
194
+ process.stderr.write(`[TACIT] Invalid profile name '${name}' — skipping profile write.\n`);
195
+ return;
196
+ }
197
+ const metaDir = path.join(os.homedir(), '.tacit', 'profiles');
198
+ fs.mkdirSync(metaDir, { recursive: true, mode: 0o700 });
199
+ try {
200
+ fs.chmodSync(metaDir, 0o700);
201
+ }
202
+ catch { /* unsupported OS */ }
203
+ const filePath = path.join(metaDir, `${name}.json`);
204
+ const tmp = filePath + '.tmp';
205
+ fs.writeFileSync(tmp, JSON.stringify(data, null, 2) + '\n', { mode: 0o600 });
206
+ fs.renameSync(tmp, filePath);
207
+ }
208
+ // ─── Metadata file (legacy v1) ───────────────────────────────────────────────
193
209
  /**
194
210
  * Write ~/.tacit/profiles/<profile>.json with { expires_at, api_url }.
195
211
  * Token plaintext is NEVER written here — metadata only.
212
+ * @deprecated Prefer writeV2Profile for full profile data.
196
213
  */
197
214
  export function writeProfileMetadata(profile, expiresAt, apiUrl) {
198
215
  if (!/^[a-z0-9][a-z0-9-]{0,63}$/.test(profile)) {
@@ -401,7 +418,7 @@ function prompt(question, hidden = false) {
401
418
  }
402
419
  });
403
420
  }
404
- async function loginFlow(apiUrl) {
421
+ export async function loginFlow(apiUrl) {
405
422
  process.stderr.write('\n Log in with your TACIT credentials.\n\n');
406
423
  const email = await prompt(' Email: ');
407
424
  const pin = await prompt(' PIN: ', true);
@@ -434,11 +451,12 @@ async function loginFlow(apiUrl) {
434
451
  const data = await res.json();
435
452
  const token = typeof data['session_token'] === 'string' ? data['session_token'] : '';
436
453
  const workspaceName = typeof data['workspace_name'] === 'string' ? data['workspace_name'] : '';
454
+ const expiresAt = typeof data['expires_at'] === 'string' ? data['expires_at'] : '';
437
455
  if (!token) {
438
456
  process.stderr.write('Error: login returned no session token.\n');
439
457
  process.exit(1);
440
458
  }
441
- return { token, workspaceName };
459
+ return { token, workspaceName, expiresAt };
442
460
  }
443
461
  // ─── Smoke synthesis ──────────────────────────────────────────────────────────
444
462
  const SMOKE_QUERY = 'What is in this knowledge base?';
@@ -512,11 +530,39 @@ export async function setup(argv) {
512
530
  if (!authenticated) {
513
531
  const loginResult = await loginFlow(apiUrl);
514
532
  token = loginResult.token;
533
+ if (loginResult.expiresAt)
534
+ expiresAt = loginResult.expiresAt;
515
535
  if (!opts.profileExplicit && loginResult.workspaceName) {
516
536
  profile = workspaceNameToProfile(loginResult.workspaceName);
517
537
  }
518
538
  }
519
539
  }
540
+ // Resolve workspace_id so we can write a full v2 profile.
541
+ let workspaceId = '';
542
+ let workspaceDisplayName = '';
543
+ if (token) {
544
+ try {
545
+ const wsResp = await fetch(apiUrl.endsWith('/api/v1')
546
+ ? `${apiUrl}/workspaces/mine`
547
+ : `${apiUrl}/api/v1/workspaces/mine`, { headers: { 'Authorization': `Bearer ${token}`, 'Accept': 'application/json' } });
548
+ if (wsResp.ok) {
549
+ const wsData = await wsResp.json();
550
+ workspaceId = typeof wsData['active_workspace_id'] === 'string' ? wsData['active_workspace_id'] : '';
551
+ if (Array.isArray(wsData['workspaces'])) {
552
+ const match = wsData['workspaces'].find(w => w.workspace_id === workspaceId || w.id === workspaceId);
553
+ if (match) {
554
+ const n = match.display_name ?? match.name;
555
+ if (typeof n === 'string')
556
+ workspaceDisplayName = n;
557
+ }
558
+ }
559
+ if (!opts.profileExplicit && workspaceDisplayName) {
560
+ profile = workspaceNameToProfile(workspaceDisplayName);
561
+ }
562
+ }
563
+ }
564
+ catch { /* workspace resolution failed — profile still works via .mcp.json fallback */ }
565
+ }
520
566
  // Final env-var name derived from (possibly updated) profile.
521
567
  const envVarName = profileToEnvVar(profile);
522
568
  // Pass the actual token when we have it (device-auth or --token);
@@ -560,8 +606,27 @@ export async function setup(argv) {
560
606
  const dest = mcpJsonPath();
561
607
  fs.writeFileSync(dest, output, { encoding: 'utf-8', mode: 0o600 });
562
608
  fs.chmodSync(dest, 0o600);
563
- // AC-12: write ~/.tacit/profiles/<profile>.json metadata (token NOT included).
564
- if (expiresAt) {
609
+ // Write a full v2 profile so `tacit launch <name>` works after setup.
610
+ if (resolvedToken && workspaceId) {
611
+ writeV2Profile(profile, {
612
+ version: 2,
613
+ workspace_id: workspaceId,
614
+ workspace_name: workspaceDisplayName || profile,
615
+ api_url: apiUrl,
616
+ app_url: deriveAppUrl(apiUrl),
617
+ token: resolvedToken,
618
+ created_at: new Date().toISOString(),
619
+ expires_at: expiresAt || undefined,
620
+ });
621
+ // Set as default profile if none exists.
622
+ const defaultFile = path.join(os.homedir(), '.tacit', 'default');
623
+ if (!fs.existsSync(defaultFile)) {
624
+ const dir = path.dirname(defaultFile);
625
+ fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
626
+ fs.writeFileSync(defaultFile, profile + '\n', { mode: 0o600 });
627
+ }
628
+ }
629
+ else if (expiresAt) {
565
630
  writeProfileMetadata(profile, expiresAt, apiUrl);
566
631
  }
567
632
  if (registered) {
@@ -578,6 +643,12 @@ export async function setup(argv) {
578
643
  ` export ${envVarName}=<your-token>\n` +
579
644
  `\n Then start a new Claude Code session to connect.\n`);
580
645
  }
646
+ // Show profile launch tip when a v2 profile was written.
647
+ if (resolvedToken && workspaceId) {
648
+ process.stdout.write(`\n Profile saved: ${profile}\n` +
649
+ ` Launch Claude Code with this workspace:\n` +
650
+ ` npx -p @tacitai/mcp-server tacit launch ${profile}\n`);
651
+ }
581
652
  if (opts.smoke) {
582
653
  await runSmoke(apiUrl, token);
583
654
  // runSmoke calls process.exit internally; return here for type safety.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tacitai/mcp-server",
3
- "version": "0.6.44",
3
+ "version": "0.6.45",
4
4
  "description": "stdio MCP server wrapping Tacit /api/v1 REST/SSE API",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {