@band-ai/sdk 0.1.2

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 (91) hide show
  1. package/dist/CodexAdapter-A1k_LMdZ.d.ts +1278 -0
  2. package/dist/CodexAdapter-BbZD-nBd.d.cts +1278 -0
  3. package/dist/adapters.cjs +10643 -0
  4. package/dist/adapters.d.cts +217 -0
  5. package/dist/adapters.d.ts +217 -0
  6. package/dist/adapters.js +92 -0
  7. package/dist/backends-BnOLsG7w.d.cts +20 -0
  8. package/dist/backends-C4n6cKOf.d.ts +20 -0
  9. package/dist/chunk-3BKAC4OZ.js +44 -0
  10. package/dist/chunk-5CXIMAH2.js +52 -0
  11. package/dist/chunk-6AJA2OPC.js +3682 -0
  12. package/dist/chunk-A3TDK6GP.js +6674 -0
  13. package/dist/chunk-AVVDPXP4.js +39 -0
  14. package/dist/chunk-EDPKUUJL.js +177 -0
  15. package/dist/chunk-FUODYQRE.js +2562 -0
  16. package/dist/chunk-GVEQ3RAH.js +373 -0
  17. package/dist/chunk-INA6YZTZ.js +88 -0
  18. package/dist/chunk-IZPV6QS6.js +115 -0
  19. package/dist/chunk-LY55KYVI.js +0 -0
  20. package/dist/chunk-NIAQBANR.js +577 -0
  21. package/dist/chunk-OD2G5LFQ.js +78 -0
  22. package/dist/chunk-SFVKOEQH.js +103 -0
  23. package/dist/chunk-SG4WLD2H.js +1093 -0
  24. package/dist/chunk-YR3BOQNW.js +39 -0
  25. package/dist/chunk-ZZJRRBPQ.js +82 -0
  26. package/dist/claude-CcnQ5OUC.d.ts +53 -0
  27. package/dist/claude-CwTAxhwI.d.cts +53 -0
  28. package/dist/config.cjs +164 -0
  29. package/dist/config.d.cts +19 -0
  30. package/dist/config.d.ts +19 -0
  31. package/dist/config.js +9 -0
  32. package/dist/converters.cjs +1086 -0
  33. package/dist/converters.d.cts +143 -0
  34. package/dist/converters.d.ts +143 -0
  35. package/dist/converters.js +468 -0
  36. package/dist/core.cjs +185 -0
  37. package/dist/core.d.cts +22 -0
  38. package/dist/core.d.ts +22 -0
  39. package/dist/core.js +24 -0
  40. package/dist/customTools-BzF0IISO.d.cts +10 -0
  41. package/dist/customTools-BzF0IISO.d.ts +10 -0
  42. package/dist/dtos-DUpbIu8k.d.cts +163 -0
  43. package/dist/dtos-DUpbIu8k.d.ts +163 -0
  44. package/dist/history-ByessXNq.d.ts +24 -0
  45. package/dist/history-i6yN7neC.d.cts +24 -0
  46. package/dist/index.cjs +13914 -0
  47. package/dist/index.d.cts +63 -0
  48. package/dist/index.d.ts +63 -0
  49. package/dist/index.js +198 -0
  50. package/dist/linear.cjs +2207 -0
  51. package/dist/linear.d.cts +167 -0
  52. package/dist/linear.d.ts +167 -0
  53. package/dist/linear.js +2139 -0
  54. package/dist/logger-CABQOnlR.d.cts +21 -0
  55. package/dist/logger-CABQOnlR.d.ts +21 -0
  56. package/dist/mcp-claude.cjs +584 -0
  57. package/dist/mcp-claude.d.cts +4 -0
  58. package/dist/mcp-claude.d.ts +4 -0
  59. package/dist/mcp-claude.js +11 -0
  60. package/dist/mcp.cjs +1247 -0
  61. package/dist/mcp.d.cts +97 -0
  62. package/dist/mcp.d.ts +97 -0
  63. package/dist/mcp.js +27 -0
  64. package/dist/opencode-BBcDchcN.d.cts +159 -0
  65. package/dist/opencode-DthQQUsZ.d.ts +159 -0
  66. package/dist/pagination-BPiys10t.d.cts +25 -0
  67. package/dist/pagination-CcDkVFxK.d.ts +25 -0
  68. package/dist/protocols-CInhtFpA.d.cts +116 -0
  69. package/dist/protocols-DrhzOH6K.d.ts +116 -0
  70. package/dist/rest.cjs +1159 -0
  71. package/dist/rest.d.cts +144 -0
  72. package/dist/rest.d.ts +144 -0
  73. package/dist/rest.js +18 -0
  74. package/dist/runtime.cjs +5353 -0
  75. package/dist/runtime.d.cts +276 -0
  76. package/dist/runtime.d.ts +276 -0
  77. package/dist/runtime.js +274 -0
  78. package/dist/schemas-BpEBkq5V.d.cts +592 -0
  79. package/dist/schemas-vos1AaBc.d.ts +592 -0
  80. package/dist/sdk-HJUVSSWA.js +10 -0
  81. package/dist/simpleAdapter-9OE_p6QW.d.ts +29 -0
  82. package/dist/simpleAdapter-DqhvjsGr.d.cts +29 -0
  83. package/dist/testing.cjs +217 -0
  84. package/dist/testing.d.cts +126 -0
  85. package/dist/testing.d.ts +126 -0
  86. package/dist/testing.js +186 -0
  87. package/dist/types-7jVzOeOP.d.ts +446 -0
  88. package/dist/types-CSHFipIc.d.cts +331 -0
  89. package/dist/types-CovcHpYf.d.cts +446 -0
  90. package/dist/types-CxII3XkA.d.ts +331 -0
  91. package/package.json +189 -0
package/dist/mcp.cjs ADDED
@@ -0,0 +1,1247 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ };
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from))
18
+ if (!__hasOwnProp.call(to, key) && key !== except)
19
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
31
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
+
33
+ // src/core/errors.ts
34
+ var init_errors = __esm({
35
+ "src/core/errors.ts"() {
36
+ "use strict";
37
+ }
38
+ });
39
+
40
+ // src/contracts/chatEvents.ts
41
+ var CHAT_EVENT_TYPES, CHAT_MESSAGE_TYPES;
42
+ var init_chatEvents = __esm({
43
+ "src/contracts/chatEvents.ts"() {
44
+ "use strict";
45
+ init_errors();
46
+ CHAT_EVENT_TYPES = ["tool_call", "tool_result", "thought", "error", "task"];
47
+ CHAT_MESSAGE_TYPES = ["text", ...CHAT_EVENT_TYPES];
48
+ }
49
+ });
50
+
51
+ // src/runtime/tools/schemas.ts
52
+ function mcpToolNames(names) {
53
+ return [...names].sort((a, b) => a.localeCompare(b)).map((name) => `${MCP_TOOL_PREFIX}${name}`);
54
+ }
55
+ function getToolDescription(name) {
56
+ const model = TOOL_MODELS[name];
57
+ return model?.description ?? `Execute ${name}`;
58
+ }
59
+ var TOOL_MODELS, ALL_TOOL_NAMES, MEMORY_TOOL_NAMES, CONTACT_TOOL_NAMES, BASE_TOOL_NAMES, CHAT_TOOL_NAMES, MCP_TOOL_PREFIX;
60
+ var init_schemas = __esm({
61
+ "src/runtime/tools/schemas.ts"() {
62
+ "use strict";
63
+ init_chatEvents();
64
+ TOOL_MODELS = {
65
+ thenvoi_send_message: {
66
+ description: "Send a message to the chat room. Use this to respond to users or other agents. Messages require at least one @mention in the mentions array. You MUST use this tool to communicate \u2014 plain text responses won't reach users. When delegating, send the full task context in this message instead of assuming hidden state.",
67
+ properties: {
68
+ content: {
69
+ type: "string",
70
+ description: "The message content to send."
71
+ },
72
+ mentions: {
73
+ type: "array",
74
+ items: { type: "string" },
75
+ minItems: 1,
76
+ description: "List of participant handles to @mention. At least one required. For users: @<username> (e.g., '@john'). For agents: @<username>/<agent-name> (e.g., '@john/weather-agent'). Use the handle of someone already in the room."
77
+ }
78
+ },
79
+ required: ["content", "mentions"]
80
+ },
81
+ thenvoi_send_event: {
82
+ description: "Send an event to the chat room. No mentions required. 'thought': Share your reasoning or plan BEFORE taking actions. Explain what you're about to do and why. 'error': Report an error or problem that occurred. 'task': Report task progress or completion status. Always send a thought before complex actions to keep users informed.",
83
+ properties: {
84
+ content: {
85
+ type: "string",
86
+ description: "Human-readable event content."
87
+ },
88
+ message_type: {
89
+ type: "string",
90
+ enum: [...CHAT_EVENT_TYPES],
91
+ description: "Type of event."
92
+ },
93
+ metadata: {
94
+ type: "object",
95
+ description: "Optional structured data for the event."
96
+ }
97
+ },
98
+ required: ["content", "message_type"]
99
+ },
100
+ thenvoi_add_participant: {
101
+ description: "Add a participant (agent or user) to the chat room by name. IMPORTANT: Use thenvoi_lookup_peers() first to find available agents. Pass the exact peer name from thenvoi_lookup_peers, not the handle. For normal delegation, omit role or use 'member'.",
102
+ properties: {
103
+ name: {
104
+ type: "string",
105
+ description: "Name of participant to add (must match a name from thenvoi_lookup_peers)."
106
+ },
107
+ role: {
108
+ type: "string",
109
+ enum: ["owner", "admin", "member"],
110
+ description: "Role for the participant in this room."
111
+ }
112
+ },
113
+ required: ["name"]
114
+ },
115
+ thenvoi_remove_participant: {
116
+ description: "Remove a participant from the chat room by name.",
117
+ properties: {
118
+ name: {
119
+ type: "string",
120
+ description: "Name of the participant to remove."
121
+ }
122
+ },
123
+ required: ["name"]
124
+ },
125
+ thenvoi_get_participants: {
126
+ description: "Get a list of all participants in the current chat room.",
127
+ properties: {},
128
+ required: []
129
+ },
130
+ thenvoi_lookup_peers: {
131
+ description: "List available peers (agents and users) that can be added to this room. Automatically excludes peers already in the room. Returns dict with 'peers' list and 'metadata' (page, page_size, total_count, total_pages). Use this to find specialized agents (e.g., Weather Agent) when you cannot answer a question directly.",
132
+ properties: {
133
+ page: {
134
+ type: "integer",
135
+ description: "Page number."
136
+ },
137
+ page_size: {
138
+ type: "integer",
139
+ description: "Items per page (max 100).",
140
+ maximum: 100
141
+ }
142
+ },
143
+ required: []
144
+ },
145
+ thenvoi_create_chatroom: {
146
+ description: "Create a new chat room for a specific task or conversation.",
147
+ properties: {
148
+ task_id: {
149
+ type: "string",
150
+ description: "Associated task ID (optional)."
151
+ }
152
+ },
153
+ required: []
154
+ },
155
+ thenvoi_list_contacts: {
156
+ description: "List agent's contacts with pagination.",
157
+ properties: {
158
+ page: {
159
+ type: "integer",
160
+ description: "Page number.",
161
+ minimum: 1
162
+ },
163
+ page_size: {
164
+ type: "integer",
165
+ description: "Items per page.",
166
+ minimum: 1,
167
+ maximum: 100
168
+ }
169
+ },
170
+ required: []
171
+ },
172
+ thenvoi_add_contact: {
173
+ description: "Send a contact request to add someone as a contact. Returns 'pending' when request is created. Returns 'approved' when inverse request existed and was auto-accepted.",
174
+ properties: {
175
+ handle: {
176
+ type: "string",
177
+ description: "Handle of user/agent to add (e.g., '@john' or '@john/agent-name')."
178
+ },
179
+ message: {
180
+ type: "string",
181
+ description: "Optional message with the request."
182
+ }
183
+ },
184
+ required: ["handle"]
185
+ },
186
+ thenvoi_remove_contact: {
187
+ description: "Remove an existing contact by handle or ID.",
188
+ properties: {
189
+ handle: {
190
+ type: "string",
191
+ description: "Contact's handle."
192
+ },
193
+ contact_id: {
194
+ type: "string",
195
+ description: "Or contact record ID (UUID)."
196
+ }
197
+ },
198
+ required: []
199
+ },
200
+ thenvoi_list_contact_requests: {
201
+ description: "List both received and sent contact requests. Received requests are always filtered to pending status. Sent requests can be filtered by status.",
202
+ properties: {
203
+ page: {
204
+ type: "integer",
205
+ description: "Page number.",
206
+ minimum: 1
207
+ },
208
+ page_size: {
209
+ type: "integer",
210
+ description: "Items per page per direction (max 100).",
211
+ minimum: 1,
212
+ maximum: 100
213
+ },
214
+ sent_status: {
215
+ type: "string",
216
+ enum: ["pending", "approved", "rejected", "cancelled", "all"],
217
+ description: "Filter sent requests by status."
218
+ }
219
+ },
220
+ required: []
221
+ },
222
+ thenvoi_respond_contact_request: {
223
+ description: "Respond to a contact request. 'approve'/'reject': For requests you RECEIVED (handle = requester's handle). 'cancel': For requests you SENT (handle = recipient's handle).",
224
+ properties: {
225
+ action: {
226
+ type: "string",
227
+ enum: ["approve", "reject", "cancel"],
228
+ description: "Action to take."
229
+ },
230
+ handle: {
231
+ type: "string",
232
+ description: "Other party's handle."
233
+ },
234
+ request_id: {
235
+ type: "string",
236
+ description: "Or request ID (UUID)."
237
+ }
238
+ },
239
+ required: ["action"]
240
+ },
241
+ thenvoi_list_memories: {
242
+ description: "List memories accessible to the agent. Returns memories about the specified subject (cross-agent sharing) and organization-wide shared memories.",
243
+ properties: {
244
+ subject_id: {
245
+ type: "string",
246
+ description: "Filter by subject UUID (required for subject-scoped queries)."
247
+ },
248
+ scope: {
249
+ type: "string",
250
+ enum: ["subject", "organization", "all"],
251
+ description: "Filter by scope."
252
+ },
253
+ system: {
254
+ type: "string",
255
+ enum: ["sensory", "working", "long_term"],
256
+ description: "Filter by memory system."
257
+ },
258
+ type: {
259
+ type: "string",
260
+ enum: [
261
+ "iconic",
262
+ "echoic",
263
+ "haptic",
264
+ "episodic",
265
+ "semantic",
266
+ "procedural"
267
+ ],
268
+ description: "Filter by memory type."
269
+ },
270
+ segment: {
271
+ type: "string",
272
+ enum: ["user", "agent", "tool", "guideline"],
273
+ description: "Filter by segment."
274
+ },
275
+ content_query: {
276
+ type: "string",
277
+ description: "Full-text search query."
278
+ },
279
+ page_size: {
280
+ type: "integer",
281
+ description: "Number of results per page.",
282
+ minimum: 1,
283
+ maximum: 50
284
+ },
285
+ status: {
286
+ type: "string",
287
+ enum: ["active", "superseded", "archived", "all"],
288
+ description: "Filter by status."
289
+ }
290
+ },
291
+ required: []
292
+ },
293
+ thenvoi_store_memory: {
294
+ description: "Store a new memory entry. The memory will be associated with the authenticated agent as the source. For subject-scoped memories, provide a subject_id. For organization-scoped memories, omit subject_id.",
295
+ properties: {
296
+ content: {
297
+ type: "string",
298
+ description: "The memory content."
299
+ },
300
+ system: {
301
+ type: "string",
302
+ enum: ["sensory", "working", "long_term"],
303
+ description: "Memory system tier."
304
+ },
305
+ type: {
306
+ type: "string",
307
+ enum: [
308
+ "iconic",
309
+ "echoic",
310
+ "haptic",
311
+ "episodic",
312
+ "semantic",
313
+ "procedural"
314
+ ],
315
+ description: "Memory type (must be valid for selected system)."
316
+ },
317
+ segment: {
318
+ type: "string",
319
+ enum: ["user", "agent", "tool", "guideline"],
320
+ description: "Logical segment."
321
+ },
322
+ thought: {
323
+ type: "string",
324
+ description: "Agent's reasoning for storing this memory."
325
+ },
326
+ scope: {
327
+ type: "string",
328
+ enum: ["subject", "organization"],
329
+ description: "Visibility scope."
330
+ },
331
+ subject_id: {
332
+ type: "string",
333
+ description: "UUID of the subject this memory is about (required for subject scope)."
334
+ },
335
+ metadata: {
336
+ type: "object",
337
+ description: "Additional metadata (tags, references)."
338
+ }
339
+ },
340
+ required: ["content", "system", "type", "segment", "thought"]
341
+ },
342
+ thenvoi_get_memory: {
343
+ description: "Retrieve a specific memory by ID.",
344
+ properties: {
345
+ memory_id: {
346
+ type: "string",
347
+ description: "Memory ID (UUID)."
348
+ }
349
+ },
350
+ required: ["memory_id"]
351
+ },
352
+ thenvoi_supersede_memory: {
353
+ description: "Mark a memory as superseded (soft delete). Use when information is outdated or incorrect. The memory remains for audit trail but won't appear in normal queries. Only the source agent can supersede.",
354
+ properties: {
355
+ memory_id: {
356
+ type: "string",
357
+ description: "Memory ID (UUID)."
358
+ }
359
+ },
360
+ required: ["memory_id"]
361
+ },
362
+ thenvoi_archive_memory: {
363
+ description: "Archive a memory (hide but preserve). Use when memory is valid but not currently needed. Archived memories can be restored later by humans. Only the source agent can archive.",
364
+ properties: {
365
+ memory_id: {
366
+ type: "string",
367
+ description: "Memory ID (UUID)."
368
+ }
369
+ },
370
+ required: ["memory_id"]
371
+ }
372
+ };
373
+ ALL_TOOL_NAMES = new Set(Object.keys(TOOL_MODELS));
374
+ MEMORY_TOOL_NAMES = /* @__PURE__ */ new Set([
375
+ "thenvoi_list_memories",
376
+ "thenvoi_store_memory",
377
+ "thenvoi_get_memory",
378
+ "thenvoi_supersede_memory",
379
+ "thenvoi_archive_memory"
380
+ ]);
381
+ CONTACT_TOOL_NAMES = /* @__PURE__ */ new Set([
382
+ "thenvoi_list_contacts",
383
+ "thenvoi_add_contact",
384
+ "thenvoi_remove_contact",
385
+ "thenvoi_list_contact_requests",
386
+ "thenvoi_respond_contact_request"
387
+ ]);
388
+ BASE_TOOL_NAMES = new Set(
389
+ [...ALL_TOOL_NAMES].filter((name) => !MEMORY_TOOL_NAMES.has(name))
390
+ );
391
+ CHAT_TOOL_NAMES = new Set(
392
+ [...BASE_TOOL_NAMES].filter((name) => !CONTACT_TOOL_NAMES.has(name))
393
+ );
394
+ MCP_TOOL_PREFIX = "mcp__thenvoi__";
395
+ }
396
+ });
397
+
398
+ // src/contracts/protocols.ts
399
+ function isToolExecutorError(value) {
400
+ if (!value || typeof value !== "object") {
401
+ return false;
402
+ }
403
+ const candidate = value;
404
+ return candidate.ok === false && typeof candidate.errorType === "string" && TOOL_EXECUTOR_ERROR_TYPES.includes(candidate.errorType) && typeof candidate.toolName === "string" && typeof candidate.message === "string" && typeof candidate.legacyMessage === "string";
405
+ }
406
+ function toLegacyToolExecutorErrorMessage(value) {
407
+ if (typeof value === "string") {
408
+ return value;
409
+ }
410
+ if (!isToolExecutorError(value)) {
411
+ return null;
412
+ }
413
+ return value.legacyMessage;
414
+ }
415
+ var TOOL_EXECUTOR_ERROR_TYPES;
416
+ var init_protocols = __esm({
417
+ "src/contracts/protocols.ts"() {
418
+ "use strict";
419
+ TOOL_EXECUTOR_ERROR_TYPES = [
420
+ "ToolArgumentsValidationError",
421
+ "ToolNotFoundError",
422
+ "ToolExecutionError"
423
+ ];
424
+ }
425
+ });
426
+
427
+ // src/mcp/registrations.ts
428
+ function buildRoomScopedRegistrations(resolver, options = {}) {
429
+ const toolNames = resolveToolNames(options);
430
+ const registrations = buildRegistrations(toolNames, async (toolName, args) => {
431
+ const roomId = asNonEmptyString(args.room_id);
432
+ if (!roomId) {
433
+ return errorResult("Missing required room_id");
434
+ }
435
+ const tools = resolver(roomId);
436
+ if (!tools) {
437
+ return errorResult(`No tool context found for room_id ${roomId}`);
438
+ }
439
+ const toolArgs = { ...args };
440
+ delete toolArgs.room_id;
441
+ return executeToolCall(tools, toolName, toolArgs);
442
+ }, { injectRoomId: true });
443
+ if (options.additionalTools) {
444
+ registrations.push(...options.additionalTools);
445
+ }
446
+ return registrations;
447
+ }
448
+ function buildSingleContextRegistrations(tools, options = {}) {
449
+ const toolNames = resolveToolNames(options);
450
+ const registrations = buildRegistrations(toolNames, (_toolName, args) => {
451
+ return executeToolCall(tools, _toolName, args);
452
+ }, { injectRoomId: false });
453
+ if (options.additionalTools) {
454
+ registrations.push(...options.additionalTools);
455
+ }
456
+ return registrations;
457
+ }
458
+ function resolveToolNames(options) {
459
+ const names = /* @__PURE__ */ new Set();
460
+ for (const name of BASE_TOOL_NAMES) {
461
+ if (!options.enableContactTools && CONTACT_TOOL_NAMES.has(name)) {
462
+ continue;
463
+ }
464
+ names.add(name);
465
+ }
466
+ if (options.enableMemoryTools) {
467
+ for (const name of MEMORY_TOOL_NAMES) {
468
+ names.add(name);
469
+ }
470
+ }
471
+ return names;
472
+ }
473
+ function buildRegistrations(toolNames, executor, opts) {
474
+ const registrations = [];
475
+ for (const toolName of toolNames) {
476
+ const model = TOOL_MODELS[toolName];
477
+ if (!model) {
478
+ continue;
479
+ }
480
+ const properties = { ...model.properties };
481
+ const required = [...model.required];
482
+ if (opts.injectRoomId) {
483
+ properties.room_id = { type: "string", description: "The room ID to execute this tool in" };
484
+ required.push("room_id");
485
+ }
486
+ registrations.push({
487
+ name: toolName,
488
+ description: getToolDescription(toolName),
489
+ inputSchema: {
490
+ type: "object",
491
+ properties,
492
+ required
493
+ },
494
+ execute: (args) => executor(toolName, args)
495
+ });
496
+ }
497
+ return registrations;
498
+ }
499
+ async function executeToolCall(tools, toolName, args) {
500
+ try {
501
+ const result = await tools.executeToolCall(toolName, args);
502
+ if (isToolExecutorError(result)) {
503
+ return errorResult(toLegacyToolExecutorErrorMessage(result) ?? result.message);
504
+ }
505
+ return successResult(result);
506
+ } catch (error) {
507
+ return errorResult(error instanceof Error ? error.message : String(error));
508
+ }
509
+ }
510
+ function asNonEmptyString(value) {
511
+ if (typeof value !== "string") {
512
+ return null;
513
+ }
514
+ const trimmed = value.trim();
515
+ return trimmed.length > 0 ? trimmed : null;
516
+ }
517
+ function successResult(value) {
518
+ return {
519
+ content: [{
520
+ type: "text",
521
+ text: serializeValue(value)
522
+ }]
523
+ };
524
+ }
525
+ function errorResult(message) {
526
+ return {
527
+ content: [{ type: "text", text: message }],
528
+ isError: true
529
+ };
530
+ }
531
+ function serializeValue(value) {
532
+ if (value === void 0 || value === null) {
533
+ return "";
534
+ }
535
+ if (typeof value === "string") {
536
+ return value;
537
+ }
538
+ try {
539
+ const json = JSON.stringify(value);
540
+ return typeof json === "string" ? json : String(value);
541
+ } catch {
542
+ return String(value);
543
+ }
544
+ }
545
+ var init_registrations = __esm({
546
+ "src/mcp/registrations.ts"() {
547
+ "use strict";
548
+ init_protocols();
549
+ init_schemas();
550
+ }
551
+ });
552
+
553
+ // src/mcp/zod.ts
554
+ function buildZodShape(z2, properties, required) {
555
+ const shape = {};
556
+ for (const [name, schema] of Object.entries(properties)) {
557
+ const validator = jsonSchemaToZod(z2, schema);
558
+ shape[name] = required.has(name) ? validator : validator.optional();
559
+ }
560
+ return shape;
561
+ }
562
+ function jsonSchemaToZod(z2, schema) {
563
+ const type = schema.type;
564
+ if (type === "string") {
565
+ if (Array.isArray(schema.enum) && schema.enum.every((v) => typeof v === "string")) {
566
+ const values = schema.enum;
567
+ if (values.length > 0) {
568
+ return z2.enum(values);
569
+ }
570
+ }
571
+ return z2.string();
572
+ }
573
+ if (type === "integer" || type === "number") {
574
+ return z2.number();
575
+ }
576
+ if (type === "boolean") {
577
+ return z2.boolean();
578
+ }
579
+ if (type === "array") {
580
+ const itemSchema = schema.items;
581
+ if (itemSchema && typeof itemSchema === "object") {
582
+ return z2.array(jsonSchemaToZod(z2, itemSchema));
583
+ }
584
+ return z2.array(z2.unknown());
585
+ }
586
+ if (type === "object") {
587
+ return z2.record(z2.string(), z2.unknown());
588
+ }
589
+ return z2.unknown();
590
+ }
591
+ var init_zod = __esm({
592
+ "src/mcp/zod.ts"() {
593
+ "use strict";
594
+ }
595
+ });
596
+
597
+ // src/mcp/sdk.ts
598
+ var sdk_exports = {};
599
+ __export(sdk_exports, {
600
+ createThenvoiSdkMcpServer: () => createThenvoiSdkMcpServer
601
+ });
602
+ function createThenvoiSdkMcpServer(options) {
603
+ const registrations = buildRoomScopedRegistrations(
604
+ options.getToolsForRoom,
605
+ {
606
+ enableMemoryTools: options.enableMemoryTools,
607
+ enableContactTools: true,
608
+ additionalTools: options.additionalTools
609
+ }
610
+ );
611
+ const toolDefinitions = registrations.map(toSdkToolDefinition);
612
+ const toolNames = new Set(registrations.map((r) => r.name));
613
+ const serverConfig = (0, import_claude_agent_sdk.createSdkMcpServer)({
614
+ name: "thenvoi",
615
+ tools: toolDefinitions
616
+ });
617
+ return {
618
+ serverConfig,
619
+ allowedTools: mcpToolNames(toolNames),
620
+ toolDefinitions
621
+ };
622
+ }
623
+ function toSdkToolDefinition(registration) {
624
+ const shape = buildZodShape(
625
+ import_zod4.z,
626
+ registration.inputSchema.properties,
627
+ new Set(registration.inputSchema.required)
628
+ );
629
+ return (0, import_claude_agent_sdk.tool)(
630
+ registration.name,
631
+ registration.description,
632
+ shape,
633
+ async (args) => registration.execute(args)
634
+ );
635
+ }
636
+ var import_claude_agent_sdk, import_zod4;
637
+ var init_sdk = __esm({
638
+ "src/mcp/sdk.ts"() {
639
+ "use strict";
640
+ import_claude_agent_sdk = require("@anthropic-ai/claude-agent-sdk");
641
+ import_zod4 = require("zod");
642
+ init_schemas();
643
+ init_registrations();
644
+ init_zod();
645
+ }
646
+ });
647
+
648
+ // src/mcp/index.ts
649
+ var mcp_exports = {};
650
+ __export(mcp_exports, {
651
+ ThenvoiMcpServer: () => ThenvoiMcpServer,
652
+ ThenvoiMcpSseServer: () => ThenvoiMcpSseServer,
653
+ ThenvoiMcpStdioServer: () => ThenvoiMcpStdioServer,
654
+ buildRoomScopedRegistrations: () => buildRoomScopedRegistrations,
655
+ buildSingleContextRegistrations: () => buildSingleContextRegistrations,
656
+ createThenvoiMcpBackend: () => createThenvoiMcpBackend,
657
+ errorResult: () => errorResult,
658
+ getThenvoiSdkMcpServerConfig: () => getThenvoiSdkMcpServerConfig,
659
+ successResult: () => successResult
660
+ });
661
+ module.exports = __toCommonJS(mcp_exports);
662
+
663
+ // src/mcp/backends.ts
664
+ init_schemas();
665
+ init_registrations();
666
+
667
+ // src/mcp/stdio.ts
668
+ init_registrations();
669
+ init_zod();
670
+ var ThenvoiMcpStdioServer = class {
671
+ options;
672
+ registrations;
673
+ mcpServer = null;
674
+ transport = null;
675
+ constructor(options) {
676
+ this.options = options;
677
+ const regOptions = {
678
+ enableMemoryTools: options.enableMemoryTools,
679
+ enableContactTools: options.enableContactTools,
680
+ additionalTools: options.additionalTools
681
+ };
682
+ if (typeof options.tools === "function") {
683
+ this.registrations = buildRoomScopedRegistrations(options.tools, regOptions);
684
+ } else {
685
+ this.registrations = buildSingleContextRegistrations(options.tools, regOptions);
686
+ }
687
+ }
688
+ get toolNames() {
689
+ return this.registrations.map((r) => r.name);
690
+ }
691
+ async start() {
692
+ if (this.transport) {
693
+ return;
694
+ }
695
+ const { McpServer } = await import("@modelcontextprotocol/sdk/server/mcp.js");
696
+ const { StdioServerTransport } = await import("@modelcontextprotocol/sdk/server/stdio.js");
697
+ const { z: z2 } = await import("zod");
698
+ const mcpServer = new McpServer({
699
+ name: this.options.name ?? "thenvoi",
700
+ version: "1.0.0"
701
+ });
702
+ registerTools(mcpServer, z2, this.registrations);
703
+ const transport = new StdioServerTransport(this.options.stdin, this.options.stdout);
704
+ await mcpServer.connect(transport);
705
+ this.mcpServer = mcpServer;
706
+ this.transport = transport;
707
+ }
708
+ async stop() {
709
+ await this.transport?.close();
710
+ this.transport = null;
711
+ this.mcpServer = null;
712
+ }
713
+ };
714
+ function registerTools(mcpServer, z2, registrations) {
715
+ for (const reg of registrations) {
716
+ const zodShape = buildZodShape(z2, reg.inputSchema.properties, new Set(reg.inputSchema.required));
717
+ mcpServer.registerTool(
718
+ reg.name,
719
+ {
720
+ description: reg.description,
721
+ inputSchema: z2.object(zodShape)
722
+ },
723
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- MCP SDK handler signature is complex; our McpToolResult is compatible
724
+ async (args) => reg.execute(args)
725
+ );
726
+ }
727
+ }
728
+
729
+ // src/mcp/server.ts
730
+ init_registrations();
731
+ init_zod();
732
+ var PORT_RANGE_START = 5e4;
733
+ var PORT_RANGE_END = 6e4;
734
+ var MCP_SERVER_VERSION = "1.0.0";
735
+ var SESSION_IDLE_TTL_MS = 15 * 60 * 1e3;
736
+ var SESSION_SWEEP_INTERVAL_MS = 60 * 1e3;
737
+ var ThenvoiMcpServer = class {
738
+ options;
739
+ registrations;
740
+ httpServer = null;
741
+ actualPort = null;
742
+ sessions = /* @__PURE__ */ new Map();
743
+ sessionSweepTimer = null;
744
+ constructor(options) {
745
+ this.options = options;
746
+ const regOptions = {
747
+ enableMemoryTools: options.enableMemoryTools,
748
+ enableContactTools: options.enableContactTools,
749
+ additionalTools: options.additionalTools
750
+ };
751
+ if (typeof options.tools === "function") {
752
+ this.registrations = buildRoomScopedRegistrations(options.tools, regOptions);
753
+ } else {
754
+ this.registrations = buildSingleContextRegistrations(options.tools, regOptions);
755
+ }
756
+ }
757
+ /** Port the server is listening on. Null if not started. */
758
+ get port() {
759
+ return this.actualPort;
760
+ }
761
+ /** MCP endpoint URL. Null if not started. */
762
+ get url() {
763
+ if (this.actualPort === null) {
764
+ return null;
765
+ }
766
+ return `http://127.0.0.1:${this.actualPort}/mcp`;
767
+ }
768
+ /** Tool names registered on this server. */
769
+ get toolNames() {
770
+ return this.registrations.map((r) => r.name);
771
+ }
772
+ async start() {
773
+ const { McpServer } = await import("@modelcontextprotocol/sdk/server/mcp.js");
774
+ const { StreamableHTTPServerTransport } = await import("@modelcontextprotocol/sdk/server/streamableHttp.js");
775
+ const { isInitializeRequest } = await import("@modelcontextprotocol/sdk/types.js");
776
+ const expressModule = await import("express");
777
+ const express = expressModule.default ?? expressModule;
778
+ const http = await import("http");
779
+ const { randomUUID } = await import("crypto");
780
+ const { z: z2 } = await import("zod");
781
+ const serverName = this.options.name ?? "thenvoi";
782
+ const app = express();
783
+ app.use(express.json());
784
+ app.get("/healthz", (_req, res) => {
785
+ res.json({ status: "ok" });
786
+ });
787
+ const handleMcpRequest = async (req, res) => {
788
+ try {
789
+ const sessionId = getSessionIdHeader(req.headers["mcp-session-id"]);
790
+ let session = sessionId ? this.sessions.get(sessionId) : void 0;
791
+ if (!session) {
792
+ if (req.method !== "POST" || sessionId || !isInitializeRequest(req.body)) {
793
+ sendMcpError(res, sessionId ? 404 : 400, sessionId ? "Session not found" : "Bad Request: No valid session ID provided");
794
+ return;
795
+ }
796
+ session = await this.createSession({
797
+ McpServer,
798
+ StreamableHTTPServerTransport,
799
+ serverName,
800
+ sessionIdGenerator: randomUUID,
801
+ z: z2
802
+ });
803
+ }
804
+ session.lastSeenAt = Date.now();
805
+ await session.transport.handleRequest(req, res, req.body);
806
+ } catch (error) {
807
+ if (!res.headersSent) {
808
+ sendMcpError(res, 500, "Internal server error");
809
+ }
810
+ }
811
+ };
812
+ app.post("/mcp", async (req, res) => {
813
+ await handleMcpRequest(req, res);
814
+ });
815
+ app.get("/mcp", async (req, res) => {
816
+ await handleMcpRequest(req, res);
817
+ });
818
+ app.delete("/mcp", async (req, res) => {
819
+ await handleMcpRequest(req, res);
820
+ });
821
+ const port = this.options.port ?? await findAvailablePort(http);
822
+ return new Promise((resolve, reject) => {
823
+ const server = http.createServer(app);
824
+ server.on("error", reject);
825
+ server.listen(port, "127.0.0.1", () => {
826
+ this.httpServer = server;
827
+ this.actualPort = port;
828
+ this.startSessionSweep();
829
+ resolve();
830
+ });
831
+ });
832
+ }
833
+ async stop() {
834
+ this.stopSessionSweep();
835
+ const activeSessions = [...this.sessions.values()];
836
+ this.sessions.clear();
837
+ await Promise.all(activeSessions.map(async (session) => {
838
+ await session.transport.close();
839
+ }));
840
+ if (!this.httpServer) {
841
+ return;
842
+ }
843
+ return new Promise((resolve, reject) => {
844
+ this.httpServer.close((error) => {
845
+ this.httpServer = null;
846
+ this.actualPort = null;
847
+ if (error) {
848
+ reject(error);
849
+ } else {
850
+ resolve();
851
+ }
852
+ });
853
+ });
854
+ }
855
+ async createSession(input) {
856
+ const createdAt = Date.now();
857
+ const mcpServer = new input.McpServer({ name: input.serverName, version: MCP_SERVER_VERSION });
858
+ registerTools2(mcpServer, input.z, this.registrations);
859
+ let record = null;
860
+ const transport = new input.StreamableHTTPServerTransport({
861
+ sessionIdGenerator: input.sessionIdGenerator,
862
+ onsessioninitialized: (sessionId) => {
863
+ if (!record) {
864
+ return;
865
+ }
866
+ this.sessions.set(sessionId, record);
867
+ },
868
+ onsessionclosed: (sessionId) => {
869
+ this.sessions.delete(sessionId);
870
+ }
871
+ });
872
+ transport.onclose = () => {
873
+ const sessionId = transport.sessionId;
874
+ if (sessionId) {
875
+ this.sessions.delete(sessionId);
876
+ }
877
+ };
878
+ await mcpServer.connect(transport);
879
+ record = {
880
+ mcpServer,
881
+ transport,
882
+ createdAt,
883
+ lastSeenAt: createdAt
884
+ };
885
+ return record;
886
+ }
887
+ startSessionSweep() {
888
+ if (this.sessionSweepTimer) {
889
+ return;
890
+ }
891
+ this.sessionSweepTimer = setInterval(() => {
892
+ void this.closeIdleSessions();
893
+ }, SESSION_SWEEP_INTERVAL_MS);
894
+ this.sessionSweepTimer.unref?.();
895
+ }
896
+ stopSessionSweep() {
897
+ if (!this.sessionSweepTimer) {
898
+ return;
899
+ }
900
+ clearInterval(this.sessionSweepTimer);
901
+ this.sessionSweepTimer = null;
902
+ }
903
+ async closeIdleSessions() {
904
+ const cutoff = Date.now() - SESSION_IDLE_TTL_MS;
905
+ const idleSessions = [...this.sessions.values()].filter((session) => session.lastSeenAt < cutoff);
906
+ await Promise.all(idleSessions.map(async (session) => {
907
+ await session.transport.close();
908
+ }));
909
+ }
910
+ };
911
+ function getSessionIdHeader(headerValue) {
912
+ if (typeof headerValue === "string" && headerValue.length > 0) {
913
+ return headerValue;
914
+ }
915
+ return null;
916
+ }
917
+ function sendMcpError(res, status, message) {
918
+ res.status(status).json({
919
+ jsonrpc: "2.0",
920
+ error: {
921
+ code: -32e3,
922
+ message
923
+ },
924
+ id: null
925
+ });
926
+ }
927
+ function registerTools2(mcpServer, z2, registrations) {
928
+ for (const reg of registrations) {
929
+ const zodShape = buildZodShape(z2, reg.inputSchema.properties, new Set(reg.inputSchema.required));
930
+ mcpServer.registerTool(
931
+ reg.name,
932
+ {
933
+ description: reg.description,
934
+ inputSchema: z2.object(zodShape)
935
+ },
936
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- MCP SDK handler signature is complex; our McpToolResult is compatible
937
+ async (args) => reg.execute(args)
938
+ );
939
+ }
940
+ }
941
+ async function findAvailablePort(http) {
942
+ for (let attempt = 0; attempt < 20; attempt++) {
943
+ const port = PORT_RANGE_START + Math.floor(Math.random() * (PORT_RANGE_END - PORT_RANGE_START));
944
+ const available = await checkPort(http, port);
945
+ if (available) {
946
+ return port;
947
+ }
948
+ }
949
+ return 0;
950
+ }
951
+ function checkPort(http, port) {
952
+ return new Promise((resolve) => {
953
+ const server = http.createServer();
954
+ server.once("error", () => resolve(false));
955
+ server.listen(port, "127.0.0.1", () => {
956
+ server.close(() => resolve(true));
957
+ });
958
+ });
959
+ }
960
+
961
+ // src/mcp/sse.ts
962
+ init_registrations();
963
+ init_zod();
964
+ var PORT_RANGE_START2 = 5e4;
965
+ var PORT_RANGE_END2 = 6e4;
966
+ var SESSION_IDLE_TTL_MS2 = 15 * 60 * 1e3;
967
+ var SESSION_SWEEP_INTERVAL_MS2 = 60 * 1e3;
968
+ var ThenvoiMcpSseServer = class {
969
+ options;
970
+ registrations;
971
+ httpServer = null;
972
+ actualPort = null;
973
+ sessions = /* @__PURE__ */ new Map();
974
+ sweepTimer = null;
975
+ constructor(options) {
976
+ this.options = options;
977
+ const regOptions = {
978
+ enableMemoryTools: options.enableMemoryTools,
979
+ enableContactTools: options.enableContactTools,
980
+ additionalTools: options.additionalTools
981
+ };
982
+ if (typeof options.tools === "function") {
983
+ this.registrations = buildRoomScopedRegistrations(options.tools, regOptions);
984
+ } else {
985
+ this.registrations = buildSingleContextRegistrations(options.tools, regOptions);
986
+ }
987
+ }
988
+ get port() {
989
+ return this.actualPort;
990
+ }
991
+ get sseUrl() {
992
+ if (this.actualPort === null) {
993
+ return null;
994
+ }
995
+ return `http://127.0.0.1:${this.actualPort}/sse`;
996
+ }
997
+ get toolNames() {
998
+ return this.registrations.map((registration) => registration.name);
999
+ }
1000
+ async start() {
1001
+ if (this.httpServer) {
1002
+ return;
1003
+ }
1004
+ const { McpServer } = await import("@modelcontextprotocol/sdk/server/mcp.js");
1005
+ const { SSEServerTransport } = await import("@modelcontextprotocol/sdk/server/sse.js");
1006
+ const expressModule = await import("express");
1007
+ const express = expressModule.default ?? expressModule;
1008
+ const http = await import("http");
1009
+ const { z: z2 } = await import("zod");
1010
+ const app = express();
1011
+ app.use(express.json());
1012
+ app.get("/healthz", (_req, res) => {
1013
+ res.json({ status: "ok" });
1014
+ });
1015
+ app.get("/sse", async (_req, res) => {
1016
+ const transport = new SSEServerTransport("/messages", res);
1017
+ const mcpServer = new McpServer({
1018
+ name: this.options.name ?? "thenvoi",
1019
+ version: "1.0.0"
1020
+ });
1021
+ registerTools3(mcpServer, z2, this.registrations);
1022
+ await mcpServer.connect(transport);
1023
+ const sessionId = transport.sessionId;
1024
+ this.sessions.set(sessionId, {
1025
+ mcpServer,
1026
+ transport,
1027
+ lastSeenAt: Date.now()
1028
+ });
1029
+ transport.onclose = () => {
1030
+ this.sessions.delete(sessionId);
1031
+ };
1032
+ transport.onerror = () => {
1033
+ this.sessions.delete(sessionId);
1034
+ };
1035
+ res.on("close", () => {
1036
+ this.sessions.delete(sessionId);
1037
+ });
1038
+ });
1039
+ app.post("/messages", async (req, res) => {
1040
+ const sessionId = typeof req.query.sessionId === "string" ? req.query.sessionId : null;
1041
+ if (!sessionId) {
1042
+ res.status(400).send("Missing sessionId");
1043
+ return;
1044
+ }
1045
+ const session = this.sessions.get(sessionId);
1046
+ if (!session) {
1047
+ res.status(404).send("Session not found");
1048
+ return;
1049
+ }
1050
+ session.lastSeenAt = Date.now();
1051
+ await session.transport.handlePostMessage(req, res, req.body);
1052
+ });
1053
+ const port = this.options.port ?? await findAvailablePort2(http);
1054
+ await new Promise((resolve, reject) => {
1055
+ const server = http.createServer(app);
1056
+ server.on("error", reject);
1057
+ server.listen(port, "127.0.0.1", () => {
1058
+ this.httpServer = server;
1059
+ this.actualPort = port;
1060
+ this.startSessionSweep();
1061
+ resolve();
1062
+ });
1063
+ });
1064
+ }
1065
+ async stop() {
1066
+ this.stopSessionSweep();
1067
+ const sessions = [...this.sessions.values()];
1068
+ this.sessions.clear();
1069
+ await Promise.all(sessions.map(async (session) => {
1070
+ await session.transport.close();
1071
+ }));
1072
+ if (!this.httpServer) {
1073
+ return;
1074
+ }
1075
+ const server = this.httpServer;
1076
+ this.httpServer = null;
1077
+ this.actualPort = null;
1078
+ await new Promise((resolve, reject) => {
1079
+ server.close((error) => {
1080
+ if (error) {
1081
+ reject(error);
1082
+ return;
1083
+ }
1084
+ resolve();
1085
+ });
1086
+ });
1087
+ }
1088
+ startSessionSweep() {
1089
+ if (this.sweepTimer) {
1090
+ return;
1091
+ }
1092
+ this.sweepTimer = setInterval(() => {
1093
+ this.closeIdleSessions();
1094
+ }, SESSION_SWEEP_INTERVAL_MS2);
1095
+ this.sweepTimer.unref?.();
1096
+ }
1097
+ stopSessionSweep() {
1098
+ if (this.sweepTimer) {
1099
+ clearInterval(this.sweepTimer);
1100
+ this.sweepTimer = null;
1101
+ }
1102
+ }
1103
+ closeIdleSessions() {
1104
+ const cutoff = Date.now() - SESSION_IDLE_TTL_MS2;
1105
+ for (const [sessionId, session] of this.sessions) {
1106
+ if (session.lastSeenAt < cutoff) {
1107
+ this.sessions.delete(sessionId);
1108
+ void session.transport.close();
1109
+ }
1110
+ }
1111
+ }
1112
+ };
1113
+ function registerTools3(mcpServer, z2, registrations) {
1114
+ for (const registration of registrations) {
1115
+ const zodShape = buildZodShape(
1116
+ z2,
1117
+ registration.inputSchema.properties,
1118
+ new Set(registration.inputSchema.required)
1119
+ );
1120
+ mcpServer.registerTool(
1121
+ registration.name,
1122
+ {
1123
+ description: registration.description,
1124
+ inputSchema: z2.object(zodShape)
1125
+ },
1126
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- MCP SDK handler signature is complex; our McpToolResult is compatible
1127
+ async (args) => registration.execute(args)
1128
+ );
1129
+ }
1130
+ }
1131
+ async function findAvailablePort2(http) {
1132
+ for (let attempt = 0; attempt < 20; attempt += 1) {
1133
+ const port = PORT_RANGE_START2 + Math.floor(Math.random() * (PORT_RANGE_END2 - PORT_RANGE_START2));
1134
+ if (await checkPort2(http, port)) {
1135
+ return port;
1136
+ }
1137
+ }
1138
+ return 0;
1139
+ }
1140
+ function checkPort2(http, port) {
1141
+ return new Promise((resolve) => {
1142
+ const server = http.createServer();
1143
+ server.once("error", () => {
1144
+ resolve(false);
1145
+ });
1146
+ server.listen(port, "127.0.0.1", () => {
1147
+ server.close(() => resolve(true));
1148
+ });
1149
+ });
1150
+ }
1151
+
1152
+ // src/mcp/backends.ts
1153
+ async function createThenvoiMcpBackend(options) {
1154
+ const registrations = buildRoomScopedRegistrations(
1155
+ options.getToolsForRoom,
1156
+ {
1157
+ enableMemoryTools: options.enableMemoryTools,
1158
+ enableContactTools: true,
1159
+ additionalTools: options.additionalTools
1160
+ }
1161
+ );
1162
+ const allowedTools = mcpToolNames(new Set(registrations.map((registration) => registration.name)));
1163
+ if (options.kind === "sdk") {
1164
+ const { createThenvoiSdkMcpServer: createThenvoiSdkMcpServer2 } = await Promise.resolve().then(() => (init_sdk(), sdk_exports));
1165
+ const server2 = createThenvoiSdkMcpServer2({
1166
+ enableMemoryTools: options.enableMemoryTools,
1167
+ getToolsForRoom: options.getToolsForRoom,
1168
+ additionalTools: options.additionalTools
1169
+ });
1170
+ return {
1171
+ kind: "sdk",
1172
+ server: server2,
1173
+ allowedTools: server2.allowedTools,
1174
+ stop: async () => void 0
1175
+ };
1176
+ }
1177
+ if (options.kind === "stdio") {
1178
+ const server2 = new ThenvoiMcpStdioServer({
1179
+ tools: options.getToolsForRoom,
1180
+ enableMemoryTools: options.enableMemoryTools,
1181
+ enableContactTools: true,
1182
+ additionalTools: options.additionalTools
1183
+ });
1184
+ await server2.start();
1185
+ return {
1186
+ kind: "stdio",
1187
+ server: server2,
1188
+ allowedTools,
1189
+ stop: async () => {
1190
+ await server2.stop();
1191
+ }
1192
+ };
1193
+ }
1194
+ if (options.kind === "sse") {
1195
+ const server2 = new ThenvoiMcpSseServer({
1196
+ tools: options.getToolsForRoom,
1197
+ enableMemoryTools: options.enableMemoryTools,
1198
+ enableContactTools: true,
1199
+ additionalTools: options.additionalTools
1200
+ });
1201
+ await server2.start();
1202
+ return {
1203
+ kind: "sse",
1204
+ server: server2,
1205
+ allowedTools,
1206
+ stop: async () => {
1207
+ await server2.stop();
1208
+ }
1209
+ };
1210
+ }
1211
+ const server = new ThenvoiMcpServer({
1212
+ tools: options.getToolsForRoom,
1213
+ enableMemoryTools: options.enableMemoryTools,
1214
+ enableContactTools: true,
1215
+ additionalTools: options.additionalTools
1216
+ });
1217
+ await server.start();
1218
+ return {
1219
+ kind: "http",
1220
+ server,
1221
+ allowedTools,
1222
+ stop: async () => {
1223
+ await server.stop();
1224
+ }
1225
+ };
1226
+ }
1227
+ function getThenvoiSdkMcpServerConfig(backend) {
1228
+ if (backend.kind !== "sdk") {
1229
+ throw new Error(`Expected sdk MCP backend, received ${backend.kind}`);
1230
+ }
1231
+ return backend.server.serverConfig;
1232
+ }
1233
+
1234
+ // src/mcp/index.ts
1235
+ init_registrations();
1236
+ // Annotate the CommonJS export names for ESM import in node:
1237
+ 0 && (module.exports = {
1238
+ ThenvoiMcpServer,
1239
+ ThenvoiMcpSseServer,
1240
+ ThenvoiMcpStdioServer,
1241
+ buildRoomScopedRegistrations,
1242
+ buildSingleContextRegistrations,
1243
+ createThenvoiMcpBackend,
1244
+ errorResult,
1245
+ getThenvoiSdkMcpServerConfig,
1246
+ successResult
1247
+ });