@agentconnect.md/daemon 1.0.0-rc.23 → 1.0.0-rc.231

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 (55) hide show
  1. package/dist/acp-host-CXUQ91Gh.js +10642 -0
  2. package/dist/acp-host-CXUQ91Gh.js.map +1 -0
  3. package/dist/agent-list-BAjZvFsO.js +21 -0
  4. package/dist/agent-list-BAjZvFsO.js.map +1 -0
  5. package/dist/bridge-DXIVgEzf.js +726 -0
  6. package/dist/bridge-DXIVgEzf.js.map +1 -0
  7. package/dist/chat-Di5QFvjw.js +79 -0
  8. package/dist/chat-Di5QFvjw.js.map +1 -0
  9. package/dist/commander-B5QVEFzH.js +2965 -0
  10. package/dist/commander-B5QVEFzH.js.map +1 -0
  11. package/dist/esm-DrGCKNjx.js +1516 -0
  12. package/dist/esm-DrGCKNjx.js.map +1 -0
  13. package/dist/execAsync-C-9b-eWN.js +12 -0
  14. package/dist/execAsync-C-9b-eWN.js.map +1 -0
  15. package/dist/getMachineId-bsd-CfqSzACM.js +29 -0
  16. package/dist/getMachineId-bsd-CfqSzACM.js.map +1 -0
  17. package/dist/getMachineId-darwin-CDKafrUs.js +26 -0
  18. package/dist/getMachineId-darwin-CDKafrUs.js.map +1 -0
  19. package/dist/getMachineId-linux-DG3AvXtg.js +22 -0
  20. package/dist/getMachineId-linux-DG3AvXtg.js.map +1 -0
  21. package/dist/getMachineId-unsupported-BIPpTXqb.js +17 -0
  22. package/dist/getMachineId-unsupported-BIPpTXqb.js.map +1 -0
  23. package/dist/getMachineId-win-DNO3uByP.js +28 -0
  24. package/dist/getMachineId-win-DNO3uByP.js.map +1 -0
  25. package/dist/git-credential-BfkyzKn2.js +99 -0
  26. package/dist/git-credential-BfkyzKn2.js.map +1 -0
  27. package/dist/gitcred-server-Dcsq6QJe.js +236 -0
  28. package/dist/gitcred-server-Dcsq6QJe.js.map +1 -0
  29. package/dist/index.js +67364 -79992
  30. package/dist/index.js.map +1 -1
  31. package/dist/load-agents-tb8Rcwan.js +356 -0
  32. package/dist/load-agents-tb8Rcwan.js.map +1 -0
  33. package/dist/lock-CA9Bm8_s.js +66 -0
  34. package/dist/lock-CA9Bm8_s.js.map +1 -0
  35. package/dist/login-8pfSiMc2.js +229 -0
  36. package/dist/login-8pfSiMc2.js.map +1 -0
  37. package/dist/paths-CcRUjFjy.js +2 -0
  38. package/dist/paths-DEcUO8lC.js +43 -0
  39. package/dist/paths-DEcUO8lC.js.map +1 -0
  40. package/dist/rolldown-runtime-CE-6LUnI.js +44 -0
  41. package/dist/run-foreground-Cg2ewYjn.js +138640 -0
  42. package/dist/run-foreground-Cg2ewYjn.js.map +1 -0
  43. package/dist/run-foreground-DxSBKNXU.js +2 -0
  44. package/dist/schemas-CQkO9hC5.js +4382 -0
  45. package/dist/schemas-CQkO9hC5.js.map +1 -0
  46. package/dist/service-6w0WKhdx.js +2 -0
  47. package/dist/service-BQVw7wbz.js +245 -0
  48. package/dist/service-BQVw7wbz.js.map +1 -0
  49. package/dist/src-DDtlVutj.js +811 -0
  50. package/dist/src-DDtlVutj.js.map +1 -0
  51. package/dist/stdio-CwrB9yrX.js +9218 -0
  52. package/dist/stdio-CwrB9yrX.js.map +1 -0
  53. package/dist/version-DGaRXjBK.js +7 -0
  54. package/dist/version-DGaRXjBK.js.map +1 -0
  55. package/package.json +2 -1
@@ -0,0 +1,726 @@
1
+ import { t as DAEMON_VERSION } from "./version-DGaRXjBK.js";
2
+ import { A as ListToolsRequestSchema, G as safeParse, K as decodeFrames, L as SUPPORTED_PROTOCOL_VERSIONS, M as LoggingLevelSchema, N as McpError, R as SetLevelRequestSchema, S as InitializedNotificationSchema, U as getObjectShape, W as isZ4Schema, _ as EmptyResultSchema, a as AjvJsonSchemaValidator, b as InitializeRequestSchema, c as CallToolRequestSchema, f as CreateMessageResultSchema, g as ElicitResultSchema, i as assertToolsCallTaskCapability, k as ListRootsResultSchema, l as CallToolResultSchema, m as CreateTaskResultSchema, n as serializeMessage, o as Protocol, p as CreateMessageResultWithToolsSchema, q as encodeFrame, r as assertClientRequestTaskCapability, s as mergeCapabilities, t as ReadBuffer, v as ErrorCode, w as LATEST_PROTOCOL_VERSION } from "./stdio-CwrB9yrX.js";
3
+ import process$1 from "node:process";
4
+ import net from "node:net";
5
+ //#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.29.0_zod@4.4.3/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/server.js
6
+ /**
7
+ * Experimental server task features for MCP SDK.
8
+ * WARNING: These APIs are experimental and may change without notice.
9
+ *
10
+ * @experimental
11
+ */
12
+ /**
13
+ * Experimental task features for low-level MCP servers.
14
+ *
15
+ * Access via `server.experimental.tasks`:
16
+ * ```typescript
17
+ * const stream = server.experimental.tasks.requestStream(request, schema, options);
18
+ * ```
19
+ *
20
+ * For high-level server usage with task-based tools, use `McpServer.experimental.tasks` instead.
21
+ *
22
+ * @experimental
23
+ */
24
+ var ExperimentalServerTasks = class {
25
+ constructor(_server) {
26
+ this._server = _server;
27
+ }
28
+ /**
29
+ * Sends a request and returns an AsyncGenerator that yields response messages.
30
+ * The generator is guaranteed to end with either a 'result' or 'error' message.
31
+ *
32
+ * This method provides streaming access to request processing, allowing you to
33
+ * observe intermediate task status updates for task-augmented requests.
34
+ *
35
+ * @param request - The request to send
36
+ * @param resultSchema - Zod schema for validating the result
37
+ * @param options - Optional request options (timeout, signal, task creation params, etc.)
38
+ * @returns AsyncGenerator that yields ResponseMessage objects
39
+ *
40
+ * @experimental
41
+ */
42
+ requestStream(request, resultSchema, options) {
43
+ return this._server.requestStream(request, resultSchema, options);
44
+ }
45
+ /**
46
+ * Sends a sampling request and returns an AsyncGenerator that yields response messages.
47
+ * The generator is guaranteed to end with either a 'result' or 'error' message.
48
+ *
49
+ * For task-augmented requests, yields 'taskCreated' and 'taskStatus' messages
50
+ * before the final result.
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * const stream = server.experimental.tasks.createMessageStream({
55
+ * messages: [{ role: 'user', content: { type: 'text', text: 'Hello' } }],
56
+ * maxTokens: 100
57
+ * }, {
58
+ * onprogress: (progress) => {
59
+ * // Handle streaming tokens via progress notifications
60
+ * console.log('Progress:', progress.message);
61
+ * }
62
+ * });
63
+ *
64
+ * for await (const message of stream) {
65
+ * switch (message.type) {
66
+ * case 'taskCreated':
67
+ * console.log('Task created:', message.task.taskId);
68
+ * break;
69
+ * case 'taskStatus':
70
+ * console.log('Task status:', message.task.status);
71
+ * break;
72
+ * case 'result':
73
+ * console.log('Final result:', message.result);
74
+ * break;
75
+ * case 'error':
76
+ * console.error('Error:', message.error);
77
+ * break;
78
+ * }
79
+ * }
80
+ * ```
81
+ *
82
+ * @param params - The sampling request parameters
83
+ * @param options - Optional request options (timeout, signal, task creation params, onprogress, etc.)
84
+ * @returns AsyncGenerator that yields ResponseMessage objects
85
+ *
86
+ * @experimental
87
+ */
88
+ createMessageStream(params, options) {
89
+ const clientCapabilities = this._server.getClientCapabilities();
90
+ if ((params.tools || params.toolChoice) && !clientCapabilities?.sampling?.tools) throw new Error("Client does not support sampling tools capability.");
91
+ if (params.messages.length > 0) {
92
+ const lastMessage = params.messages[params.messages.length - 1];
93
+ const lastContent = Array.isArray(lastMessage.content) ? lastMessage.content : [lastMessage.content];
94
+ const hasToolResults = lastContent.some((c) => c.type === "tool_result");
95
+ const previousMessage = params.messages.length > 1 ? params.messages[params.messages.length - 2] : void 0;
96
+ const previousContent = previousMessage ? Array.isArray(previousMessage.content) ? previousMessage.content : [previousMessage.content] : [];
97
+ const hasPreviousToolUse = previousContent.some((c) => c.type === "tool_use");
98
+ if (hasToolResults) {
99
+ if (lastContent.some((c) => c.type !== "tool_result")) throw new Error("The last message must contain only tool_result content if any is present");
100
+ if (!hasPreviousToolUse) throw new Error("tool_result blocks are not matching any tool_use from the previous message");
101
+ }
102
+ if (hasPreviousToolUse) {
103
+ const toolUseIds = new Set(previousContent.filter((c) => c.type === "tool_use").map((c) => c.id));
104
+ const toolResultIds = new Set(lastContent.filter((c) => c.type === "tool_result").map((c) => c.toolUseId));
105
+ if (toolUseIds.size !== toolResultIds.size || ![...toolUseIds].every((id) => toolResultIds.has(id))) throw new Error("ids of tool_result blocks and tool_use blocks from previous message do not match");
106
+ }
107
+ }
108
+ return this.requestStream({
109
+ method: "sampling/createMessage",
110
+ params
111
+ }, CreateMessageResultSchema, options);
112
+ }
113
+ /**
114
+ * Sends an elicitation request and returns an AsyncGenerator that yields response messages.
115
+ * The generator is guaranteed to end with either a 'result' or 'error' message.
116
+ *
117
+ * For task-augmented requests (especially URL-based elicitation), yields 'taskCreated'
118
+ * and 'taskStatus' messages before the final result.
119
+ *
120
+ * @example
121
+ * ```typescript
122
+ * const stream = server.experimental.tasks.elicitInputStream({
123
+ * mode: 'url',
124
+ * message: 'Please authenticate',
125
+ * elicitationId: 'auth-123',
126
+ * url: 'https://example.com/auth'
127
+ * }, {
128
+ * task: { ttl: 300000 } // Task-augmented for long-running auth flow
129
+ * });
130
+ *
131
+ * for await (const message of stream) {
132
+ * switch (message.type) {
133
+ * case 'taskCreated':
134
+ * console.log('Task created:', message.task.taskId);
135
+ * break;
136
+ * case 'taskStatus':
137
+ * console.log('Task status:', message.task.status);
138
+ * break;
139
+ * case 'result':
140
+ * console.log('User action:', message.result.action);
141
+ * break;
142
+ * case 'error':
143
+ * console.error('Error:', message.error);
144
+ * break;
145
+ * }
146
+ * }
147
+ * ```
148
+ *
149
+ * @param params - The elicitation request parameters
150
+ * @param options - Optional request options (timeout, signal, task creation params, etc.)
151
+ * @returns AsyncGenerator that yields ResponseMessage objects
152
+ *
153
+ * @experimental
154
+ */
155
+ elicitInputStream(params, options) {
156
+ const clientCapabilities = this._server.getClientCapabilities();
157
+ const mode = params.mode ?? "form";
158
+ switch (mode) {
159
+ case "url":
160
+ if (!clientCapabilities?.elicitation?.url) throw new Error("Client does not support url elicitation.");
161
+ break;
162
+ case "form":
163
+ if (!clientCapabilities?.elicitation?.form) throw new Error("Client does not support form elicitation.");
164
+ break;
165
+ }
166
+ const normalizedParams = mode === "form" && params.mode === void 0 ? {
167
+ ...params,
168
+ mode: "form"
169
+ } : params;
170
+ return this.requestStream({
171
+ method: "elicitation/create",
172
+ params: normalizedParams
173
+ }, ElicitResultSchema, options);
174
+ }
175
+ /**
176
+ * Gets the current status of a task.
177
+ *
178
+ * @param taskId - The task identifier
179
+ * @param options - Optional request options
180
+ * @returns The task status
181
+ *
182
+ * @experimental
183
+ */
184
+ async getTask(taskId, options) {
185
+ return this._server.getTask({ taskId }, options);
186
+ }
187
+ /**
188
+ * Retrieves the result of a completed task.
189
+ *
190
+ * @param taskId - The task identifier
191
+ * @param resultSchema - Zod schema for validating the result
192
+ * @param options - Optional request options
193
+ * @returns The task result
194
+ *
195
+ * @experimental
196
+ */
197
+ async getTaskResult(taskId, resultSchema, options) {
198
+ return this._server.getTaskResult({ taskId }, resultSchema, options);
199
+ }
200
+ /**
201
+ * Lists tasks with optional pagination.
202
+ *
203
+ * @param cursor - Optional pagination cursor
204
+ * @param options - Optional request options
205
+ * @returns List of tasks with optional next cursor
206
+ *
207
+ * @experimental
208
+ */
209
+ async listTasks(cursor, options) {
210
+ return this._server.listTasks(cursor ? { cursor } : void 0, options);
211
+ }
212
+ /**
213
+ * Cancels a running task.
214
+ *
215
+ * @param taskId - The task identifier
216
+ * @param options - Optional request options
217
+ *
218
+ * @experimental
219
+ */
220
+ async cancelTask(taskId, options) {
221
+ return this._server.cancelTask({ taskId }, options);
222
+ }
223
+ };
224
+ //#endregion
225
+ //#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.29.0_zod@4.4.3/node_modules/@modelcontextprotocol/sdk/dist/esm/server/index.js
226
+ /**
227
+ * An MCP server on top of a pluggable transport.
228
+ *
229
+ * This server will automatically respond to the initialization flow as initiated from the client.
230
+ *
231
+ * To use with custom types, extend the base Request/Notification/Result types and pass them as type parameters:
232
+ *
233
+ * ```typescript
234
+ * // Custom schemas
235
+ * const CustomRequestSchema = RequestSchema.extend({...})
236
+ * const CustomNotificationSchema = NotificationSchema.extend({...})
237
+ * const CustomResultSchema = ResultSchema.extend({...})
238
+ *
239
+ * // Type aliases
240
+ * type CustomRequest = z.infer<typeof CustomRequestSchema>
241
+ * type CustomNotification = z.infer<typeof CustomNotificationSchema>
242
+ * type CustomResult = z.infer<typeof CustomResultSchema>
243
+ *
244
+ * // Create typed server
245
+ * const server = new Server<CustomRequest, CustomNotification, CustomResult>({
246
+ * name: "CustomServer",
247
+ * version: "1.0.0"
248
+ * })
249
+ * ```
250
+ * @deprecated Use `McpServer` instead for the high-level API. Only use `Server` for advanced use cases.
251
+ */
252
+ var Server = class extends Protocol {
253
+ /**
254
+ * Initializes this server with the given name and version information.
255
+ */
256
+ constructor(_serverInfo, options) {
257
+ super(options);
258
+ this._serverInfo = _serverInfo;
259
+ this._loggingLevels = /* @__PURE__ */ new Map();
260
+ this.LOG_LEVEL_SEVERITY = new Map(LoggingLevelSchema.options.map((level, index) => [level, index]));
261
+ this.isMessageIgnored = (level, sessionId) => {
262
+ const currentLevel = this._loggingLevels.get(sessionId);
263
+ return currentLevel ? this.LOG_LEVEL_SEVERITY.get(level) < this.LOG_LEVEL_SEVERITY.get(currentLevel) : false;
264
+ };
265
+ this._capabilities = options?.capabilities ?? {};
266
+ this._instructions = options?.instructions;
267
+ this._jsonSchemaValidator = options?.jsonSchemaValidator ?? new AjvJsonSchemaValidator();
268
+ this.setRequestHandler(InitializeRequestSchema, (request) => this._oninitialize(request));
269
+ this.setNotificationHandler(InitializedNotificationSchema, () => this.oninitialized?.());
270
+ if (this._capabilities.logging) this.setRequestHandler(SetLevelRequestSchema, async (request, extra) => {
271
+ const transportSessionId = extra.sessionId || extra.requestInfo?.headers["mcp-session-id"] || void 0;
272
+ const { level } = request.params;
273
+ const parseResult = LoggingLevelSchema.safeParse(level);
274
+ if (parseResult.success) this._loggingLevels.set(transportSessionId, parseResult.data);
275
+ return {};
276
+ });
277
+ }
278
+ /**
279
+ * Access experimental features.
280
+ *
281
+ * WARNING: These APIs are experimental and may change without notice.
282
+ *
283
+ * @experimental
284
+ */
285
+ get experimental() {
286
+ if (!this._experimental) this._experimental = { tasks: new ExperimentalServerTasks(this) };
287
+ return this._experimental;
288
+ }
289
+ /**
290
+ * Registers new capabilities. This can only be called before connecting to a transport.
291
+ *
292
+ * The new capabilities will be merged with any existing capabilities previously given (e.g., at initialization).
293
+ */
294
+ registerCapabilities(capabilities) {
295
+ if (this.transport) throw new Error("Cannot register capabilities after connecting to transport");
296
+ this._capabilities = mergeCapabilities(this._capabilities, capabilities);
297
+ }
298
+ /**
299
+ * Override request handler registration to enforce server-side validation for tools/call.
300
+ */
301
+ setRequestHandler(requestSchema, handler) {
302
+ const methodSchema = getObjectShape(requestSchema)?.method;
303
+ if (!methodSchema) throw new Error("Schema is missing a method literal");
304
+ let methodValue;
305
+ if (isZ4Schema(methodSchema)) {
306
+ const v4Schema = methodSchema;
307
+ methodValue = (v4Schema._zod?.def)?.value ?? v4Schema.value;
308
+ } else {
309
+ const v3Schema = methodSchema;
310
+ methodValue = v3Schema._def?.value ?? v3Schema.value;
311
+ }
312
+ if (typeof methodValue !== "string") throw new Error("Schema method literal must be a string");
313
+ if (methodValue === "tools/call") {
314
+ const wrappedHandler = async (request, extra) => {
315
+ const validatedRequest = safeParse(CallToolRequestSchema, request);
316
+ if (!validatedRequest.success) {
317
+ const errorMessage = validatedRequest.error instanceof Error ? validatedRequest.error.message : String(validatedRequest.error);
318
+ throw new McpError(ErrorCode.InvalidParams, `Invalid tools/call request: ${errorMessage}`);
319
+ }
320
+ const { params } = validatedRequest.data;
321
+ const result = await Promise.resolve(handler(request, extra));
322
+ if (params.task) {
323
+ const taskValidationResult = safeParse(CreateTaskResultSchema, result);
324
+ if (!taskValidationResult.success) {
325
+ const errorMessage = taskValidationResult.error instanceof Error ? taskValidationResult.error.message : String(taskValidationResult.error);
326
+ throw new McpError(ErrorCode.InvalidParams, `Invalid task creation result: ${errorMessage}`);
327
+ }
328
+ return taskValidationResult.data;
329
+ }
330
+ const validationResult = safeParse(CallToolResultSchema, result);
331
+ if (!validationResult.success) {
332
+ const errorMessage = validationResult.error instanceof Error ? validationResult.error.message : String(validationResult.error);
333
+ throw new McpError(ErrorCode.InvalidParams, `Invalid tools/call result: ${errorMessage}`);
334
+ }
335
+ return validationResult.data;
336
+ };
337
+ return super.setRequestHandler(requestSchema, wrappedHandler);
338
+ }
339
+ return super.setRequestHandler(requestSchema, handler);
340
+ }
341
+ assertCapabilityForMethod(method) {
342
+ switch (method) {
343
+ case "sampling/createMessage":
344
+ if (!this._clientCapabilities?.sampling) throw new Error(`Client does not support sampling (required for ${method})`);
345
+ break;
346
+ case "elicitation/create":
347
+ if (!this._clientCapabilities?.elicitation) throw new Error(`Client does not support elicitation (required for ${method})`);
348
+ break;
349
+ case "roots/list":
350
+ if (!this._clientCapabilities?.roots) throw new Error(`Client does not support listing roots (required for ${method})`);
351
+ break;
352
+ case "ping": break;
353
+ }
354
+ }
355
+ assertNotificationCapability(method) {
356
+ switch (method) {
357
+ case "notifications/message":
358
+ if (!this._capabilities.logging) throw new Error(`Server does not support logging (required for ${method})`);
359
+ break;
360
+ case "notifications/resources/updated":
361
+ case "notifications/resources/list_changed":
362
+ if (!this._capabilities.resources) throw new Error(`Server does not support notifying about resources (required for ${method})`);
363
+ break;
364
+ case "notifications/tools/list_changed":
365
+ if (!this._capabilities.tools) throw new Error(`Server does not support notifying of tool list changes (required for ${method})`);
366
+ break;
367
+ case "notifications/prompts/list_changed":
368
+ if (!this._capabilities.prompts) throw new Error(`Server does not support notifying of prompt list changes (required for ${method})`);
369
+ break;
370
+ case "notifications/elicitation/complete":
371
+ if (!this._clientCapabilities?.elicitation?.url) throw new Error(`Client does not support URL elicitation (required for ${method})`);
372
+ break;
373
+ case "notifications/cancelled": break;
374
+ case "notifications/progress": break;
375
+ }
376
+ }
377
+ assertRequestHandlerCapability(method) {
378
+ if (!this._capabilities) return;
379
+ switch (method) {
380
+ case "completion/complete":
381
+ if (!this._capabilities.completions) throw new Error(`Server does not support completions (required for ${method})`);
382
+ break;
383
+ case "logging/setLevel":
384
+ if (!this._capabilities.logging) throw new Error(`Server does not support logging (required for ${method})`);
385
+ break;
386
+ case "prompts/get":
387
+ case "prompts/list":
388
+ if (!this._capabilities.prompts) throw new Error(`Server does not support prompts (required for ${method})`);
389
+ break;
390
+ case "resources/list":
391
+ case "resources/templates/list":
392
+ case "resources/read":
393
+ if (!this._capabilities.resources) throw new Error(`Server does not support resources (required for ${method})`);
394
+ break;
395
+ case "tools/call":
396
+ case "tools/list":
397
+ if (!this._capabilities.tools) throw new Error(`Server does not support tools (required for ${method})`);
398
+ break;
399
+ case "tasks/get":
400
+ case "tasks/list":
401
+ case "tasks/result":
402
+ case "tasks/cancel":
403
+ if (!this._capabilities.tasks) throw new Error(`Server does not support tasks capability (required for ${method})`);
404
+ break;
405
+ case "ping":
406
+ case "initialize": break;
407
+ }
408
+ }
409
+ assertTaskCapability(method) {
410
+ assertClientRequestTaskCapability(this._clientCapabilities?.tasks?.requests, method, "Client");
411
+ }
412
+ assertTaskHandlerCapability(method) {
413
+ if (!this._capabilities) return;
414
+ assertToolsCallTaskCapability(this._capabilities.tasks?.requests, method, "Server");
415
+ }
416
+ async _oninitialize(request) {
417
+ const requestedVersion = request.params.protocolVersion;
418
+ this._clientCapabilities = request.params.capabilities;
419
+ this._clientVersion = request.params.clientInfo;
420
+ return {
421
+ protocolVersion: SUPPORTED_PROTOCOL_VERSIONS.includes(requestedVersion) ? requestedVersion : LATEST_PROTOCOL_VERSION,
422
+ capabilities: this.getCapabilities(),
423
+ serverInfo: this._serverInfo,
424
+ ...this._instructions && { instructions: this._instructions }
425
+ };
426
+ }
427
+ /**
428
+ * After initialization has completed, this will be populated with the client's reported capabilities.
429
+ */
430
+ getClientCapabilities() {
431
+ return this._clientCapabilities;
432
+ }
433
+ /**
434
+ * After initialization has completed, this will be populated with information about the client's name and version.
435
+ */
436
+ getClientVersion() {
437
+ return this._clientVersion;
438
+ }
439
+ getCapabilities() {
440
+ return this._capabilities;
441
+ }
442
+ async ping() {
443
+ return this.request({ method: "ping" }, EmptyResultSchema);
444
+ }
445
+ async createMessage(params, options) {
446
+ if (params.tools || params.toolChoice) {
447
+ if (!this._clientCapabilities?.sampling?.tools) throw new Error("Client does not support sampling tools capability.");
448
+ }
449
+ if (params.messages.length > 0) {
450
+ const lastMessage = params.messages[params.messages.length - 1];
451
+ const lastContent = Array.isArray(lastMessage.content) ? lastMessage.content : [lastMessage.content];
452
+ const hasToolResults = lastContent.some((c) => c.type === "tool_result");
453
+ const previousMessage = params.messages.length > 1 ? params.messages[params.messages.length - 2] : void 0;
454
+ const previousContent = previousMessage ? Array.isArray(previousMessage.content) ? previousMessage.content : [previousMessage.content] : [];
455
+ const hasPreviousToolUse = previousContent.some((c) => c.type === "tool_use");
456
+ if (hasToolResults) {
457
+ if (lastContent.some((c) => c.type !== "tool_result")) throw new Error("The last message must contain only tool_result content if any is present");
458
+ if (!hasPreviousToolUse) throw new Error("tool_result blocks are not matching any tool_use from the previous message");
459
+ }
460
+ if (hasPreviousToolUse) {
461
+ const toolUseIds = new Set(previousContent.filter((c) => c.type === "tool_use").map((c) => c.id));
462
+ const toolResultIds = new Set(lastContent.filter((c) => c.type === "tool_result").map((c) => c.toolUseId));
463
+ if (toolUseIds.size !== toolResultIds.size || ![...toolUseIds].every((id) => toolResultIds.has(id))) throw new Error("ids of tool_result blocks and tool_use blocks from previous message do not match");
464
+ }
465
+ }
466
+ if (params.tools) return this.request({
467
+ method: "sampling/createMessage",
468
+ params
469
+ }, CreateMessageResultWithToolsSchema, options);
470
+ return this.request({
471
+ method: "sampling/createMessage",
472
+ params
473
+ }, CreateMessageResultSchema, options);
474
+ }
475
+ /**
476
+ * Creates an elicitation request for the given parameters.
477
+ * For backwards compatibility, `mode` may be omitted for form requests and will default to `'form'`.
478
+ * @param params The parameters for the elicitation request.
479
+ * @param options Optional request options.
480
+ * @returns The result of the elicitation request.
481
+ */
482
+ async elicitInput(params, options) {
483
+ switch (params.mode ?? "form") {
484
+ case "url": {
485
+ if (!this._clientCapabilities?.elicitation?.url) throw new Error("Client does not support url elicitation.");
486
+ const urlParams = params;
487
+ return this.request({
488
+ method: "elicitation/create",
489
+ params: urlParams
490
+ }, ElicitResultSchema, options);
491
+ }
492
+ case "form": {
493
+ if (!this._clientCapabilities?.elicitation?.form) throw new Error("Client does not support form elicitation.");
494
+ const formParams = params.mode === "form" ? params : {
495
+ ...params,
496
+ mode: "form"
497
+ };
498
+ const result = await this.request({
499
+ method: "elicitation/create",
500
+ params: formParams
501
+ }, ElicitResultSchema, options);
502
+ if (result.action === "accept" && result.content && formParams.requestedSchema) try {
503
+ const validationResult = this._jsonSchemaValidator.getValidator(formParams.requestedSchema)(result.content);
504
+ if (!validationResult.valid) throw new McpError(ErrorCode.InvalidParams, `Elicitation response content does not match requested schema: ${validationResult.errorMessage}`);
505
+ } catch (error) {
506
+ if (error instanceof McpError) throw error;
507
+ throw new McpError(ErrorCode.InternalError, `Error validating elicitation response: ${error instanceof Error ? error.message : String(error)}`);
508
+ }
509
+ return result;
510
+ }
511
+ }
512
+ }
513
+ /**
514
+ * Creates a reusable callback that, when invoked, will send a `notifications/elicitation/complete`
515
+ * notification for the specified elicitation ID.
516
+ *
517
+ * @param elicitationId The ID of the elicitation to mark as complete.
518
+ * @param options Optional notification options. Useful when the completion notification should be related to a prior request.
519
+ * @returns A function that emits the completion notification when awaited.
520
+ */
521
+ createElicitationCompletionNotifier(elicitationId, options) {
522
+ if (!this._clientCapabilities?.elicitation?.url) throw new Error("Client does not support URL elicitation (required for notifications/elicitation/complete)");
523
+ return () => this.notification({
524
+ method: "notifications/elicitation/complete",
525
+ params: { elicitationId }
526
+ }, options);
527
+ }
528
+ async listRoots(params, options) {
529
+ return this.request({
530
+ method: "roots/list",
531
+ params
532
+ }, ListRootsResultSchema, options);
533
+ }
534
+ /**
535
+ * Sends a logging message to the client, if connected.
536
+ * Note: You only need to send the parameters object, not the entire JSON RPC message
537
+ * @see LoggingMessageNotification
538
+ * @param params
539
+ * @param sessionId optional for stateless and backward compatibility
540
+ */
541
+ async sendLoggingMessage(params, sessionId) {
542
+ if (this._capabilities.logging) {
543
+ if (!this.isMessageIgnored(params.level, sessionId)) return this.notification({
544
+ method: "notifications/message",
545
+ params
546
+ });
547
+ }
548
+ }
549
+ async sendResourceUpdated(params) {
550
+ return this.notification({
551
+ method: "notifications/resources/updated",
552
+ params
553
+ });
554
+ }
555
+ async sendResourceListChanged() {
556
+ return this.notification({ method: "notifications/resources/list_changed" });
557
+ }
558
+ async sendToolListChanged() {
559
+ return this.notification({ method: "notifications/tools/list_changed" });
560
+ }
561
+ async sendPromptListChanged() {
562
+ return this.notification({ method: "notifications/prompts/list_changed" });
563
+ }
564
+ };
565
+ //#endregion
566
+ //#region ../../node_modules/.pnpm/@modelcontextprotocol+sdk@1.29.0_zod@4.4.3/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js
567
+ /**
568
+ * Server transport for stdio: this communicates with an MCP client by reading from the current process' stdin and writing to stdout.
569
+ *
570
+ * This transport is only available in Node.js environments.
571
+ */
572
+ var StdioServerTransport = class {
573
+ constructor(_stdin = process$1.stdin, _stdout = process$1.stdout) {
574
+ this._stdin = _stdin;
575
+ this._stdout = _stdout;
576
+ this._readBuffer = new ReadBuffer();
577
+ this._started = false;
578
+ this._ondata = (chunk) => {
579
+ this._readBuffer.append(chunk);
580
+ this.processReadBuffer();
581
+ };
582
+ this._onerror = (error) => {
583
+ this.onerror?.(error);
584
+ };
585
+ }
586
+ /**
587
+ * Starts listening for messages on stdin.
588
+ */
589
+ async start() {
590
+ if (this._started) throw new Error("StdioServerTransport already started! If using Server class, note that connect() calls start() automatically.");
591
+ this._started = true;
592
+ this._stdin.on("data", this._ondata);
593
+ this._stdin.on("error", this._onerror);
594
+ }
595
+ processReadBuffer() {
596
+ while (true) try {
597
+ const message = this._readBuffer.readMessage();
598
+ if (message === null) break;
599
+ this.onmessage?.(message);
600
+ } catch (error) {
601
+ this.onerror?.(error);
602
+ }
603
+ }
604
+ async close() {
605
+ this._stdin.off("data", this._ondata);
606
+ this._stdin.off("error", this._onerror);
607
+ if (this._stdin.listenerCount("data") === 0) this._stdin.pause();
608
+ this._readBuffer.clear();
609
+ this.onclose?.();
610
+ }
611
+ send(message) {
612
+ return new Promise((resolve) => {
613
+ const json = serializeMessage(message);
614
+ if (this._stdout.write(json)) resolve();
615
+ else this._stdout.once("drain", resolve);
616
+ });
617
+ }
618
+ };
619
+ //#endregion
620
+ //#region src/mcp/bridge.ts
621
+ /**
622
+ * IPC client half of the bridge: a persistent UDS connection to the daemon's
623
+ * control server. Requests are correlated by an incrementing id; an `ok:false`
624
+ * response rejects with the daemon's error message.
625
+ */
626
+ var IpcClient = class {
627
+ token;
628
+ socket;
629
+ nextId = 1;
630
+ pending = /* @__PURE__ */ new Map();
631
+ buf = "";
632
+ ready;
633
+ constructor(endpoint, token) {
634
+ this.token = token;
635
+ this.socket = net.connect(endpoint);
636
+ this.socket.setEncoding("utf8");
637
+ this.ready = new Promise((resolve, reject) => {
638
+ this.socket.once("connect", resolve);
639
+ this.socket.once("error", reject);
640
+ });
641
+ this.socket.on("data", (chunk) => {
642
+ this.buf += chunk;
643
+ const { messages, rest } = decodeFrames(this.buf);
644
+ this.buf = rest;
645
+ for (const res of messages) {
646
+ const p = this.pending.get(res.id);
647
+ if (!p) continue;
648
+ this.pending.delete(res.id);
649
+ if (res.ok) p.resolve(res.result);
650
+ else p.reject(new Error(res.error ?? "tool call failed"));
651
+ }
652
+ });
653
+ this.socket.on("close", () => {
654
+ for (const p of this.pending.values()) p.reject(/* @__PURE__ */ new Error("daemon connection closed"));
655
+ this.pending.clear();
656
+ });
657
+ }
658
+ async request(call) {
659
+ await this.ready;
660
+ const id = this.nextId++;
661
+ return new Promise((resolve, reject) => {
662
+ this.pending.set(id, {
663
+ resolve,
664
+ reject
665
+ });
666
+ this.socket.write(encodeFrame({
667
+ id,
668
+ token: this.token,
669
+ ...call
670
+ }));
671
+ });
672
+ }
673
+ };
674
+ /**
675
+ * Entry point for `agentconnect mcp-bridge`: a stdio MCP server that relays
676
+ * `tools/list` and `tools/call` to the running daemon over its control socket.
677
+ * The agent harness spawns this per session; the daemon does the real work.
678
+ */
679
+ async function runBridge() {
680
+ const endpoint = process.env.AC_MCP_ENDPOINT;
681
+ const token = process.env.AC_MCP_TOKEN;
682
+ if (!endpoint || !token) {
683
+ process.stderr.write("mcp-bridge: AC_MCP_ENDPOINT and AC_MCP_TOKEN must be set\n");
684
+ process.exit(2);
685
+ }
686
+ const ipc = new IpcClient(endpoint, token);
687
+ let tools;
688
+ try {
689
+ tools = (await ipc.request({ op: "listTools" })).tools;
690
+ } catch (err) {
691
+ process.stderr.write(`mcp-bridge: could not reach daemon: ${err.message}\n`);
692
+ process.exit(1);
693
+ }
694
+ const server = new Server({
695
+ name: "agentconnect",
696
+ version: DAEMON_VERSION
697
+ }, { capabilities: { tools: {} } });
698
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools }));
699
+ server.setRequestHandler(CallToolRequestSchema, async (req) => {
700
+ try {
701
+ const result = await ipc.request({
702
+ op: "callTool",
703
+ name: req.params.name,
704
+ args: req.params.arguments ?? {}
705
+ });
706
+ if (result && typeof result === "object" && Array.isArray(result.mcpContent)) return { content: result.mcpContent };
707
+ return { content: [{
708
+ type: "text",
709
+ text: typeof result === "string" ? result : JSON.stringify(result, null, 2)
710
+ }] };
711
+ } catch (err) {
712
+ return {
713
+ content: [{
714
+ type: "text",
715
+ text: err.message
716
+ }],
717
+ isError: true
718
+ };
719
+ }
720
+ });
721
+ await server.connect(new StdioServerTransport());
722
+ }
723
+ //#endregion
724
+ export { runBridge };
725
+
726
+ //# sourceMappingURL=bridge-DXIVgEzf.js.map