@devframes/agentic 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mcp/index.mjs +53 -4
- package/package.json +3 -3
package/dist/mcp/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { homedir } from "node:os";
|
|
2
2
|
import process from "node:process";
|
|
3
|
-
import { Server, createMcpHandler } from "@modelcontextprotocol/server";
|
|
3
|
+
import { ProtocolError, ProtocolErrorCode, Server, createMcpHandler } from "@modelcontextprotocol/server";
|
|
4
4
|
import { DEVFRAME_EVENTS } from "devframe/constants";
|
|
5
5
|
import { argsToJsonSchema, diagnostics, formatMcpError, getMcpContent, returnToJsonSchema, stringifyForMcp } from "devframe/internal";
|
|
6
6
|
import { createHostContext } from "devframe/node";
|
|
@@ -29,7 +29,8 @@ function buildMcpServerFromContext(ctx, options) {
|
|
|
29
29
|
}, {
|
|
30
30
|
capabilities: {
|
|
31
31
|
tools: { listChanged: true },
|
|
32
|
-
resources: { listChanged: true }
|
|
32
|
+
resources: { listChanged: true },
|
|
33
|
+
...options.prompts?.size ? { prompts: { listChanged: false } } : {}
|
|
33
34
|
},
|
|
34
35
|
...options.instructions ? { instructions: options.instructions } : {}
|
|
35
36
|
});
|
|
@@ -43,6 +44,7 @@ function buildMcpServerFromContext(ctx, options) {
|
|
|
43
44
|
description,
|
|
44
45
|
mimeType
|
|
45
46
|
})) }));
|
|
47
|
+
if (options.prompts?.size) registerPromptHandlers(server, options.prompts);
|
|
46
48
|
return server;
|
|
47
49
|
}
|
|
48
50
|
/**
|
|
@@ -89,6 +91,7 @@ async function createMcpServer(definition, options = {}) {
|
|
|
89
91
|
reason: "Only stdio transport is supported in this release."
|
|
90
92
|
});
|
|
91
93
|
const resourceTemplates = compileResourceTemplates(options.resourceTemplates);
|
|
94
|
+
const prompts = compilePrompts(options.prompts);
|
|
92
95
|
const ctx = await createHostContext({
|
|
93
96
|
cwd: process.cwd(),
|
|
94
97
|
mode: "dev",
|
|
@@ -111,7 +114,8 @@ async function createMcpServer(definition, options = {}) {
|
|
|
111
114
|
serverVersion: options.serverVersion ?? definition.version ?? "0.0.0",
|
|
112
115
|
exposeSharedState: options.exposeSharedState ?? true,
|
|
113
116
|
instructions: options.instructions,
|
|
114
|
-
resourceTemplates
|
|
117
|
+
resourceTemplates,
|
|
118
|
+
prompts
|
|
115
119
|
};
|
|
116
120
|
let handle;
|
|
117
121
|
try {
|
|
@@ -313,6 +317,49 @@ function registerResourceHandlers(server, ctx, exposeSharedState, templates) {
|
|
|
313
317
|
throw new Error(`[devframe/mcp] unknown resource URI "${uri}"`);
|
|
314
318
|
});
|
|
315
319
|
}
|
|
320
|
+
/**
|
|
321
|
+
* Index prompts by name, once per endpoint. A repeated name throws
|
|
322
|
+
* `DF0085`, since `prompts/get` finds a prompt by its name.
|
|
323
|
+
*
|
|
324
|
+
* @internal
|
|
325
|
+
*/
|
|
326
|
+
function compilePrompts(prompts = []) {
|
|
327
|
+
const byName = /* @__PURE__ */ new Map();
|
|
328
|
+
for (const prompt of prompts) {
|
|
329
|
+
if (byName.has(prompt.name)) throw diagnostics.DF0085({ name: prompt.name });
|
|
330
|
+
byName.set(prompt.name, prompt);
|
|
331
|
+
}
|
|
332
|
+
return byName;
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Serve `prompts/list` and `prompts/get`. An unknown name, or a required
|
|
336
|
+
* argument that is missing or empty, is an invalid-params error. An error
|
|
337
|
+
* thrown by `get` goes to the MCP client.
|
|
338
|
+
*/
|
|
339
|
+
function registerPromptHandlers(server, prompts) {
|
|
340
|
+
server.setRequestHandler("prompts/list", async () => ({ prompts: [...prompts.values()].map(({ name, title, description, arguments: args }) => ({
|
|
341
|
+
name,
|
|
342
|
+
title,
|
|
343
|
+
description,
|
|
344
|
+
...args?.length ? { arguments: args.map((argument) => ({
|
|
345
|
+
name: argument.name,
|
|
346
|
+
description: argument.description,
|
|
347
|
+
required: argument.required
|
|
348
|
+
})) } : {}
|
|
349
|
+
})) }));
|
|
350
|
+
server.setRequestHandler("prompts/get", async (request) => {
|
|
351
|
+
const { name, arguments: given = {} } = request.params;
|
|
352
|
+
const prompt = prompts.get(name);
|
|
353
|
+
if (!prompt) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `[devframe/mcp] unknown prompt "${name}"`);
|
|
354
|
+
const missing = (prompt.arguments ?? []).filter((argument) => argument.required && !(Object.hasOwn(given, argument.name) && given[argument.name])).map((argument) => argument.name);
|
|
355
|
+
if (missing.length) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `[devframe/mcp] prompt "${name}" needs the argument(s): ${missing.join(", ")}`);
|
|
356
|
+
const { description, messages } = await prompt.get(given);
|
|
357
|
+
return {
|
|
358
|
+
description,
|
|
359
|
+
messages
|
|
360
|
+
};
|
|
361
|
+
});
|
|
362
|
+
}
|
|
316
363
|
/** One `{name}` expression of a URI template. */
|
|
317
364
|
const TEMPLATE_EXPRESSION_RE = /\{([^{}]*)\}/;
|
|
318
365
|
/** RFC 6570 `varname`: letters, digits and `_`, with single dots between them. */
|
|
@@ -542,12 +589,14 @@ function createMcpFetchHandler(ctx, options) {
|
|
|
542
589
|
const allowedOrigins = options.allowedOrigins;
|
|
543
590
|
const authorization = options.authorization ?? false;
|
|
544
591
|
const resourceTemplates = compileResourceTemplates(options.resourceTemplates);
|
|
592
|
+
const prompts = compilePrompts(options.prompts);
|
|
545
593
|
const handler = createMcpHandler(() => buildMcpServerFromContext(ctx, {
|
|
546
594
|
serverName: options.serverName,
|
|
547
595
|
serverVersion: options.serverVersion,
|
|
548
596
|
exposeSharedState: options.exposeSharedState,
|
|
549
597
|
instructions: options.instructions,
|
|
550
|
-
resourceTemplates
|
|
598
|
+
resourceTemplates,
|
|
599
|
+
prompts
|
|
551
600
|
}));
|
|
552
601
|
const unbridge = bridgeListChanged(ctx, {
|
|
553
602
|
tools: () => {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@devframes/agentic",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.1",
|
|
5
5
|
"description": "Agent-surface implementation for devframe: installing it next to devframe enables the MCP adapter (devframe/adapters/mcp) and the devframe connect gateway.",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"dist"
|
|
31
31
|
],
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"devframe": "1.3.
|
|
33
|
+
"devframe": "1.3.1"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@modelcontextprotocol/client": "^2.3.1",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@standard-schema/spec": "^1.1.0",
|
|
43
43
|
"@types/node": "^26.6.5",
|
|
44
|
-
"devframe": "1.3.
|
|
44
|
+
"devframe": "1.3.1",
|
|
45
45
|
"tsdown": "0.23.0",
|
|
46
46
|
"valibot": "^1.5.0"
|
|
47
47
|
},
|