@tacitai/mcp-server 0.6.42 → 0.6.44

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
@@ -66,6 +66,12 @@ function loadProfile(name) {
66
66
  process.stderr.write(`Profile '${name}' was created by setup and lacks credentials. Re-run: npx -p @tacitai/mcp-server tacit login\n`);
67
67
  process.exit(1);
68
68
  }
69
+ for (const field of ['workspace_id', 'token', 'api_url']) {
70
+ if (!data[field] || typeof data[field] !== 'string') {
71
+ process.stderr.write(`Profile '${name}' is missing required field '${field}'. Re-run: npx -p @tacitai/mcp-server tacit login\n`);
72
+ process.exit(1);
73
+ }
74
+ }
69
75
  return data;
70
76
  }
71
77
  function writeProfile(name, data) {
@@ -98,6 +104,10 @@ function tryLoadProfile(name) {
98
104
  const data = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
99
105
  if (data.version !== 2)
100
106
  return null;
107
+ for (const field of ['workspace_id', 'token', 'api_url']) {
108
+ if (!data[field] || typeof data[field] !== 'string')
109
+ return null;
110
+ }
101
111
  return data;
102
112
  }
103
113
  catch {
@@ -329,6 +339,12 @@ function cmdStatus() {
329
339
  else if (wsId && token) {
330
340
  process.stdout.write('\nResolved via env vars (TACIT_WORKSPACE_ID + TACIT_TOKEN)\n');
331
341
  }
342
+ else if (token && !wsId) {
343
+ process.stdout.write('\nTACIT_TOKEN is set but TACIT_WORKSPACE_ID is missing — workspace cannot be resolved.\n');
344
+ }
345
+ else if (wsId && !token) {
346
+ process.stdout.write('\nTACIT_WORKSPACE_ID is set but TACIT_TOKEN is missing — authentication will fail.\n');
347
+ }
332
348
  else if (defaultName) {
333
349
  const p = tryLoadProfile(defaultName);
334
350
  if (p) {
package/dist/client.js CHANGED
@@ -475,13 +475,13 @@ export function loadProfile(name) {
475
475
  * Throws on set-but-invalid states (profile missing, WORKSPACE_ID without TOKEN).
476
476
  */
477
477
  export function resolveProfileOptions() {
478
- // Level 1: TACIT_PROFILE env → load profile
478
+ // Level 1: TACIT_PROFILE env → load profile (profile values take precedence over stray env vars)
479
479
  const profileName = process.env['TACIT_PROFILE'];
480
480
  if (isNonEmpty(profileName)) {
481
481
  const profile = loadProfile(profileName);
482
482
  return {
483
- apiUrl: isNonEmpty(process.env['TACIT_API_URL']) ? process.env['TACIT_API_URL'].trim() : profile.api_url,
484
- appUrl: isNonEmpty(process.env['TACIT_APP_URL']) ? process.env['TACIT_APP_URL'].trim() : profile.app_url,
483
+ apiUrl: profile.api_url,
484
+ appUrl: profile.app_url,
485
485
  token: profile.token,
486
486
  workspaceId: profile.workspace_id,
487
487
  };
package/dist/index.js CHANGED
@@ -229,6 +229,8 @@ function parseProfile(argv) {
229
229
  return 'tacit';
230
230
  }
231
231
  function checkProfileExpiry(profile) {
232
+ if (!/^[a-z0-9][a-z0-9-]{0,63}$/.test(profile))
233
+ return;
232
234
  const metaPath = path.join(os.homedir(), '.tacit', 'profiles', `${profile}.json`);
233
235
  if (!fs.existsSync(metaPath)) {
234
236
  return;
@@ -316,6 +318,17 @@ async function run() {
316
318
  if (!isHttpMode) {
317
319
  try {
318
320
  profileOpts = resolveProfileOptions();
321
+ // Propagate profile credentials to process.env so the module-level getClient()
322
+ // singleton (used by ~107 tool call sites) picks up the correct identity.
323
+ // Without this, tools would use stale env vars from the parent shell.
324
+ if (profileOpts) {
325
+ if (profileOpts.apiUrl)
326
+ process.env['TACIT_API_URL'] = profileOpts.apiUrl;
327
+ if (profileOpts.token)
328
+ process.env['TACIT_TOKEN'] = profileOpts.token;
329
+ if (profileOpts.workspaceId)
330
+ process.env['TACIT_WORKSPACE_ID'] = profileOpts.workspaceId;
331
+ }
319
332
  }
320
333
  catch (err) {
321
334
  const msg = err instanceof Error ? err.message : String(err);
package/dist/setup.js CHANGED
@@ -76,6 +76,10 @@ function parseArgs(argv) {
76
76
  process.stderr.write('Error: --profile requires a value\n');
77
77
  process.exit(1);
78
78
  }
79
+ if (!/^[a-z0-9][a-z0-9-]{0,63}$/.test(next)) {
80
+ process.stderr.write(`Error: invalid profile name '${next}'. Names must be lowercase alphanumeric with hyphens.\n`);
81
+ process.exit(1);
82
+ }
79
83
  opts.profile = next;
80
84
  opts.profileExplicit = true;
81
85
  i++;
@@ -106,7 +110,10 @@ export function profileToEnvVar(profile) {
106
110
  * AC-12: lowercased, spaces→hyphens, non-alphanumeric-hyphen stripped.
107
111
  */
108
112
  export function workspaceNameToProfile(name) {
109
- return name.toLowerCase().replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, '');
113
+ const slug = name.toLowerCase().replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, '').replace(/^-+/, '');
114
+ if (!slug || !/^[a-z0-9]/.test(slug))
115
+ return 'workspace';
116
+ return slug.slice(0, 64);
110
117
  }
111
118
  function claudeDir() {
112
119
  return path.join(os.homedir(), '.claude');
@@ -188,6 +195,10 @@ function configToBytes(cfg) {
188
195
  * Token plaintext is NEVER written here — metadata only.
189
196
  */
190
197
  export function writeProfileMetadata(profile, expiresAt, apiUrl) {
198
+ if (!/^[a-z0-9][a-z0-9-]{0,63}$/.test(profile)) {
199
+ process.stderr.write(`[TACIT] Invalid profile name '${profile}' — skipping metadata write.\n`);
200
+ return;
201
+ }
191
202
  const metaDir = path.join(os.homedir(), '.tacit', 'profiles');
192
203
  fs.mkdirSync(metaDir, { recursive: true, mode: 0o700 });
193
204
  try {
@@ -195,12 +206,14 @@ export function writeProfileMetadata(profile, expiresAt, apiUrl) {
195
206
  }
196
207
  catch { /* unsupported OS */ }
197
208
  const filePath = path.join(metaDir, `${profile}.json`);
198
- // v2 non-clobber: if a login profile exists, don't overwrite with metadata-only
209
+ // v2 non-clobber: if a login profile exists, update expires_at and api_url in place
199
210
  if (fs.existsSync(filePath)) {
200
211
  try {
201
212
  const existing = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
202
213
  if (existing.version === 2) {
203
- process.stderr.write(`[TACIT] Profile '${profile}' is a v2 login profile — skipping metadata write.\n`);
214
+ existing.expires_at = expiresAt;
215
+ existing.api_url = apiUrl;
216
+ fs.writeFileSync(filePath, JSON.stringify(existing, null, 2), { mode: 0o600 });
204
217
  return;
205
218
  }
206
219
  }
@@ -410,7 +423,11 @@ async function loginFlow(apiUrl) {
410
423
  process.stderr.write('\n Login failed — check your email and PIN.\n');
411
424
  }
412
425
  else {
413
- process.stderr.write(`\n Login failed (${res.status}): ${body}\n`);
426
+ const isHtml = body.trimStart().startsWith('<!') || body.trimStart().startsWith('<html');
427
+ const detail = isHtml
428
+ ? `The server returned an HTML page instead of a JSON response.\n This usually means --api-url points to the web app, not the API.\n Try without --api-url (the default is correct for most users),\n or use the API URL (e.g. https://api-beta.tacitai.app).`
429
+ : body.slice(0, 200);
430
+ process.stderr.write(`\n Login failed (${res.status}): ${detail}\n`);
414
431
  }
415
432
  process.exit(1);
416
433
  }
@@ -458,7 +475,17 @@ async function runSmoke(apiUrl, token) {
458
475
  export async function setup(argv) {
459
476
  const opts = parseArgs(argv);
460
477
  // Resolve api-url: flag > env > default.
461
- const apiUrl = opts.apiUrl ?? process.env['TACIT_API_URL'] ?? 'https://api-beta.tacitai.app';
478
+ let apiUrl = opts.apiUrl ?? process.env['TACIT_API_URL'] ?? 'https://api-beta.tacitai.app';
479
+ // Auto-correct common mistake: frontend URL (beta.tacitai.app) → API URL (api-beta.tacitai.app).
480
+ try {
481
+ const parsed = new URL(apiUrl);
482
+ if (/^(?!api[-.]).*\.tacitai\.app$/.test(parsed.hostname)) {
483
+ const corrected = `${parsed.protocol}//api-${parsed.hostname}`;
484
+ process.stderr.write(`\n Note: ${apiUrl} looks like the web app URL.\n Using API URL instead: ${corrected}\n\n`);
485
+ apiUrl = corrected;
486
+ }
487
+ }
488
+ catch { /* invalid URL — let it fail naturally downstream */ }
462
489
  // Determine profile and token.
463
490
  let profile = opts.profile;
464
491
  let token = opts.token;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tacitai/mcp-server",
3
- "version": "0.6.42",
3
+ "version": "0.6.44",
4
4
  "description": "stdio MCP server wrapping Tacit /api/v1 REST/SSE API",
5
5
  "license": "UNLICENSED",
6
6
  "repository": {