Skip to content

fix(sandbox): support nested JSON and banner prefix in AgentRun MCP response#1930

Open
itxaiohanglover wants to merge 1 commit into
agentscope-ai:mainfrom
itxaiohanglover:fix/agentrun-mcp-nested-response
Open

fix(sandbox): support nested JSON and banner prefix in AgentRun MCP response#1930
itxaiohanglover wants to merge 1 commit into
agentscope-ai:mainfrom
itxaiohanglover:fix/agentrun-mcp-nested-response

Conversation

@itxaiohanglover

Copy link
Copy Markdown
Contributor

Summary

  • Support nested JSON format ({"result":{"exitCode":...}}) in parseExecPayload()
  • Handle markdown banner prefixes before JSON payload by locating first {
  • Only treat as exec result when exitCode/exit_code is present in the resolved object

Problem

AgentRunMcpChannel.parseExecPayload() assumed flat JSON and required text to start with {. The AgentRun MCP server (protocol 2025-03-26) returns:

  1. Nested formatexitCode/stdout/stderr inside a result sub-object
  2. Banner prefix — markdown headers before the JSON payload

When parsing fails, the entire MCP response text (including banner) is returned as stdout, causing glob() to treat banner lines as file paths and triggering InvalidPathException on Windows.

Fixes #1908

Test Plan

  • Unit test: flat JSON {"exitCode":0,"stdout":"ok","stderr":""} still parses correctly
  • Unit test: nested JSON {"result":{"exitCode":1,"stdout":"","stderr":"err"}} parses correctly
  • Unit test: banner + JSON ### process_exec_cmd\n...\n{"exitCode":0,...} parses correctly
  • Unit test: plain text falls back to ExecResult(0, text, "")

…esponse

parseExecPayload() assumed flat JSON format and required the text to
start with "{". AgentRun MCP server returns nested format with
exitCode/stdout/stderr inside a "result" sub-object, and may prepend
a markdown banner before the JSON payload.

- Locate first "{" to skip banner prefixes
- Check "result" sub-object for exit fields before falling back to root
- Only treat as exec result if exitCode/exit_code is present

Fixes agentscope-ai#1908
@itxaiohanglover itxaiohanglover requested a review from a team June 26, 2026 04:03
@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 15 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...xtensions/sandbox/agentrun/AgentRunMcpChannel.java 0.00% 15 Missing ⚠️

📢 Thoughts on this report? Let us know!

@itxaiohanglover

Copy link
Copy Markdown
Contributor Author

The codecov/patch failure is expected for fork PRs — the fork doesn't have the CODECOV_TOKEN secret configured. The actual build passes on both ubuntu and windows. This is a known issue with fork CI, not related to the code changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: AgentRunMcpChannel.parseExecPayload() 不支持 AgentRun MCP 嵌套响应格式

1 participant