惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
WordPress大学
WordPress大学
阮一峰的网络日志
阮一峰的网络日志
博客园 - 司徒正美
月光博客
月光博客
宝玉的分享
宝玉的分享
Recent Announcements
Recent Announcements
小众软件
小众软件
H
Hackread – Cybersecurity News, Data Breaches, AI and More
美团技术团队
博客园 - 三生石上(FineUI控件)
A
About on SuperTechFans
J
Java Code Geeks
云风的 BLOG
云风的 BLOG
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
IT之家
IT之家
Vercel News
Vercel News
量子位
Martin Fowler
Martin Fowler
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
腾讯CDC
有赞技术团队
有赞技术团队

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(agents): surface MCP structured content in tool resul...
Pluviobyte · 2026-05-29 · via Recent Commits to openclaw:main
Original file line numberDiff line numberDiff line change

@@ -27,30 +27,33 @@ function toAgentToolResult(params: {

2727

const content = Array.isArray(params.result.content)

2828

? (params.result.content as AgentToolResult<unknown>["content"])

2929

: [];

30-

const normalizedContent: AgentToolResult<unknown>["content"] =

31-

content.length > 0

30+

const structuredContentBlock =

31+

params.result.structuredContent !== undefined

32+

? ({

33+

type: "text",

34+

text: `structuredContent:\n${JSON.stringify(params.result.structuredContent, null, 2)}`,

35+

} as const)

36+

: null;

37+

// Structured MCP results are the canonical model payload here; replacing

38+

// mirrored content avoids duplicating large tool output in the prompt.

39+

const normalizedContent: AgentToolResult<unknown>["content"] = structuredContentBlock

40+

? [structuredContentBlock]

41+

: content.length > 0

3242

? content

33-

: params.result.structuredContent !== undefined

34-

? [

35-

{

36-

type: "text",

37-

text: JSON.stringify(params.result.structuredContent, null, 2),

38-

},

39-

]

40-

: ([

41-

{

42-

type: "text",

43-

text: JSON.stringify(

44-

{

45-

status: params.result.isError === true ? "error" : "ok",

46-

server: params.serverName,

47-

tool: params.toolName,

48-

},

49-

null,

50-

2,

51-

),

52-

},

53-

] as AgentToolResult<unknown>["content"]);

43+

: ([

44+

{

45+

type: "text",

46+

text: JSON.stringify(

47+

{

48+

status: params.result.isError === true ? "error" : "ok",

49+

server: params.serverName,

50+

tool: params.toolName,

51+

},

52+

null,

53+

2,

54+

),

55+

},

56+

] as AgentToolResult<unknown>["content"]);

5457

const details: Record<string, unknown> = {

5558

mcpServer: params.serverName,

5659

mcpTool: params.toolName,

Original file line numberDiff line numberDiff line change

@@ -1,3 +1,4 @@

1+

import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";

12

import { validateToolArguments } from "openclaw/plugin-sdk/llm";

23

import { describe, expect, it } from "vitest";

34

import { getPluginToolMeta } from "../plugins/tools.js";

@@ -18,6 +19,7 @@ function makeToolRuntime(

1819

params: {

1920

tools?: McpCatalogTool[];

2021

serverName?: string;

22+

result?: CallToolResult;

2123

resultText?: string;

2224

} = {},

2325

): SessionMcpRuntime {

@@ -63,10 +65,11 @@ function makeToolRuntime(

6365

},

6466

tools,

6567

}),

66-

callTool: async () => ({

67-

content: [{ type: "text", text: params.resultText ?? "FROM-BUNDLE" }],

68-

isError: false,

69-

}),

68+

callTool: async () =>

69+

params.result ?? {

70+

content: [{ type: "text", text: params.resultText ?? "FROM-BUNDLE" }],

71+

isError: false,

72+

},

7073

dispose: async () => {},

7174

};

7275

}

@@ -87,6 +90,44 @@ describe("createBundleMcpToolRuntime", () => {

8790

});

8891

});

8992
93+

it("keeps structuredContent visible when MCP tools also return text content", async () => {

94+

const runtime = await materializeBundleMcpToolsForRun({

95+

runtime: makeToolRuntime({

96+

result: {

97+

content: [{ type: "text", text: "pong" }],

98+

structuredContent: {

99+

threadId: "019e6cdb-8e7f-7cb2-891f-9edb689f6fc7",

100+

content: "pong",

101+

},

102+

isError: false,

103+

},

104+

}),

105+

});

106+
107+

const result = await runtime.tools[0].execute("call-bundle-probe", {}, undefined, undefined);

108+
109+

expectTextContentBlock(

110+

result.content[0],

111+

`structuredContent:\n${JSON.stringify(

112+

{

113+

threadId: "019e6cdb-8e7f-7cb2-891f-9edb689f6fc7",

114+

content: "pong",

115+

},

116+

null,

117+

2,

118+

)}`,

119+

);

120+

expect(result.content).toHaveLength(1);

121+

expect(result.details).toEqual({

122+

mcpServer: "bundleProbe",

123+

mcpTool: "bundle_probe",

124+

structuredContent: {

125+

threadId: "019e6cdb-8e7f-7cb2-891f-9edb689f6fc7",

126+

content: "pong",

127+

},

128+

});

129+

});

130+
90131

it("disambiguates bundle MCP tools that collide with existing tool names", async () => {

91132

const runtime = await materializeBundleMcpToolsForRun({

92133

runtime: makeToolRuntime(),