@devframes/agentic 1.2.4 → 1.2.6

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 (2) hide show
  1. package/dist/mcp/index.mjs +43 -8
  2. package/package.json +3 -3
@@ -2,7 +2,7 @@ import { homedir } from "node:os";
2
2
  import process from "node:process";
3
3
  import { Server, createMcpHandler } from "@modelcontextprotocol/server";
4
4
  import { DEVFRAME_EVENTS } from "devframe/constants";
5
- import { argsToJsonSchema, diagnostics, formatMcpError, returnToJsonSchema, stringifyForMcp } from "devframe/internal";
5
+ import { argsToJsonSchema, diagnostics, formatMcpError, getMcpContent, returnToJsonSchema, stringifyForMcp } from "devframe/internal";
6
6
  import { createHostContext } from "devframe/node";
7
7
  import { toAgentToolName } from "devframe/utils/agent-tool-name";
8
8
  import { join } from "pathe";
@@ -26,10 +26,13 @@ function buildMcpServerFromContext(ctx, options) {
26
26
  const server = new Server({
27
27
  name: options.serverName,
28
28
  version: options.serverVersion
29
- }, { capabilities: {
30
- tools: { listChanged: true },
31
- resources: { listChanged: true }
32
- } });
29
+ }, {
30
+ capabilities: {
31
+ tools: { listChanged: true },
32
+ resources: { listChanged: true }
33
+ },
34
+ ...options.instructions ? { instructions: options.instructions } : {}
35
+ });
33
36
  registerToolHandlers(server, ctx, options.exposeSharedState);
34
37
  registerResourceHandlers(server, ctx, options.exposeSharedState);
35
38
  return server;
@@ -89,7 +92,8 @@ async function createMcpServer(definition, options = {}) {
89
92
  const buildOptions = {
90
93
  serverName: options.serverName ?? `${definition.id} (devframe)`,
91
94
  serverVersion: options.serverVersion ?? definition.version ?? "0.0.0",
92
- exposeSharedState: options.exposeSharedState ?? true
95
+ exposeSharedState: options.exposeSharedState ?? true,
96
+ instructions: options.instructions
93
97
  };
94
98
  let handle;
95
99
  try {
@@ -217,7 +221,7 @@ function registerToolHandlers(server, ctx, exposeSharedState) {
217
221
  const outputSchema = tool ? usableOutputSchema(tool.outputSchema ?? computeOutputSchema(tool, ctx)) : void 0;
218
222
  const result = await ctx.agent.invoke(tool?.id ?? name, args ?? {});
219
223
  return {
220
- content: [{
224
+ content: mcpContentOf(name, result) ?? [{
221
225
  type: "text",
222
226
  text: stringifyForMcp(result)
223
227
  }],
@@ -278,6 +282,36 @@ function registerResourceHandlers(server, ctx, exposeSharedState) {
278
282
  });
279
283
  }
280
284
  /**
285
+ * The content blocks a tool result carries through `withMcpContent`, checked
286
+ * and copied field by field, or `undefined` when it carries none. Invalid
287
+ * blocks throw DF0081, which the `tools/call` handler turns into an
288
+ * `isError` result.
289
+ */
290
+ function mcpContentOf(name, result) {
291
+ const blocks = getMcpContent(result);
292
+ if (blocks === void 0) return void 0;
293
+ if (!Array.isArray(blocks) || blocks.length === 0) throw diagnostics.DF0081({
294
+ name,
295
+ reason: "expected a non-empty array"
296
+ });
297
+ return Array.from(blocks, (block, index) => {
298
+ const b = block ?? {};
299
+ if (b.type === "text" && typeof b.text === "string") return {
300
+ type: "text",
301
+ text: b.text
302
+ };
303
+ if ((b.type === "image" || b.type === "audio") && typeof b.data === "string" && typeof b.mimeType === "string") return {
304
+ type: b.type,
305
+ data: b.data,
306
+ mimeType: b.mimeType
307
+ };
308
+ throw diagnostics.DF0081({
309
+ name,
310
+ reason: `block ${index} is not a valid text, image or audio block`
311
+ });
312
+ });
313
+ }
314
+ /**
281
315
  * MCP constrains a tool's `outputSchema` to a JSON Schema of `type:
282
316
  * "object"`; clients (the SDK included) reject anything else. Non-object
283
317
  * return schemas (e.g. a schema for `void` / a bare string) simply project
@@ -398,7 +432,8 @@ function createMcpFetchHandler(ctx, options) {
398
432
  const handler = createMcpHandler(() => buildMcpServerFromContext(ctx, {
399
433
  serverName: options.serverName,
400
434
  serverVersion: options.serverVersion,
401
- exposeSharedState: options.exposeSharedState
435
+ exposeSharedState: options.exposeSharedState,
436
+ instructions: options.instructions
402
437
  }));
403
438
  const unbridge = bridgeListChanged(ctx, {
404
439
  tools: () => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@devframes/agentic",
3
3
  "type": "module",
4
- "version": "1.2.4",
4
+ "version": "1.2.6",
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.2.4"
33
+ "devframe": "1.2.6"
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.4",
44
- "devframe": "1.2.4",
44
+ "devframe": "1.2.6",
45
45
  "tsdown": "^0.23.0",
46
46
  "valibot": "^1.5.0"
47
47
  },