@tacitai/mcp-server 0.7.0 → 0.8.1

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.
Files changed (73) hide show
  1. package/dist/api-errors.d.ts +102 -0
  2. package/dist/api-errors.js +165 -0
  3. package/dist/autonomy.d.ts +46 -0
  4. package/dist/autonomy.js +118 -0
  5. package/dist/claude-config.d.ts +139 -0
  6. package/dist/claude-config.js +339 -0
  7. package/dist/cli-launch.d.ts +33 -0
  8. package/dist/cli-launch.js +178 -0
  9. package/dist/cli-login.d.ts +34 -0
  10. package/dist/cli-login.js +200 -0
  11. package/dist/cli-mode.d.ts +47 -0
  12. package/dist/cli-mode.js +170 -0
  13. package/dist/cli-profiles.d.ts +37 -0
  14. package/dist/cli-profiles.js +344 -0
  15. package/dist/cli.d.ts +9 -0
  16. package/dist/cli.js +59 -458
  17. package/dist/client.d.ts +90 -52
  18. package/dist/client.js +198 -296
  19. package/dist/credentials.d.ts +81 -0
  20. package/dist/credentials.js +291 -0
  21. package/dist/index.d.ts +3 -3
  22. package/dist/index.js +37 -89
  23. package/dist/oauth.d.ts +1 -1
  24. package/dist/oauth.js +5 -5
  25. package/dist/profile-store.d.ts +96 -0
  26. package/dist/profile-store.js +382 -0
  27. package/dist/prompt.d.ts +32 -0
  28. package/dist/prompt.js +99 -0
  29. package/dist/prompts.d.ts +2 -2
  30. package/dist/prompts.js +3 -3
  31. package/dist/server-mode.d.ts +65 -0
  32. package/dist/server-mode.js +99 -0
  33. package/dist/setup-migrate.d.ts +35 -0
  34. package/dist/setup-migrate.js +204 -0
  35. package/dist/setup.d.ts +41 -66
  36. package/dist/setup.js +361 -531
  37. package/dist/signin.d.ts +108 -0
  38. package/dist/signin.js +595 -0
  39. package/dist/tools/agents.d.ts +6 -4
  40. package/dist/tools/agents.js +15 -4
  41. package/dist/tools/artifacts.d.ts +2 -0
  42. package/dist/tools/artifacts.js +8 -1
  43. package/dist/tools/capture.js +2 -2
  44. package/dist/tools/career.js +2 -2
  45. package/dist/tools/chronicle.js +7 -7
  46. package/dist/tools/crews.js +8 -8
  47. package/dist/tools/errors.d.ts +18 -0
  48. package/dist/tools/errors.js +73 -1
  49. package/dist/tools/exec-route.d.ts +34 -0
  50. package/dist/tools/exec-route.js +101 -27
  51. package/dist/tools/github.js +2 -2
  52. package/dist/tools/gm.js +2 -2
  53. package/dist/tools/iam.js +2 -3
  54. package/dist/tools/kb.js +2 -2
  55. package/dist/tools/lake-structure.js +8 -8
  56. package/dist/tools/lake.js +2 -2
  57. package/dist/tools/onboarding.js +2 -2
  58. package/dist/tools/people.js +7 -7
  59. package/dist/tools/pyramid.js +2 -2
  60. package/dist/tools/recall.js +2 -2
  61. package/dist/tools/secretary.d.ts +1 -0
  62. package/dist/tools/secretary.js +2 -1
  63. package/dist/tools/synthesize.d.ts +37 -0
  64. package/dist/tools/synthesize.js +128 -9
  65. package/dist/tools/voice.d.ts +3 -2
  66. package/dist/tools/voice.js +70 -18
  67. package/dist/tools/wiki.js +2 -2
  68. package/dist/tools/workspaces.js +20 -6
  69. package/dist/version.d.ts +6 -0
  70. package/dist/version.js +18 -0
  71. package/dist/workflow-registry.d.ts +1 -0
  72. package/dist/workflow-registry.js +21 -0
  73. package/package.json +4 -1
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { TacitApiError } from '../client.js';
2
+ import { TacitApiError, TokenExpiredError } from '../client.js';
3
3
  import { success, error, featureDisabledResult } from './errors.js';
4
4
  export function registerLakeStructureTools(server, getClient) {
5
5
  server.tool('tacit_lake_propose_structure', 'Generate a v7 structure proposal for a registered source. Does NOT modify the repo.', {
@@ -11,7 +11,7 @@ export function registerLakeStructureTools(server, getClient) {
11
11
  return success(data);
12
12
  }
13
13
  catch (e) {
14
- if (e instanceof TacitApiError)
14
+ if (e instanceof TacitApiError || e instanceof TokenExpiredError)
15
15
  return featureDisabledResult(e) ?? error(e.message);
16
16
  return error(`Unexpected error: ${e instanceof Error ? e.message : String(e)}`);
17
17
  }
@@ -33,7 +33,7 @@ export function registerLakeStructureTools(server, getClient) {
33
33
  return success(data);
34
34
  }
35
35
  catch (e) {
36
- if (e instanceof TacitApiError)
36
+ if (e instanceof TacitApiError || e instanceof TokenExpiredError)
37
37
  return featureDisabledResult(e) ?? error(e.message);
38
38
  return error(`Unexpected error: ${e instanceof Error ? e.message : String(e)}`);
39
39
  }
@@ -47,7 +47,7 @@ export function registerLakeStructureTools(server, getClient) {
47
47
  return success(data);
48
48
  }
49
49
  catch (e) {
50
- if (e instanceof TacitApiError)
50
+ if (e instanceof TacitApiError || e instanceof TokenExpiredError)
51
51
  return featureDisabledResult(e) ?? error(e.message);
52
52
  return error(`Unexpected error: ${e instanceof Error ? e.message : String(e)}`);
53
53
  }
@@ -70,7 +70,7 @@ export function registerLakeStructureTools(server, getClient) {
70
70
  return success(data);
71
71
  }
72
72
  catch (e) {
73
- if (e instanceof TacitApiError)
73
+ if (e instanceof TacitApiError || e instanceof TokenExpiredError)
74
74
  return featureDisabledResult(e) ?? error(e.message);
75
75
  return error(`Unexpected error: ${e instanceof Error ? e.message : String(e)}`);
76
76
  }
@@ -86,7 +86,7 @@ export function registerLakeStructureTools(server, getClient) {
86
86
  return success(data);
87
87
  }
88
88
  catch (e) {
89
- if (e instanceof TacitApiError)
89
+ if (e instanceof TacitApiError || e instanceof TokenExpiredError)
90
90
  return featureDisabledResult(e) ?? error(e.message);
91
91
  return error(`Unexpected error: ${e instanceof Error ? e.message : String(e)}`);
92
92
  }
@@ -102,7 +102,7 @@ export function registerLakeStructureTools(server, getClient) {
102
102
  return success(data);
103
103
  }
104
104
  catch (e) {
105
- if (e instanceof TacitApiError)
105
+ if (e instanceof TacitApiError || e instanceof TokenExpiredError)
106
106
  return featureDisabledResult(e) ?? error(e.message);
107
107
  return error(`Unexpected error: ${e instanceof Error ? e.message : String(e)}`);
108
108
  }
@@ -118,7 +118,7 @@ export function registerLakeStructureTools(server, getClient) {
118
118
  return success(data);
119
119
  }
120
120
  catch (e) {
121
- if (e instanceof TacitApiError)
121
+ if (e instanceof TacitApiError || e instanceof TokenExpiredError)
122
122
  return featureDisabledResult(e) ?? error(e.message);
123
123
  return error(`Unexpected error: ${e instanceof Error ? e.message : String(e)}`);
124
124
  }
@@ -26,7 +26,7 @@
26
26
  */
27
27
  import { z } from 'zod';
28
28
  import { getClient, TacitApiError, TokenExpiredError } from '../client.js';
29
- import { featureDisabledResult } from './errors.js';
29
+ import { featureDisabledResult, apiErrorText } from './errors.js';
30
30
  function apiErrorResult(err, toolName) {
31
31
  if (err instanceof TokenExpiredError) {
32
32
  return {
@@ -38,7 +38,7 @@ function apiErrorResult(err, toolName) {
38
38
  const disabled = featureDisabledResult(err);
39
39
  if (disabled)
40
40
  return disabled;
41
- return { content: [{ type: 'text', text: `API error ${err.statusCode} on ${toolName}: ${err.body}` }], isError: true };
41
+ return { content: [{ type: 'text', text: apiErrorText(err, toolName) }], isError: true };
42
42
  }
43
43
  const msg = err instanceof Error ? err.message : String(err);
44
44
  return { content: [{ type: 'text', text: `Error: ${msg}` }], isError: true };
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { TacitApiError } from '../client.js';
2
+ import { TacitApiError, TokenExpiredError } from '../client.js';
3
3
  import { success, error, featureDisabledResult } from './errors.js';
4
4
  import { EXPERIENCES, fetchWorkspaceState, normalizeCompleted } from '../prompts.js';
5
5
  export function registerOnboardingTools(server, getClient) {
@@ -104,7 +104,7 @@ export function registerOnboardingTools(server, getClient) {
104
104
  });
105
105
  }
106
106
  catch (e) {
107
- if (e instanceof TacitApiError)
107
+ if (e instanceof TacitApiError || e instanceof TokenExpiredError)
108
108
  return featureDisabledResult(e) ?? error(e.message);
109
109
  return error(`Unexpected error: ${e instanceof Error ? e.message : String(e)}`);
110
110
  }
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import { TacitApiError } from '../client.js';
2
+ import { TacitApiError, TokenExpiredError } from '../client.js';
3
3
  import { success, error, featureDisabledResult } from './errors.js';
4
4
  export function registerPeopleTools(server, getClient) {
5
5
  server.tool('tacit_list_people', 'List all people in the current workspace.', {}, async () => {
@@ -9,7 +9,7 @@ export function registerPeopleTools(server, getClient) {
9
9
  return success(data);
10
10
  }
11
11
  catch (e) {
12
- if (e instanceof TacitApiError)
12
+ if (e instanceof TacitApiError || e instanceof TokenExpiredError)
13
13
  return featureDisabledResult(e) ?? error(e.message);
14
14
  return error(`Unexpected error: ${e instanceof Error ? e.message : String(e)}`);
15
15
  }
@@ -23,7 +23,7 @@ export function registerPeopleTools(server, getClient) {
23
23
  return success(data);
24
24
  }
25
25
  catch (e) {
26
- if (e instanceof TacitApiError)
26
+ if (e instanceof TacitApiError || e instanceof TokenExpiredError)
27
27
  return featureDisabledResult(e) ?? error(e.message);
28
28
  return error(`Unexpected error: ${e instanceof Error ? e.message : String(e)}`);
29
29
  }
@@ -39,7 +39,7 @@ export function registerPeopleTools(server, getClient) {
39
39
  return success(data);
40
40
  }
41
41
  catch (e) {
42
- if (e instanceof TacitApiError)
42
+ if (e instanceof TacitApiError || e instanceof TokenExpiredError)
43
43
  return featureDisabledResult(e) ?? error(e.message);
44
44
  return error(`Unexpected error: ${e instanceof Error ? e.message : String(e)}`);
45
45
  }
@@ -61,7 +61,7 @@ export function registerPeopleTools(server, getClient) {
61
61
  return success(data);
62
62
  }
63
63
  catch (e) {
64
- if (e instanceof TacitApiError)
64
+ if (e instanceof TacitApiError || e instanceof TokenExpiredError)
65
65
  return featureDisabledResult(e) ?? error(e.message);
66
66
  return error(`Unexpected error: ${e instanceof Error ? e.message : String(e)}`);
67
67
  }
@@ -80,7 +80,7 @@ export function registerPeopleTools(server, getClient) {
80
80
  return success(data);
81
81
  }
82
82
  catch (e) {
83
- if (e instanceof TacitApiError)
83
+ if (e instanceof TacitApiError || e instanceof TokenExpiredError)
84
84
  return featureDisabledResult(e) ?? error(e.message);
85
85
  return error(`Unexpected error: ${e instanceof Error ? e.message : String(e)}`);
86
86
  }
@@ -92,7 +92,7 @@ export function registerPeopleTools(server, getClient) {
92
92
  return success(data);
93
93
  }
94
94
  catch (e) {
95
- if (e instanceof TacitApiError)
95
+ if (e instanceof TacitApiError || e instanceof TokenExpiredError)
96
96
  return featureDisabledResult(e) ?? error(e.message);
97
97
  return error(`Unexpected error: ${e instanceof Error ? e.message : String(e)}`);
98
98
  }
@@ -11,7 +11,7 @@
11
11
  */
12
12
  import { z } from 'zod';
13
13
  import { getClient, getRequestPrincipal, TacitApiError, TokenExpiredError } from '../client.js';
14
- import { apiErrorResult as sharedApiErrorResult, featureDisabledResult } from './errors.js';
14
+ import { apiErrorResult as sharedApiErrorResult, featureDisabledResult, apiErrorText } from './errors.js';
15
15
  import { GM_LIST_TOOL_NEXT_STEP } from '../workflow-gate.js';
16
16
  function apiErrorResult(err, toolName) {
17
17
  if (err instanceof TokenExpiredError) {
@@ -24,7 +24,7 @@ function apiErrorResult(err, toolName) {
24
24
  const disabled = featureDisabledResult(err);
25
25
  if (disabled)
26
26
  return disabled;
27
- return { content: [{ type: 'text', text: `API error ${err.statusCode} on ${toolName}: ${err.body}` }], isError: true };
27
+ return { content: [{ type: 'text', text: apiErrorText(err, toolName) }], isError: true };
28
28
  }
29
29
  const msg = err instanceof Error ? err.message : String(err);
30
30
  return { content: [{ type: 'text', text: `Error: ${msg}` }], isError: true };
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import { z } from 'zod';
6
6
  import { getClient, TacitApiError, TokenExpiredError } from '../client.js';
7
- import { featureDisabledResult } from './errors.js';
7
+ import { apiErrorText, featureDisabledResult } from './errors.js';
8
8
  export const recallInputSchema = z.object({
9
9
  query: z.string().min(1).describe('Recall query'),
10
10
  portfolio_id: z.string().min(1).describe('Portfolio UUID to scope the recall'),
@@ -50,7 +50,7 @@ export function buildRecallRequest(client, input) {
50
50
  const disabled = featureDisabledResult(err);
51
51
  if (disabled)
52
52
  return disabled;
53
- return { content: [{ type: 'text', text: `API error ${err.statusCode}: ${err.body}` }], isError: true };
53
+ return { content: [{ type: 'text', text: apiErrorText(err) }], isError: true };
54
54
  }
55
55
  const msg = err instanceof Error ? err.message : String(err);
56
56
  return { content: [{ type: 'text', text: `Error: ${msg}` }], isError: true };
@@ -15,6 +15,7 @@ export interface LogPayloadArgs {
15
15
  chapter_id?: string;
16
16
  participants?: string;
17
17
  supersedes_event_id?: string;
18
+ source?: string;
18
19
  }
19
20
  export declare function buildLogPayload(args: LogPayloadArgs): Record<string, unknown>;
20
21
  export interface RecallRequestArgs {
@@ -85,7 +85,7 @@ export function buildLogPayload(args) {
85
85
  event_type: backendType,
86
86
  title,
87
87
  raw_payload: args.description,
88
- metadata: { secretary_kind: eventType },
88
+ metadata: { secretary_kind: eventType, source: args.source ?? 'CHAT' },
89
89
  hint: `Logged as ${eventType} (backend: ${backendType}). Pass event_hint to override.`,
90
90
  };
91
91
  if (args.project_id)
@@ -161,6 +161,7 @@ export function registerSecretaryTools(server, getClient) {
161
161
  .optional()
162
162
  .describe('Comma-separated participant names or emails'),
163
163
  supersedes_event_id: z.string().uuid().optional().describe('UUID of a prior event this one supersedes'),
164
+ source: z.enum(['EMAIL', 'PHONE', 'SLACK', 'CHAT', 'OTHER']).optional().describe('Source channel for work event types (defaults to CHAT)'),
164
165
  }, async (args) => {
165
166
  try {
166
167
  const client = await getClient();
@@ -6,6 +6,11 @@
6
6
  *
7
7
  * Aliases: tacit_ask / tacit_compose route to this same handler.
8
8
  * stream:true selects the SSE variant and returns aggregated chunks.
9
+ *
10
+ * Voice (BUG-418): voice_mode voice_on/voice_only or voice_profile_id force the SSE
11
+ * path; voice is confirmed by voice_applied on the done event. voice_off picks the
12
+ * endpoint by `stream` alone: it sends voice_mode:'voice_off' on the SSE path only;
13
+ * the JSON path gets no voice fields.
9
14
  */
10
15
  import { z } from 'zod';
11
16
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
@@ -206,6 +211,37 @@ export declare const SYNTHESIZE_TOOL_DEF: {
206
211
  required: string[];
207
212
  };
208
213
  };
214
+ type ToolResult = {
215
+ content: Array<{
216
+ type: 'text';
217
+ text: string;
218
+ }>;
219
+ isError?: boolean;
220
+ };
221
+ /**
222
+ * BUG-418: parse an SSE data chunk and return it only if it is the `done` event.
223
+ * postSSE yields data payloads without the event name, so the done event is
224
+ * recognised by its voice fields or its synthesis_id.
225
+ */
226
+ export declare function parseSseDone(chunk: string): Record<string, unknown> | null;
227
+ /**
228
+ * BUG-418: shared voice check for SSE paths. Returns an error result when voice
229
+ * was requested but the server did not report voice_applied === true; null when
230
+ * voice was applied. Used by tacit_synthesize/ask/compose and tacit_compose_in_voice.
231
+ * `chunks` are the streamed chunks, used to show the user what the server said.
232
+ */
233
+ export declare function voiceNotAppliedResult(done: Record<string, unknown> | null, chunks?: string[]): ToolResult | null;
234
+ export interface VoiceProfileRow {
235
+ profile_id?: string;
236
+ voice_active?: boolean;
237
+ }
238
+ /** GET /voice/profiles; accepts only {profiles: [...]}. Throws on any other shape. */
239
+ export declare function listVoiceProfiles(client: TacitClient): Promise<VoiceProfileRow[]>;
240
+ /**
241
+ * BUG-418: the SSE path applies the single active profile. Returns an error unless
242
+ * EXACTLY one profile is active and it equals `explicitId` (when given).
243
+ */
244
+ export declare function requireSoleActiveProfile(client: TacitClient, explicitId?: string): Promise<ToolResult | null>;
209
245
  export interface ToolRequest {
210
246
  execute(): Promise<{
211
247
  content: Array<{
@@ -228,3 +264,4 @@ export declare function handleSynthesize(args: unknown): Promise<{
228
264
  isError?: boolean;
229
265
  }>;
230
266
  export declare function registerSynthesizeTools(server: McpServer, getClientFn: () => Promise<TacitClient>): void;
267
+ export {};
@@ -6,10 +6,15 @@
6
6
  *
7
7
  * Aliases: tacit_ask / tacit_compose route to this same handler.
8
8
  * stream:true selects the SSE variant and returns aggregated chunks.
9
+ *
10
+ * Voice (BUG-418): voice_mode voice_on/voice_only or voice_profile_id force the SSE
11
+ * path; voice is confirmed by voice_applied on the done event. voice_off picks the
12
+ * endpoint by `stream` alone: it sends voice_mode:'voice_off' on the SSE path only;
13
+ * the JSON path gets no voice fields.
9
14
  */
10
15
  import { z } from 'zod';
11
16
  import { getClient, TacitApiError, TokenExpiredError } from '../client.js';
12
- import { featureDisabledResult } from './errors.js';
17
+ import { apiErrorText, featureDisabledResult } from './errors.js';
13
18
  export const synthesizeInputSchema = z.object({
14
19
  query: z.string().min(1).describe('Question or synthesis prompt'),
15
20
  stream: z.boolean().optional().describe('If true, use SSE stream variant (/mind/synthesize/stream)'),
@@ -39,7 +44,8 @@ export const SYNTHESIZE_TOOL_DEF = {
39
44
  name: 'tacit_synthesize',
40
45
  description: 'Synthesize knowledge from the Tacit workspace. ' +
41
46
  'stream:false (default) → POST /api/v1/mind/synthesize (JSON). ' +
42
- 'stream:true → POST /api/v1/mind/synthesize/stream (SSE; also exposed as tacit_ask / tacit_compose aliases).',
47
+ 'stream:true → POST /api/v1/mind/synthesize/stream (SSE; also exposed as tacit_ask / tacit_compose aliases). ' +
48
+ 'voice_mode voice_on/voice_only or voice_profile_id force the SSE path; voice is confirmed by voice_applied.',
43
49
  inputSchema: {
44
50
  type: 'object',
45
51
  properties: {
@@ -67,6 +73,93 @@ export const SYNTHESIZE_TOOL_DEF = {
67
73
  required: ['query'],
68
74
  },
69
75
  };
76
+ /**
77
+ * BUG-418: parse an SSE data chunk and return it only if it is the `done` event.
78
+ * postSSE yields data payloads without the event name, so the done event is
79
+ * recognised by its voice fields or its synthesis_id.
80
+ */
81
+ export function parseSseDone(chunk) {
82
+ try {
83
+ const parsed = JSON.parse(chunk);
84
+ if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)
85
+ && ('voice_applied' in parsed || 'voice_skip_reason' in parsed || 'synthesis_id' in parsed)) {
86
+ return parsed;
87
+ }
88
+ }
89
+ catch {
90
+ // not JSON — raw text chunk
91
+ }
92
+ return null;
93
+ }
94
+ const TAIL_MAX = 300;
95
+ /**
96
+ * BUG-418: shared voice check for SSE paths. Returns an error result when voice
97
+ * was requested but the server did not report voice_applied === true; null when
98
+ * voice was applied. Used by tacit_synthesize/ask/compose and tacit_compose_in_voice.
99
+ * `chunks` are the streamed chunks, used to show the user what the server said.
100
+ */
101
+ export function voiceNotAppliedResult(done, chunks = []) {
102
+ if (done && done['voice_applied'] === true)
103
+ return null;
104
+ const skip = done && typeof done['voice_skip_reason'] === 'string' ? done['voice_skip_reason'] : '';
105
+ let detail;
106
+ if (skip) {
107
+ detail = `voice_skip_reason: ${skip}`;
108
+ }
109
+ else if (done && !('voice_applied' in done) && done['scope_matched_zero_sources'] === true) {
110
+ detail = 'the request ended before generation (empty scope), so no voice fields were reported';
111
+ }
112
+ else if (done && !('voice_applied' in done)) {
113
+ detail = 'the done event had no voice fields; voice may be disabled on this cell (FEATURE_VOICE_SIGNATURE_V2)';
114
+ }
115
+ else {
116
+ detail = done ? 'voice_applied was false and the server gave no reason' : 'no done event received from the server';
117
+ }
118
+ let extra = '';
119
+ if (!skip) {
120
+ const last = chunks.filter((c) => parseSseDone(c) === null).pop();
121
+ if (last)
122
+ extra += ` Last streamed text: ${last.length > TAIL_MAX ? last.slice(0, TAIL_MAX) + '...' : last}`;
123
+ if (done && done['scope_matched_zero_sources'] !== undefined) {
124
+ extra += ` scope_matched_zero_sources: ${JSON.stringify(done['scope_matched_zero_sources'])}.`;
125
+ }
126
+ }
127
+ return {
128
+ content: [{
129
+ type: 'text',
130
+ text: `Voice was NOT applied (${detail}). The output is not in the user's voice; do not present it as voice-matched.${extra}`,
131
+ }],
132
+ isError: true,
133
+ };
134
+ }
135
+ /** GET /voice/profiles; accepts only {profiles: [...]}. Throws on any other shape. */
136
+ export async function listVoiceProfiles(client) {
137
+ const res = await client.get('/api/v1/voice/profiles');
138
+ const rows = res?.profiles;
139
+ if (!Array.isArray(rows))
140
+ throw new Error('unexpected /voice/profiles response shape (expected {profiles: [...]})');
141
+ return rows;
142
+ }
143
+ /**
144
+ * BUG-418: the SSE path applies the single active profile. Returns an error unless
145
+ * EXACTLY one profile is active and it equals `explicitId` (when given).
146
+ */
147
+ export async function requireSoleActiveProfile(client, explicitId) {
148
+ const active = (await listVoiceProfiles(client)).filter((p) => p.voice_active === true);
149
+ const hint = 'Use tacit_compose_in_voice with the grounded text in `content` (and voice_profile_id) to choose a profile.';
150
+ const fail = (text) => ({ content: [{ type: 'text', text }], isError: true });
151
+ if (active.length === 0) {
152
+ return fail(`No active voice profile exists (a profile needs 3+ samples and must be active). ${hint}`);
153
+ }
154
+ if (active.length > 1) {
155
+ const ids = active.map((p) => p.profile_id).join(', ');
156
+ return fail(`More than one voice profile is active (${ids}); the SSE path cannot choose between them. ${hint}`);
157
+ }
158
+ if (explicitId && active[0].profile_id !== explicitId) {
159
+ return fail(`voice_profile_id ${explicitId} is not the active profile (${active[0].profile_id}); the SSE path only uses the active profile. ${hint}`);
160
+ }
161
+ return null;
162
+ }
70
163
  /**
71
164
  * Build a synthesize request object. Call .execute() to perform the HTTP call.
72
165
  * Exported for testability (allows injecting a mock TacitClient).
@@ -108,16 +201,31 @@ export function buildSynthesizeRequest(client, input) {
108
201
  body['synthesis_mode'] = synthesis_mode;
109
202
  if (max_turns)
110
203
  body['max_turns'] = max_turns;
111
- if (voice_mode)
112
- body['voice_mode'] = voice_mode;
113
- if (voice_profile_id)
204
+ // BUG-418: voice fields are rejected by the JSON endpoint, so a voice request forces SSE.
205
+ // voice_off never forces SSE: on JSON it sends no voice fields; on SSE it sends
206
+ // voice_mode 'voice_off' (an absent mode would be treated as voice_on) and no profile id.
207
+ // Otherwise voice_profile_id implies voice_on.
208
+ const voiceOff = voice_mode === 'voice_off';
209
+ const voiceMode = voiceOff ? undefined : (voice_mode ?? (voice_profile_id ? 'voice_on' : undefined));
210
+ if (voiceMode)
211
+ body['voice_mode'] = voiceMode;
212
+ if (voiceMode && voice_profile_id)
114
213
  body['voice_profile_id'] = voice_profile_id;
214
+ if (voiceOff && stream)
215
+ body['voice_mode'] = 'voice_off';
115
216
  try {
116
- if (stream) {
117
- // SSE path: POST /api/v1/mind/synthesize/stream
217
+ if (stream || voiceMode) {
218
+ if (voiceMode) {
219
+ // The SSE path applies the single active profile; refuse ambiguity or a mismatch.
220
+ const blocked = await requireSoleActiveProfile(client, voice_profile_id);
221
+ if (blocked)
222
+ return blocked;
223
+ }
118
224
  const chunks = [];
119
225
  let structuredAnswer = null;
226
+ let done = null;
120
227
  for await (const chunk of client.postSSE('/api/v1/mind/synthesize/stream', body)) {
228
+ done = parseSseDone(chunk) ?? done;
121
229
  try {
122
230
  const parsed = JSON.parse(chunk);
123
231
  if (parsed.type === 'structured_answer') {
@@ -130,6 +238,17 @@ export function buildSynthesizeRequest(client, input) {
130
238
  }
131
239
  chunks.push(chunk);
132
240
  }
241
+ if (voiceMode === 'voice_on' || voiceMode === 'voice_only') {
242
+ const failed = voiceNotAppliedResult(done, chunks);
243
+ if (failed)
244
+ return failed;
245
+ }
246
+ if (voiceOff && done?.['voice_applied'] === true) {
247
+ return {
248
+ content: [{ type: 'text', text: "Voice was applied although voice_off was requested. The output is in the user's voice contrary to the request; do not present it as voice-free." }],
249
+ isError: true,
250
+ };
251
+ }
133
252
  if (chunks.length === 0 && !structuredAnswer) {
134
253
  return {
135
254
  content: [{ type: 'text', text: JSON.stringify({ chunks: 0, text: '' }) }],
@@ -160,7 +279,7 @@ export function buildSynthesizeRequest(client, input) {
160
279
  const disabled = featureDisabledResult(err);
161
280
  if (disabled)
162
281
  return disabled;
163
- return { content: [{ type: 'text', text: `API error ${err.statusCode}: ${err.body}` }], isError: true };
282
+ return { content: [{ type: 'text', text: apiErrorText(err) }], isError: true };
164
283
  }
165
284
  const msg = err instanceof Error ? err.message : String(err);
166
285
  return { content: [{ type: 'text', text: `Error: ${msg}` }], isError: true };
@@ -208,7 +327,7 @@ export function registerSynthesizeTools(server, getClientFn) {
208
327
  const client = await getClientFn();
209
328
  return buildSynthesizeRequest(client, args).execute();
210
329
  };
211
- server.tool('tacit_synthesize', 'Synthesize knowledge from the Tacit workspace. synthesis_mode: burst (default, fast retrieval), orbit (agentic multi-turn), crew_compose (crew artifact generation). stream:false → JSON, stream:true → SSE.', SYNTH_SCHEMA, handler);
330
+ server.tool('tacit_synthesize', 'Synthesize knowledge from the Tacit workspace. synthesis_mode: burst (default, fast retrieval), orbit (agentic multi-turn), crew_compose (crew artifact generation). stream:false → JSON, stream:true → SSE. voice_mode voice_on/voice_only or voice_profile_id force the SSE path; voice is confirmed by voice_applied.', SYNTH_SCHEMA, handler);
212
331
  server.tool('tacit_ask', 'Ask a question against the Tacit workspace. Supports synthesis_mode: burst (default), orbit (agentic), crew_compose.', SYNTH_SCHEMA, handler);
213
332
  server.tool('tacit_compose', 'Compose knowledge from the Tacit workspace. Supports synthesis_mode: burst (default), orbit (agentic), crew_compose.', SYNTH_SCHEMA, handler);
214
333
  }
@@ -8,8 +8,9 @@
8
8
  * GET /profiles/:id/stats — get profile statistics
9
9
  * POST /profiles/:id/samples — upload a voice sample
10
10
  *
11
- * compose_in_voice uses POST /api/v1/mind/synthesize with
12
- * synthesis_mode=crew_compose + voice_mode=voice_on.
11
+ * compose_in_voice (BUG-418):
12
+ * with `content` -> POST /api/v1/voice/profiles/:id/generate (voice rewrite of grounded text)
13
+ * without content -> SSE /api/v1/mind/synthesize/stream, voice_mode=voice_on, voice_applied checked
13
14
  */
14
15
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
15
16
  import { TacitClient } from '../client.js';
@@ -8,12 +8,13 @@
8
8
  * GET /profiles/:id/stats — get profile statistics
9
9
  * POST /profiles/:id/samples — upload a voice sample
10
10
  *
11
- * compose_in_voice uses POST /api/v1/mind/synthesize with
12
- * synthesis_mode=crew_compose + voice_mode=voice_on.
11
+ * compose_in_voice (BUG-418):
12
+ * with `content` -> POST /api/v1/voice/profiles/:id/generate (voice rewrite of grounded text)
13
+ * without content -> SSE /api/v1/mind/synthesize/stream, voice_mode=voice_on, voice_applied checked
13
14
  */
14
15
  import { z } from 'zod';
15
- import { apiErrorResult } from './errors.js';
16
- import { buildSynthesizeRequest } from './synthesize.js';
16
+ import { apiErrorResult, error } from './errors.js';
17
+ import { parseSseDone, voiceNotAppliedResult, listVoiceProfiles, requireSoleActiveProfile } from './synthesize.js';
17
18
  export function registerVoiceTools(server, getClientFn) {
18
19
  // ── tacit_voice_list_profiles ──────────────────────────────────────────────
19
20
  server.tool('tacit_voice_list_profiles', 'List your voice profiles with name, active status, sample count, and quality indicators. Use when someone asks about their voice profiles or writing style settings.', {}, async () => {
@@ -71,28 +72,79 @@ export function registerVoiceTools(server, getClientFn) {
71
72
  }
72
73
  });
73
74
  // ── tacit_compose_in_voice ─────────────────────────────────────────────────
74
- server.tool('tacit_compose_in_voice', 'Compose an artifact in your writing voice. Combines crew-based artifact generation with voice personalization in a single call. Use when someone says "write this in my voice" or "compose a brief in my style".', {
75
- query: z.string().min(1).describe('Composition prompt — what to write'),
75
+ server.tool('tacit_compose_in_voice', 'Compose or rewrite text in your writing voice. Put the grounded source text (facts, draft, cover letter) in `content` and it is rewritten in your voice via your active voice profile. Omit `content` only for a KB-grounded draft generated from workspace knowledge. Fails loudly if voice cannot be applied. Use when someone says "write this in my voice" or "rewrite this in my style".', {
76
+ query: z.string().min(1).describe('Composition prompt — what to write (becomes the voice constraint when content is given)'),
77
+ content: z.string().min(1).optional().describe("Grounded source text to rewrite in the user's voice. Omit only for KB-grounded drafts."),
78
+ title: z.string().optional().describe('Title for the voice rewrite (default "Voice rewrite"). Used with content.'),
76
79
  voice_profile_id: z.string().optional().describe('Specific voice profile UUID. Omit to use the active profile.'),
77
80
  workspace_id: z.string().optional().describe('Optional workspace UUID'),
78
- collection_ids: z.array(z.string()).optional().describe('Optional collection UUIDs to scope synthesis to'),
79
- program_ids: z.array(z.string()).optional().describe('Optional program UUIDs to scope synthesis to'),
81
+ collection_ids: z.array(z.string()).optional().describe('Optional collection UUIDs to scope synthesis to (KB-grounded drafts)'),
82
+ program_ids: z.array(z.string()).optional().describe('Optional program UUIDs to scope synthesis to (KB-grounded drafts)'),
80
83
  }, async (args) => {
81
84
  try {
82
85
  const client = await getClientFn();
83
- const input = {
84
- query: args.query,
85
- synthesis_mode: 'crew_compose',
86
- voice_mode: 'voice_on',
87
- voice_profile_id: args.voice_profile_id,
88
- workspace_id: args.workspace_id,
89
- collection_ids: args.collection_ids,
90
- program_ids: args.program_ids,
91
- };
92
- return buildSynthesizeRequest(client, input).execute();
86
+ if (args.content)
87
+ return await composeFromContent(client, args);
88
+ return await composeFromKb(client, args);
93
89
  }
94
90
  catch (err) {
95
91
  return apiErrorResult(err, 'compose_in_voice');
96
92
  }
97
93
  });
98
94
  }
95
+ const NO_ACTIVE_PROFILE = 'No active voice profile exists. A voice profile needs 3+ writing samples (tacit_voice_upload_sample) and must be active before text can be written in your voice.';
96
+ async function composeFromContent(client, args) {
97
+ let id = args.voice_profile_id;
98
+ if (!id) {
99
+ const active = (await listVoiceProfiles(client)).filter((p) => p.voice_active === true);
100
+ if (active.length === 0)
101
+ return error(NO_ACTIVE_PROFILE);
102
+ if (active.length > 1) {
103
+ return error(`More than one voice profile is active (${active.map((p) => p.profile_id).join(', ')}). Pass voice_profile_id to choose one.`);
104
+ }
105
+ id = active[0].profile_id;
106
+ if (!id)
107
+ return error('unexpected /voice/profiles response shape (active profile has no profile_id)');
108
+ }
109
+ try {
110
+ const res = (await client.post(`/api/v1/voice/profiles/${id}/generate`, {
111
+ title: args.title ?? 'Voice rewrite',
112
+ content: args.content,
113
+ constraint: args.query,
114
+ formats: ['text'],
115
+ }));
116
+ const out = {
117
+ text: res['narrative_content'],
118
+ voice_profile_id: id,
119
+ voice_match_degraded: res['voice_match_degraded'],
120
+ identity_similarity: res['identity_similarity'],
121
+ constellation_label: res['constellation_label'],
122
+ };
123
+ return { content: [{ type: 'text', text: JSON.stringify(out) }] };
124
+ }
125
+ catch (err) {
126
+ return apiErrorResult(err, `/api/v1/voice/profiles/${id}/generate`);
127
+ }
128
+ }
129
+ async function composeFromKb(client, args) {
130
+ const blocked = await requireSoleActiveProfile(client, args.voice_profile_id);
131
+ if (blocked)
132
+ return blocked;
133
+ const chunks = [];
134
+ let done = null;
135
+ for await (const chunk of client.postSSE('/api/v1/mind/synthesize/stream', {
136
+ query: args.query,
137
+ synthesis_mode: 'crew_compose',
138
+ voice_mode: 'voice_on',
139
+ ...(args.workspace_id ? { workspace_id: args.workspace_id } : {}),
140
+ ...(args.collection_ids ? { collection_ids: args.collection_ids } : {}),
141
+ ...(args.program_ids ? { program_ids: args.program_ids } : {}),
142
+ })) {
143
+ done = parseSseDone(chunk) ?? done;
144
+ chunks.push(chunk);
145
+ }
146
+ const failed = voiceNotAppliedResult(done, chunks);
147
+ if (failed)
148
+ return failed;
149
+ return { content: chunks.map((c) => ({ type: 'text', text: c })) };
150
+ }
@@ -10,7 +10,7 @@
10
10
  */
11
11
  import { z } from 'zod';
12
12
  import { TacitApiError, TokenExpiredError } from '../client.js';
13
- import { featureDisabledResult } from './errors.js';
13
+ import { apiErrorText, featureDisabledResult } from './errors.js';
14
14
  function apiErrorResult(err, toolName) {
15
15
  if (err instanceof TokenExpiredError) {
16
16
  return { content: [{ type: 'text', text: err.message }], isError: true };
@@ -19,7 +19,7 @@ function apiErrorResult(err, toolName) {
19
19
  const disabled = featureDisabledResult(err);
20
20
  if (disabled)
21
21
  return disabled;
22
- return { content: [{ type: 'text', text: `API error ${err.statusCode} on ${toolName}: ${err.body}` }], isError: true };
22
+ return { content: [{ type: 'text', text: apiErrorText(err, toolName) }], isError: true };
23
23
  }
24
24
  const msg = err instanceof Error ? err.message : String(err);
25
25
  return { content: [{ type: 'text', text: `Error: ${msg}` }], isError: true };