@dexto/server 1.6.18 → 1.6.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hono/index.d.ts +170 -142
- package/dist/hono/index.d.ts.map +1 -1
- package/dist/hono/routes/a2a-tasks.cjs +17 -4
- package/dist/hono/routes/a2a-tasks.d.ts +39 -35
- package/dist/hono/routes/a2a-tasks.d.ts.map +1 -1
- package/dist/hono/routes/a2a-tasks.js +17 -4
- package/dist/hono/routes/agents.d.ts +8 -8
- package/dist/hono/routes/approvals.cjs +19 -8
- package/dist/hono/routes/approvals.d.ts +49 -18
- package/dist/hono/routes/approvals.d.ts.map +1 -1
- package/dist/hono/routes/approvals.js +19 -8
- package/dist/hono/routes/llm.d.ts +1 -1
- package/dist/hono/routes/mcp.cjs +56 -26
- package/dist/hono/routes/mcp.d.ts +22 -29
- package/dist/hono/routes/mcp.d.ts.map +1 -1
- package/dist/hono/routes/mcp.js +64 -28
- package/dist/hono/routes/messages.cjs +34 -35
- package/dist/hono/routes/messages.d.ts +12 -12
- package/dist/hono/routes/messages.d.ts.map +1 -1
- package/dist/hono/routes/messages.js +41 -36
- package/dist/hono/routes/prompts.cjs +10 -4
- package/dist/hono/routes/prompts.d.ts +4 -4
- package/dist/hono/routes/prompts.d.ts.map +1 -1
- package/dist/hono/routes/prompts.js +15 -5
- package/dist/hono/routes/queue.cjs +42 -29
- package/dist/hono/routes/queue.d.ts +9 -9
- package/dist/hono/routes/queue.d.ts.map +1 -1
- package/dist/hono/routes/queue.js +49 -30
- package/dist/hono/routes/resources.d.ts +1 -1
- package/dist/hono/routes/schedules.d.ts +4 -4
- package/dist/hono/routes/search.d.ts +4 -4
- package/dist/hono/routes/sessions.cjs +7 -2
- package/dist/hono/routes/sessions.d.ts +12 -12
- package/dist/hono/routes/sessions.d.ts.map +1 -1
- package/dist/hono/routes/sessions.js +7 -2
- package/dist/hono/routes/tools.d.ts +1 -1
- package/dist/hono/routes/webhooks.cjs +59 -24
- package/dist/hono/routes/webhooks.d.ts +7 -7
- package/dist/hono/routes/webhooks.d.ts.map +1 -1
- package/dist/hono/routes/webhooks.js +59 -24
- package/dist/hono/schemas/responses.cjs +112 -2
- package/dist/hono/schemas/responses.d.ts +246 -54
- package/dist/hono/schemas/responses.d.ts.map +1 -1
- package/dist/hono/schemas/responses.js +105 -1
- package/package.json +11 -11
|
@@ -40,8 +40,8 @@ export declare function createLlmRouter(getAgent: GetAgentFn): OpenAPIHono<impor
|
|
|
40
40
|
$get: {
|
|
41
41
|
input: {
|
|
42
42
|
query: {
|
|
43
|
-
provider?: string | string[] | undefined;
|
|
44
43
|
scope?: "curated" | "all" | undefined;
|
|
44
|
+
provider?: string | string[] | undefined;
|
|
45
45
|
includeModels?: "0" | "1" | "true" | "false" | undefined;
|
|
46
46
|
hasKey?: "0" | "1" | "true" | "false" | undefined;
|
|
47
47
|
fileType?: "image" | "audio" | "pdf" | undefined;
|
package/dist/hono/routes/mcp.cjs
CHANGED
|
@@ -87,9 +87,15 @@ const ServerConfigResponseSchema = import_zod_openapi.z.object({
|
|
|
87
87
|
name: import_zod_openapi.z.string().describe("Server name"),
|
|
88
88
|
config: import_core.McpServerConfigSchema.describe("Server configuration")
|
|
89
89
|
}).strict().describe("MCP server configuration response");
|
|
90
|
+
const ServerResourceSchema = import_zod_openapi.z.object({
|
|
91
|
+
uri: import_zod_openapi.z.string().describe("Resolved resource URI for this server"),
|
|
92
|
+
name: import_zod_openapi.z.string().describe("Resource display name"),
|
|
93
|
+
originalUri: import_zod_openapi.z.string().describe("Original MCP resource URI"),
|
|
94
|
+
serverName: import_zod_openapi.z.string().describe("Owning MCP server name")
|
|
95
|
+
}).strict().describe("Resource exposed by a specific MCP server");
|
|
90
96
|
const ResourcesListResponseSchema = import_zod_openapi.z.object({
|
|
91
97
|
success: import_zod_openapi.z.boolean().describe("Success indicator"),
|
|
92
|
-
resources: import_zod_openapi.z.array(
|
|
98
|
+
resources: import_zod_openapi.z.array(ServerResourceSchema).describe("Array of available resources")
|
|
93
99
|
}).strict().describe("List of resources from MCP server");
|
|
94
100
|
const ResourceContentSchema = import_zod_openapi.z.object({
|
|
95
101
|
content: import_zod_openapi.z.any().describe("Resource content data")
|
|
@@ -141,7 +147,10 @@ function createMcpRouter(getAgent, getAgentConfigPath) {
|
|
|
141
147
|
description: "Server configuration",
|
|
142
148
|
content: { "application/json": { schema: ServerConfigResponseSchema } }
|
|
143
149
|
},
|
|
144
|
-
404: {
|
|
150
|
+
404: {
|
|
151
|
+
description: "Not found",
|
|
152
|
+
content: { "application/json": { schema: import_responses.ApiErrorResponseSchema } }
|
|
153
|
+
}
|
|
145
154
|
}
|
|
146
155
|
});
|
|
147
156
|
const updateServerRoute = (0, import_zod_openapi.createRoute)({
|
|
@@ -159,7 +168,10 @@ function createMcpRouter(getAgent, getAgentConfigPath) {
|
|
|
159
168
|
description: "Server updated",
|
|
160
169
|
content: { "application/json": { schema: ServerStatusResponseSchema } }
|
|
161
170
|
},
|
|
162
|
-
404: {
|
|
171
|
+
404: {
|
|
172
|
+
description: "Not found",
|
|
173
|
+
content: { "application/json": { schema: import_responses.ApiErrorResponseSchema } }
|
|
174
|
+
}
|
|
163
175
|
}
|
|
164
176
|
});
|
|
165
177
|
const toolsRoute = (0, import_zod_openapi.createRoute)({
|
|
@@ -176,7 +188,10 @@ function createMcpRouter(getAgent, getAgentConfigPath) {
|
|
|
176
188
|
description: "Tools list",
|
|
177
189
|
content: { "application/json": { schema: ToolsListResponseSchema } }
|
|
178
190
|
},
|
|
179
|
-
404: {
|
|
191
|
+
404: {
|
|
192
|
+
description: "Not found",
|
|
193
|
+
content: { "application/json": { schema: import_responses.ApiErrorResponseSchema } }
|
|
194
|
+
}
|
|
180
195
|
}
|
|
181
196
|
});
|
|
182
197
|
const deleteServerRoute = (0, import_zod_openapi.createRoute)({
|
|
@@ -193,7 +208,10 @@ function createMcpRouter(getAgent, getAgentConfigPath) {
|
|
|
193
208
|
description: "Disconnected",
|
|
194
209
|
content: { "application/json": { schema: DisconnectResponseSchema } }
|
|
195
210
|
},
|
|
196
|
-
404: {
|
|
211
|
+
404: {
|
|
212
|
+
description: "Not found",
|
|
213
|
+
content: { "application/json": { schema: import_responses.ApiErrorResponseSchema } }
|
|
214
|
+
}
|
|
197
215
|
}
|
|
198
216
|
});
|
|
199
217
|
const restartServerRoute = (0, import_zod_openapi.createRoute)({
|
|
@@ -210,7 +228,10 @@ function createMcpRouter(getAgent, getAgentConfigPath) {
|
|
|
210
228
|
description: "Server restarted",
|
|
211
229
|
content: { "application/json": { schema: RestartResponseSchema } }
|
|
212
230
|
},
|
|
213
|
-
404: {
|
|
231
|
+
404: {
|
|
232
|
+
description: "Not found",
|
|
233
|
+
content: { "application/json": { schema: import_responses.ApiErrorResponseSchema } }
|
|
234
|
+
}
|
|
214
235
|
}
|
|
215
236
|
});
|
|
216
237
|
const execToolRoute = (0, import_zod_openapi.createRoute)({
|
|
@@ -231,7 +252,10 @@ function createMcpRouter(getAgent, getAgentConfigPath) {
|
|
|
231
252
|
description: "Tool executed",
|
|
232
253
|
content: { "application/json": { schema: ToolExecutionResponseSchema } }
|
|
233
254
|
},
|
|
234
|
-
404: {
|
|
255
|
+
404: {
|
|
256
|
+
description: "Not found",
|
|
257
|
+
content: { "application/json": { schema: import_responses.ApiErrorResponseSchema } }
|
|
258
|
+
}
|
|
235
259
|
}
|
|
236
260
|
});
|
|
237
261
|
const listResourcesRoute = (0, import_zod_openapi.createRoute)({
|
|
@@ -248,7 +272,10 @@ function createMcpRouter(getAgent, getAgentConfigPath) {
|
|
|
248
272
|
description: "Server resources",
|
|
249
273
|
content: { "application/json": { schema: ResourcesListResponseSchema } }
|
|
250
274
|
},
|
|
251
|
-
404: {
|
|
275
|
+
404: {
|
|
276
|
+
description: "Not found",
|
|
277
|
+
content: { "application/json": { schema: import_responses.ApiErrorResponseSchema } }
|
|
278
|
+
}
|
|
252
279
|
}
|
|
253
280
|
});
|
|
254
281
|
const getResourceContentRoute = (0, import_zod_openapi.createRoute)({
|
|
@@ -268,7 +295,10 @@ function createMcpRouter(getAgent, getAgentConfigPath) {
|
|
|
268
295
|
description: "Resource content",
|
|
269
296
|
content: { "application/json": { schema: ResourceContentResponseSchema } }
|
|
270
297
|
},
|
|
271
|
-
404: {
|
|
298
|
+
404: {
|
|
299
|
+
description: "Not found",
|
|
300
|
+
content: { "application/json": { schema: import_responses.ApiErrorResponseSchema } }
|
|
301
|
+
}
|
|
272
302
|
}
|
|
273
303
|
});
|
|
274
304
|
return app.openapi(addServerRoute, async (ctx) => {
|
|
@@ -317,22 +347,22 @@ function createMcpRouter(getAgent, getAgentConfigPath) {
|
|
|
317
347
|
for (const name of Object.keys(failedConnections)) {
|
|
318
348
|
servers.push({ id: name, name, status: "error" });
|
|
319
349
|
}
|
|
320
|
-
return ctx.json({ servers });
|
|
350
|
+
return ctx.json({ servers }, 200);
|
|
321
351
|
}).openapi(getServerConfigRoute, async (ctx) => {
|
|
322
352
|
const agent = await getAgent(ctx);
|
|
323
353
|
const { serverId } = ctx.req.valid("param");
|
|
324
354
|
const config = agent.getMcpServerConfig(serverId);
|
|
325
355
|
if (!config) {
|
|
326
|
-
|
|
356
|
+
throw import_core.MCPError.serverNotFound(serverId);
|
|
327
357
|
}
|
|
328
|
-
return ctx.json({ name: serverId, config }, 200);
|
|
358
|
+
return ctx.json({ name: serverId, config: import_core.McpServerConfigSchema.parse(config) }, 200);
|
|
329
359
|
}).openapi(updateServerRoute, async (ctx) => {
|
|
330
360
|
const agent = await getAgent(ctx);
|
|
331
361
|
const { serverId } = ctx.req.valid("param");
|
|
332
362
|
const { config, persistToAgent } = ctx.req.valid("json");
|
|
333
363
|
const existingConfig = agent.getMcpServerConfig(serverId);
|
|
334
364
|
if (!existingConfig) {
|
|
335
|
-
|
|
365
|
+
throw import_core.MCPError.serverNotFound(serverId);
|
|
336
366
|
}
|
|
337
367
|
await agent.updateMcpServer(serverId, config);
|
|
338
368
|
if (persistToAgent === true) {
|
|
@@ -365,26 +395,26 @@ function createMcpRouter(getAgent, getAgentConfigPath) {
|
|
|
365
395
|
const { serverId } = ctx.req.valid("param");
|
|
366
396
|
const client = agent.getMcpClients().get(serverId);
|
|
367
397
|
if (!client) {
|
|
368
|
-
|
|
398
|
+
throw import_core.MCPError.serverNotFound(serverId);
|
|
369
399
|
}
|
|
370
400
|
const toolsMap = await client.getTools();
|
|
371
401
|
const tools = Object.entries(toolsMap).map(([toolName, toolDef]) => ({
|
|
372
402
|
id: toolName,
|
|
373
403
|
name: toolName,
|
|
374
404
|
description: toolDef.description || "",
|
|
375
|
-
inputSchema: toolDef.parameters,
|
|
405
|
+
inputSchema: toolDef.parameters === void 0 ? void 0 : ToolInputSchema.parse(toolDef.parameters),
|
|
376
406
|
_meta: toolDef._meta
|
|
377
407
|
}));
|
|
378
|
-
return ctx.json({ tools });
|
|
408
|
+
return ctx.json({ tools }, 200);
|
|
379
409
|
}).openapi(deleteServerRoute, async (ctx) => {
|
|
380
410
|
const agent = await getAgent(ctx);
|
|
381
411
|
const { serverId } = ctx.req.valid("param");
|
|
382
412
|
const clientExists = agent.getMcpClients().has(serverId) || agent.getMcpFailedConnections()[serverId];
|
|
383
413
|
if (!clientExists) {
|
|
384
|
-
|
|
414
|
+
throw import_core.MCPError.serverNotFound(serverId);
|
|
385
415
|
}
|
|
386
416
|
await agent.removeMcpServer(serverId);
|
|
387
|
-
return ctx.json({ status: "disconnected", id: serverId });
|
|
417
|
+
return ctx.json({ status: "disconnected", id: serverId }, 200);
|
|
388
418
|
}).openapi(restartServerRoute, async (ctx) => {
|
|
389
419
|
const agent = await getAgent(ctx);
|
|
390
420
|
const { serverId } = ctx.req.valid("param");
|
|
@@ -392,21 +422,21 @@ function createMcpRouter(getAgent, getAgentConfigPath) {
|
|
|
392
422
|
const clientExists = agent.getMcpClients().has(serverId);
|
|
393
423
|
if (!clientExists) {
|
|
394
424
|
import_core.logger.warn(`Attempted to restart non-existent server: ${serverId}`);
|
|
395
|
-
|
|
425
|
+
throw import_core.MCPError.serverNotFound(serverId);
|
|
396
426
|
}
|
|
397
427
|
await agent.restartMcpServer(serverId);
|
|
398
|
-
return ctx.json({ status: "restarted", id: serverId });
|
|
428
|
+
return ctx.json({ status: "restarted", id: serverId }, 200);
|
|
399
429
|
}).openapi(execToolRoute, async (ctx) => {
|
|
400
430
|
const agent = await getAgent(ctx);
|
|
401
431
|
const { serverId, toolName } = ctx.req.valid("param");
|
|
402
432
|
const body = ctx.req.valid("json");
|
|
403
433
|
const client = agent.getMcpClients().get(serverId);
|
|
404
434
|
if (!client) {
|
|
405
|
-
|
|
435
|
+
throw import_core.MCPError.serverNotFound(serverId);
|
|
406
436
|
}
|
|
407
437
|
try {
|
|
408
438
|
const rawResult = await client.callTool(toolName, body);
|
|
409
|
-
return ctx.json({ success: true, data: rawResult });
|
|
439
|
+
return ctx.json({ success: true, data: rawResult }, 200);
|
|
410
440
|
} catch (error) {
|
|
411
441
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
412
442
|
import_core.logger.error(
|
|
@@ -420,20 +450,20 @@ function createMcpRouter(getAgent, getAgentConfigPath) {
|
|
|
420
450
|
const { serverId } = ctx.req.valid("param");
|
|
421
451
|
const client = agent.getMcpClients().get(serverId);
|
|
422
452
|
if (!client) {
|
|
423
|
-
|
|
453
|
+
throw import_core.MCPError.serverNotFound(serverId);
|
|
424
454
|
}
|
|
425
455
|
const resources = await agent.listResourcesForServer(serverId);
|
|
426
|
-
return ctx.json({ success: true, resources });
|
|
456
|
+
return ctx.json({ success: true, resources }, 200);
|
|
427
457
|
}).openapi(getResourceContentRoute, async (ctx) => {
|
|
428
458
|
const agent = await getAgent(ctx);
|
|
429
459
|
const { serverId, resourceId } = ctx.req.valid("param");
|
|
430
460
|
const client = agent.getMcpClients().get(serverId);
|
|
431
461
|
if (!client) {
|
|
432
|
-
|
|
462
|
+
throw import_core.MCPError.serverNotFound(serverId);
|
|
433
463
|
}
|
|
434
464
|
const qualifiedUri = `mcp:${serverId}:${resourceId}`;
|
|
435
465
|
const content = await agent.readResource(qualifiedUri);
|
|
436
|
-
return ctx.json({ success: true, data: { content } });
|
|
466
|
+
return ctx.json({ success: true, data: { content } }, 200);
|
|
437
467
|
});
|
|
438
468
|
}
|
|
439
469
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -47,8 +47,8 @@ export declare function createMcpRouter(getAgent: GetAgentFn, getAgentConfigPath
|
|
|
47
47
|
output: {
|
|
48
48
|
servers: {
|
|
49
49
|
status: "error" | "connected" | "disconnected" | "auth-required";
|
|
50
|
-
id: string;
|
|
51
50
|
name: string;
|
|
51
|
+
id: string;
|
|
52
52
|
}[];
|
|
53
53
|
};
|
|
54
54
|
outputFormat: "json";
|
|
@@ -63,8 +63,8 @@ export declare function createMcpRouter(getAgent: GetAgentFn, getAgentConfigPath
|
|
|
63
63
|
serverId: string;
|
|
64
64
|
};
|
|
65
65
|
};
|
|
66
|
-
output:
|
|
67
|
-
outputFormat:
|
|
66
|
+
output: never;
|
|
67
|
+
outputFormat: "json";
|
|
68
68
|
status: 404;
|
|
69
69
|
} | {
|
|
70
70
|
input: {
|
|
@@ -143,8 +143,8 @@ export declare function createMcpRouter(getAgent: GetAgentFn, getAgentConfigPath
|
|
|
143
143
|
persistToAgent?: boolean | undefined;
|
|
144
144
|
};
|
|
145
145
|
};
|
|
146
|
-
output:
|
|
147
|
-
outputFormat:
|
|
146
|
+
output: never;
|
|
147
|
+
outputFormat: "json";
|
|
148
148
|
status: 404;
|
|
149
149
|
} | {
|
|
150
150
|
input: {
|
|
@@ -195,8 +195,8 @@ export declare function createMcpRouter(getAgent: GetAgentFn, getAgentConfigPath
|
|
|
195
195
|
serverId: string;
|
|
196
196
|
};
|
|
197
197
|
};
|
|
198
|
-
output:
|
|
199
|
-
outputFormat:
|
|
198
|
+
output: never;
|
|
199
|
+
outputFormat: "json";
|
|
200
200
|
status: 404;
|
|
201
201
|
} | {
|
|
202
202
|
input: {
|
|
@@ -207,8 +207,8 @@ export declare function createMcpRouter(getAgent: GetAgentFn, getAgentConfigPath
|
|
|
207
207
|
output: {
|
|
208
208
|
tools: {
|
|
209
209
|
description: string;
|
|
210
|
-
id: string;
|
|
211
210
|
name: string;
|
|
211
|
+
id: string;
|
|
212
212
|
inputSchema?: {
|
|
213
213
|
[x: string]: import("hono/utils/types").JSONValue;
|
|
214
214
|
type?: "object" | undefined;
|
|
@@ -240,8 +240,8 @@ export declare function createMcpRouter(getAgent: GetAgentFn, getAgentConfigPath
|
|
|
240
240
|
serverId: string;
|
|
241
241
|
};
|
|
242
242
|
};
|
|
243
|
-
output:
|
|
244
|
-
outputFormat:
|
|
243
|
+
output: never;
|
|
244
|
+
outputFormat: "json";
|
|
245
245
|
status: 404;
|
|
246
246
|
} | {
|
|
247
247
|
input: {
|
|
@@ -265,8 +265,8 @@ export declare function createMcpRouter(getAgent: GetAgentFn, getAgentConfigPath
|
|
|
265
265
|
serverId: string;
|
|
266
266
|
};
|
|
267
267
|
};
|
|
268
|
-
output:
|
|
269
|
-
outputFormat:
|
|
268
|
+
output: never;
|
|
269
|
+
outputFormat: "json";
|
|
270
270
|
status: 404;
|
|
271
271
|
} | {
|
|
272
272
|
input: {
|
|
@@ -293,8 +293,8 @@ export declare function createMcpRouter(getAgent: GetAgentFn, getAgentConfigPath
|
|
|
293
293
|
} & {
|
|
294
294
|
json: Record<string, unknown>;
|
|
295
295
|
};
|
|
296
|
-
output:
|
|
297
|
-
outputFormat:
|
|
296
|
+
output: never;
|
|
297
|
+
outputFormat: "json";
|
|
298
298
|
status: 404;
|
|
299
299
|
} | {
|
|
300
300
|
input: {
|
|
@@ -307,8 +307,8 @@ export declare function createMcpRouter(getAgent: GetAgentFn, getAgentConfigPath
|
|
|
307
307
|
};
|
|
308
308
|
output: {
|
|
309
309
|
success: boolean;
|
|
310
|
-
data?: any;
|
|
311
310
|
error?: string | undefined;
|
|
311
|
+
data?: any;
|
|
312
312
|
};
|
|
313
313
|
outputFormat: "json";
|
|
314
314
|
status: 200;
|
|
@@ -322,8 +322,8 @@ export declare function createMcpRouter(getAgent: GetAgentFn, getAgentConfigPath
|
|
|
322
322
|
serverId: string;
|
|
323
323
|
};
|
|
324
324
|
};
|
|
325
|
-
output:
|
|
326
|
-
outputFormat:
|
|
325
|
+
output: never;
|
|
326
|
+
outputFormat: "json";
|
|
327
327
|
status: 404;
|
|
328
328
|
} | {
|
|
329
329
|
input: {
|
|
@@ -333,17 +333,10 @@ export declare function createMcpRouter(getAgent: GetAgentFn, getAgentConfigPath
|
|
|
333
333
|
};
|
|
334
334
|
output: {
|
|
335
335
|
resources: {
|
|
336
|
+
name: string;
|
|
336
337
|
uri: string;
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
mimeType?: string | undefined;
|
|
340
|
-
metadata?: {
|
|
341
|
-
[x: string]: import("hono/utils/types").JSONValue;
|
|
342
|
-
} | undefined;
|
|
343
|
-
name?: string | undefined;
|
|
344
|
-
serverName?: string | undefined;
|
|
345
|
-
size?: number | undefined;
|
|
346
|
-
lastModified?: string | undefined;
|
|
338
|
+
serverName: string;
|
|
339
|
+
originalUri: string;
|
|
347
340
|
}[];
|
|
348
341
|
success: boolean;
|
|
349
342
|
};
|
|
@@ -360,8 +353,8 @@ export declare function createMcpRouter(getAgent: GetAgentFn, getAgentConfigPath
|
|
|
360
353
|
resourceId: string;
|
|
361
354
|
};
|
|
362
355
|
};
|
|
363
|
-
output:
|
|
364
|
-
outputFormat:
|
|
356
|
+
output: never;
|
|
357
|
+
outputFormat: "json";
|
|
365
358
|
status: 404;
|
|
366
359
|
} | {
|
|
367
360
|
input: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../../src/hono/routes/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAkB,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../../src/hono/routes/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAkB,MAAM,mBAAmB,CAAC;AAUhE,OAAO,KAAK,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAyKpE,wBAAgB,eAAe,CAAC,QAAQ,EAAE,UAAU,EAAE,kBAAkB,EAAE,oBAAoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;QAka7F"}
|
package/dist/hono/routes/mcp.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { OpenAPIHono, createRoute, z } from "@hono/zod-openapi";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
AgentError,
|
|
4
|
+
logger,
|
|
5
|
+
MCPError,
|
|
6
|
+
McpServerConfigSchema,
|
|
7
|
+
MCP_CONNECTION_STATUSES
|
|
8
|
+
} from "@dexto/core";
|
|
3
9
|
import { updateAgentConfigFile } from "@dexto/agent-management";
|
|
4
|
-
import {
|
|
10
|
+
import { ApiErrorResponseSchema } from "../schemas/responses.js";
|
|
5
11
|
const McpServerRequestSchema = z.object({
|
|
6
12
|
name: z.string().min(1, "Server name is required").describe("A unique name for the server"),
|
|
7
13
|
config: McpServerConfigSchema.describe("The server configuration object"),
|
|
@@ -64,9 +70,15 @@ const ServerConfigResponseSchema = z.object({
|
|
|
64
70
|
name: z.string().describe("Server name"),
|
|
65
71
|
config: McpServerConfigSchema.describe("Server configuration")
|
|
66
72
|
}).strict().describe("MCP server configuration response");
|
|
73
|
+
const ServerResourceSchema = z.object({
|
|
74
|
+
uri: z.string().describe("Resolved resource URI for this server"),
|
|
75
|
+
name: z.string().describe("Resource display name"),
|
|
76
|
+
originalUri: z.string().describe("Original MCP resource URI"),
|
|
77
|
+
serverName: z.string().describe("Owning MCP server name")
|
|
78
|
+
}).strict().describe("Resource exposed by a specific MCP server");
|
|
67
79
|
const ResourcesListResponseSchema = z.object({
|
|
68
80
|
success: z.boolean().describe("Success indicator"),
|
|
69
|
-
resources: z.array(
|
|
81
|
+
resources: z.array(ServerResourceSchema).describe("Array of available resources")
|
|
70
82
|
}).strict().describe("List of resources from MCP server");
|
|
71
83
|
const ResourceContentSchema = z.object({
|
|
72
84
|
content: z.any().describe("Resource content data")
|
|
@@ -118,7 +130,10 @@ function createMcpRouter(getAgent, getAgentConfigPath) {
|
|
|
118
130
|
description: "Server configuration",
|
|
119
131
|
content: { "application/json": { schema: ServerConfigResponseSchema } }
|
|
120
132
|
},
|
|
121
|
-
404: {
|
|
133
|
+
404: {
|
|
134
|
+
description: "Not found",
|
|
135
|
+
content: { "application/json": { schema: ApiErrorResponseSchema } }
|
|
136
|
+
}
|
|
122
137
|
}
|
|
123
138
|
});
|
|
124
139
|
const updateServerRoute = createRoute({
|
|
@@ -136,7 +151,10 @@ function createMcpRouter(getAgent, getAgentConfigPath) {
|
|
|
136
151
|
description: "Server updated",
|
|
137
152
|
content: { "application/json": { schema: ServerStatusResponseSchema } }
|
|
138
153
|
},
|
|
139
|
-
404: {
|
|
154
|
+
404: {
|
|
155
|
+
description: "Not found",
|
|
156
|
+
content: { "application/json": { schema: ApiErrorResponseSchema } }
|
|
157
|
+
}
|
|
140
158
|
}
|
|
141
159
|
});
|
|
142
160
|
const toolsRoute = createRoute({
|
|
@@ -153,7 +171,10 @@ function createMcpRouter(getAgent, getAgentConfigPath) {
|
|
|
153
171
|
description: "Tools list",
|
|
154
172
|
content: { "application/json": { schema: ToolsListResponseSchema } }
|
|
155
173
|
},
|
|
156
|
-
404: {
|
|
174
|
+
404: {
|
|
175
|
+
description: "Not found",
|
|
176
|
+
content: { "application/json": { schema: ApiErrorResponseSchema } }
|
|
177
|
+
}
|
|
157
178
|
}
|
|
158
179
|
});
|
|
159
180
|
const deleteServerRoute = createRoute({
|
|
@@ -170,7 +191,10 @@ function createMcpRouter(getAgent, getAgentConfigPath) {
|
|
|
170
191
|
description: "Disconnected",
|
|
171
192
|
content: { "application/json": { schema: DisconnectResponseSchema } }
|
|
172
193
|
},
|
|
173
|
-
404: {
|
|
194
|
+
404: {
|
|
195
|
+
description: "Not found",
|
|
196
|
+
content: { "application/json": { schema: ApiErrorResponseSchema } }
|
|
197
|
+
}
|
|
174
198
|
}
|
|
175
199
|
});
|
|
176
200
|
const restartServerRoute = createRoute({
|
|
@@ -187,7 +211,10 @@ function createMcpRouter(getAgent, getAgentConfigPath) {
|
|
|
187
211
|
description: "Server restarted",
|
|
188
212
|
content: { "application/json": { schema: RestartResponseSchema } }
|
|
189
213
|
},
|
|
190
|
-
404: {
|
|
214
|
+
404: {
|
|
215
|
+
description: "Not found",
|
|
216
|
+
content: { "application/json": { schema: ApiErrorResponseSchema } }
|
|
217
|
+
}
|
|
191
218
|
}
|
|
192
219
|
});
|
|
193
220
|
const execToolRoute = createRoute({
|
|
@@ -208,7 +235,10 @@ function createMcpRouter(getAgent, getAgentConfigPath) {
|
|
|
208
235
|
description: "Tool executed",
|
|
209
236
|
content: { "application/json": { schema: ToolExecutionResponseSchema } }
|
|
210
237
|
},
|
|
211
|
-
404: {
|
|
238
|
+
404: {
|
|
239
|
+
description: "Not found",
|
|
240
|
+
content: { "application/json": { schema: ApiErrorResponseSchema } }
|
|
241
|
+
}
|
|
212
242
|
}
|
|
213
243
|
});
|
|
214
244
|
const listResourcesRoute = createRoute({
|
|
@@ -225,7 +255,10 @@ function createMcpRouter(getAgent, getAgentConfigPath) {
|
|
|
225
255
|
description: "Server resources",
|
|
226
256
|
content: { "application/json": { schema: ResourcesListResponseSchema } }
|
|
227
257
|
},
|
|
228
|
-
404: {
|
|
258
|
+
404: {
|
|
259
|
+
description: "Not found",
|
|
260
|
+
content: { "application/json": { schema: ApiErrorResponseSchema } }
|
|
261
|
+
}
|
|
229
262
|
}
|
|
230
263
|
});
|
|
231
264
|
const getResourceContentRoute = createRoute({
|
|
@@ -245,7 +278,10 @@ function createMcpRouter(getAgent, getAgentConfigPath) {
|
|
|
245
278
|
description: "Resource content",
|
|
246
279
|
content: { "application/json": { schema: ResourceContentResponseSchema } }
|
|
247
280
|
},
|
|
248
|
-
404: {
|
|
281
|
+
404: {
|
|
282
|
+
description: "Not found",
|
|
283
|
+
content: { "application/json": { schema: ApiErrorResponseSchema } }
|
|
284
|
+
}
|
|
249
285
|
}
|
|
250
286
|
});
|
|
251
287
|
return app.openapi(addServerRoute, async (ctx) => {
|
|
@@ -294,22 +330,22 @@ function createMcpRouter(getAgent, getAgentConfigPath) {
|
|
|
294
330
|
for (const name of Object.keys(failedConnections)) {
|
|
295
331
|
servers.push({ id: name, name, status: "error" });
|
|
296
332
|
}
|
|
297
|
-
return ctx.json({ servers });
|
|
333
|
+
return ctx.json({ servers }, 200);
|
|
298
334
|
}).openapi(getServerConfigRoute, async (ctx) => {
|
|
299
335
|
const agent = await getAgent(ctx);
|
|
300
336
|
const { serverId } = ctx.req.valid("param");
|
|
301
337
|
const config = agent.getMcpServerConfig(serverId);
|
|
302
338
|
if (!config) {
|
|
303
|
-
|
|
339
|
+
throw MCPError.serverNotFound(serverId);
|
|
304
340
|
}
|
|
305
|
-
return ctx.json({ name: serverId, config }, 200);
|
|
341
|
+
return ctx.json({ name: serverId, config: McpServerConfigSchema.parse(config) }, 200);
|
|
306
342
|
}).openapi(updateServerRoute, async (ctx) => {
|
|
307
343
|
const agent = await getAgent(ctx);
|
|
308
344
|
const { serverId } = ctx.req.valid("param");
|
|
309
345
|
const { config, persistToAgent } = ctx.req.valid("json");
|
|
310
346
|
const existingConfig = agent.getMcpServerConfig(serverId);
|
|
311
347
|
if (!existingConfig) {
|
|
312
|
-
|
|
348
|
+
throw MCPError.serverNotFound(serverId);
|
|
313
349
|
}
|
|
314
350
|
await agent.updateMcpServer(serverId, config);
|
|
315
351
|
if (persistToAgent === true) {
|
|
@@ -342,26 +378,26 @@ function createMcpRouter(getAgent, getAgentConfigPath) {
|
|
|
342
378
|
const { serverId } = ctx.req.valid("param");
|
|
343
379
|
const client = agent.getMcpClients().get(serverId);
|
|
344
380
|
if (!client) {
|
|
345
|
-
|
|
381
|
+
throw MCPError.serverNotFound(serverId);
|
|
346
382
|
}
|
|
347
383
|
const toolsMap = await client.getTools();
|
|
348
384
|
const tools = Object.entries(toolsMap).map(([toolName, toolDef]) => ({
|
|
349
385
|
id: toolName,
|
|
350
386
|
name: toolName,
|
|
351
387
|
description: toolDef.description || "",
|
|
352
|
-
inputSchema: toolDef.parameters,
|
|
388
|
+
inputSchema: toolDef.parameters === void 0 ? void 0 : ToolInputSchema.parse(toolDef.parameters),
|
|
353
389
|
_meta: toolDef._meta
|
|
354
390
|
}));
|
|
355
|
-
return ctx.json({ tools });
|
|
391
|
+
return ctx.json({ tools }, 200);
|
|
356
392
|
}).openapi(deleteServerRoute, async (ctx) => {
|
|
357
393
|
const agent = await getAgent(ctx);
|
|
358
394
|
const { serverId } = ctx.req.valid("param");
|
|
359
395
|
const clientExists = agent.getMcpClients().has(serverId) || agent.getMcpFailedConnections()[serverId];
|
|
360
396
|
if (!clientExists) {
|
|
361
|
-
|
|
397
|
+
throw MCPError.serverNotFound(serverId);
|
|
362
398
|
}
|
|
363
399
|
await agent.removeMcpServer(serverId);
|
|
364
|
-
return ctx.json({ status: "disconnected", id: serverId });
|
|
400
|
+
return ctx.json({ status: "disconnected", id: serverId }, 200);
|
|
365
401
|
}).openapi(restartServerRoute, async (ctx) => {
|
|
366
402
|
const agent = await getAgent(ctx);
|
|
367
403
|
const { serverId } = ctx.req.valid("param");
|
|
@@ -369,21 +405,21 @@ function createMcpRouter(getAgent, getAgentConfigPath) {
|
|
|
369
405
|
const clientExists = agent.getMcpClients().has(serverId);
|
|
370
406
|
if (!clientExists) {
|
|
371
407
|
logger.warn(`Attempted to restart non-existent server: ${serverId}`);
|
|
372
|
-
|
|
408
|
+
throw MCPError.serverNotFound(serverId);
|
|
373
409
|
}
|
|
374
410
|
await agent.restartMcpServer(serverId);
|
|
375
|
-
return ctx.json({ status: "restarted", id: serverId });
|
|
411
|
+
return ctx.json({ status: "restarted", id: serverId }, 200);
|
|
376
412
|
}).openapi(execToolRoute, async (ctx) => {
|
|
377
413
|
const agent = await getAgent(ctx);
|
|
378
414
|
const { serverId, toolName } = ctx.req.valid("param");
|
|
379
415
|
const body = ctx.req.valid("json");
|
|
380
416
|
const client = agent.getMcpClients().get(serverId);
|
|
381
417
|
if (!client) {
|
|
382
|
-
|
|
418
|
+
throw MCPError.serverNotFound(serverId);
|
|
383
419
|
}
|
|
384
420
|
try {
|
|
385
421
|
const rawResult = await client.callTool(toolName, body);
|
|
386
|
-
return ctx.json({ success: true, data: rawResult });
|
|
422
|
+
return ctx.json({ success: true, data: rawResult }, 200);
|
|
387
423
|
} catch (error) {
|
|
388
424
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
389
425
|
logger.error(
|
|
@@ -397,20 +433,20 @@ function createMcpRouter(getAgent, getAgentConfigPath) {
|
|
|
397
433
|
const { serverId } = ctx.req.valid("param");
|
|
398
434
|
const client = agent.getMcpClients().get(serverId);
|
|
399
435
|
if (!client) {
|
|
400
|
-
|
|
436
|
+
throw MCPError.serverNotFound(serverId);
|
|
401
437
|
}
|
|
402
438
|
const resources = await agent.listResourcesForServer(serverId);
|
|
403
|
-
return ctx.json({ success: true, resources });
|
|
439
|
+
return ctx.json({ success: true, resources }, 200);
|
|
404
440
|
}).openapi(getResourceContentRoute, async (ctx) => {
|
|
405
441
|
const agent = await getAgent(ctx);
|
|
406
442
|
const { serverId, resourceId } = ctx.req.valid("param");
|
|
407
443
|
const client = agent.getMcpClients().get(serverId);
|
|
408
444
|
if (!client) {
|
|
409
|
-
|
|
445
|
+
throw MCPError.serverNotFound(serverId);
|
|
410
446
|
}
|
|
411
447
|
const qualifiedUri = `mcp:${serverId}:${resourceId}`;
|
|
412
448
|
const content = await agent.readResource(qualifiedUri);
|
|
413
|
-
return ctx.json({ success: true, data: { content } });
|
|
449
|
+
return ctx.json({ success: true, data: { content } }, 200);
|
|
414
450
|
});
|
|
415
451
|
}
|
|
416
452
|
export {
|