operon-agents-core 0.1.0-alpha.21 → 0.1.0-alpha.23

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.
@@ -8,7 +8,9 @@ export function computeContextBreakdown(input) {
8
8
  let builtinTools = 0;
9
9
  let mcpTools = 0;
10
10
  for (const tool of input.tools) {
11
- const tokens = estimateTokens(JSON.stringify(tool.schema));
11
+ // What goes on the wire: `outputSchema` is for programs calling the tool, never sent to the model.
12
+ const { outputSchema: _programOnly, ...sent } = tool.schema;
13
+ const tokens = estimateTokens(JSON.stringify(sent));
12
14
  if (isMcpToolName(tool.schema.name))
13
15
  mcpTools += tokens;
14
16
  else
@@ -2,6 +2,9 @@ import { ToolAccesses } from "../index.js";
2
2
  import { applyMcpToolFilter } from "./filter.js";
3
3
  import { qualifyMcpToolName } from "./tool-naming.js";
4
4
  import { mcpResultToContent } from "./output.js";
5
+ function isRecord(value) {
6
+ return value !== null && typeof value === "object" && !Array.isArray(value);
7
+ }
5
8
  function asArgs(raw) {
6
9
  return raw !== null && typeof raw === "object" ? raw : null;
7
10
  }
@@ -20,6 +23,7 @@ export function wrapMcpTool(server, def) {
20
23
  name: qualifiedName,
21
24
  description: def.description ?? `MCP tool "${rawName}" from server "${server.name}".`,
22
25
  parameters: def.inputSchema ?? { type: "object", properties: {} },
26
+ ...(isRecord(def.outputSchema) ? { outputSchema: def.outputSchema } : {}),
23
27
  },
24
28
  resolve: (rawArgs) => {
25
29
  const args = asArgs(rawArgs);
@@ -32,7 +36,7 @@ export function wrapMcpTool(server, def) {
32
36
  try {
33
37
  const result = await server.callTool(rawName, args, { signal: ctx.signal });
34
38
  const { content, isError } = mcpResultToContent(result, qualifiedName);
35
- return { content, isError };
39
+ return { content, isError, ...(result.structuredContent !== undefined ? { structured: result.structuredContent } : {}) };
36
40
  }
37
41
  catch (error) {
38
42
  const text = await defaultErrorText(server, rawName, error);
@@ -2,6 +2,8 @@ export interface MCPTool {
2
2
  readonly name: string;
3
3
  readonly description?: string;
4
4
  readonly inputSchema?: Record<string, unknown>;
5
+ /** JSON Schema of `structuredContent` in this tool's results, when the server declares one. */
6
+ readonly outputSchema?: Record<string, unknown>;
5
7
  readonly [key: string]: unknown;
6
8
  }
7
9
  export interface MCPContentBlock {
@@ -21,6 +23,8 @@ export interface MCPContentBlock {
21
23
  }
22
24
  export interface MCPToolResult {
23
25
  readonly content: readonly MCPContentBlock[];
26
+ /** The result as JSON, conforming to the tool's `outputSchema`. */
27
+ readonly structuredContent?: unknown;
24
28
  readonly isError?: boolean;
25
29
  readonly [key: string]: unknown;
26
30
  }
@@ -2,5 +2,11 @@ export interface ToolSchema {
2
2
  readonly name: string;
3
3
  readonly description: string;
4
4
  readonly parameters: Readonly<Record<string, unknown>>;
5
+ /**
6
+ * JSON Schema of the tool's machine-readable result ({@link ToolResult.structured}), when it
7
+ * has one (an MCP tool that declares `outputSchema`). Never sent to the model: it is the
8
+ * contract for a program calling the tool (Code Mode), which receives the value instead of text.
9
+ */
10
+ readonly outputSchema?: Readonly<Record<string, unknown>>;
5
11
  }
6
12
  //# sourceMappingURL=tool-schema.d.ts.map
@@ -40,6 +40,12 @@ export interface ToolResumeContext {
40
40
  }
41
41
  export interface ToolResult<Details = unknown> {
42
42
  readonly content: ToolResultContent;
43
+ /**
44
+ * The result as plain JSON data, conforming to the tool's `schema.outputSchema` (an MCP tool's
45
+ * `structuredContent`). The model reads `content`; a program calling the tool (Code Mode)
46
+ * receives this value instead of the text.
47
+ */
48
+ readonly structured?: unknown;
43
49
  readonly details?: Details;
44
50
  readonly isError?: boolean;
45
51
  readonly stopTurn?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "operon-agents-core",
3
- "version": "0.1.0-alpha.21",
3
+ "version": "0.1.0-alpha.23",
4
4
  "description": "Internal engine for operon-agents. Prefer operon-agents for application code.",
5
5
  "type": "module",
6
6
  "engines": {