Skip to content

fix(mcp): preserve distinct structured tool results - #3654

Merged
RealKai42 merged 2 commits into
mainfrom
fix/mcp-structured-results
Sep 8, 2026
Merged

fix(mcp): preserve distinct structured tool results#3654
RealKai42 merged 2 commits into
mainfrom
fix/mcp-structured-results

Conversation

@RealKai42

@RealKai42 RealKai42 commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

Related Issue

Related to #2554 and follows up on #3234's handling of duplicate MCP output.

Problem

An MCP tool can return a short summary in content and its records in structuredContent. The current adapter drops the records whenever content contains any usable text or media: a response saying “Found 1 row.” reaches the model without the row itself. The dropped data never reaches the tool-result spill pipeline.

What changed

  • Preserve structured results alongside summaries, human-readable reports, media, and conflicting text values. Omit the structured copy only when a complete text block parses to the same JSON value; whitespace and object-key order do not prevent deduplication.
  • Compare numeric values conservatively. Noncanonical number spellings retain both representations instead of allowing JSON parsing to round distinct values into an apparent match.
  • Escape < in serialized extras instead of deleting closing-tag strings, so decoded field values remain unchanged.
  • Update existing unit and real stdio-server tests, add an executor/spill/Read regression that retrieves all 1,200 records without repeating the MCP call, and document the behavior in both locales.

Human-readable renderings can overlap with structured data; they are retained because the adapter cannot establish that they preserve every field and type. Existing global spill retention limits and persistence-failure behavior remain outside this change.

Validation

  • CI follow-up: pnpm --filter @moonshot-ai/agent-core-v2 test src/human/test/llm/thinking.test.ts — 15 tests passed after correcting an existing test listener from llm.delta to llm.streaming.part. The requester already emits the latter; production behavior is unchanged.
  • pnpm --filter @moonshot-ai/agent-core-v2 test test/agent/mcp test/mcpCore test/agent/toolExecutor test/agent/toolResultTruncation test/os/backends/node-local/tools/read.test.ts --disableConsoleIntercept --maxWorkers=4 — 419 tests passed across 15 files.
  • After replacing the touched fixture's project identifiers with neutral examples, pnpm --filter @moonshot-ai/agent-core-v2 test test/agent/mcp/output.test.ts — 68 tests passed.
  • pnpm --filter @moonshot-ai/agent-core-v2 typecheck — passed.
  • pnpm --filter @moonshot-ai/agent-core-v2 lint:imports — passed.
  • pnpm lint — passed with warnings and no errors.
  • pnpm --dir docs run build — passed.
  • Read-only pre-PR audit found no new internal identifiers, credentials, unrelated files, or blocking findings.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked the related issue and explained the problem.
  • I have added tests that prove the behavior works.
  • Ran gen-changesets guidance and included a CLI patch changeset.
  • Reviewed gen-docs guidance and synchronized the affected documentation with translate-docs.

@changeset-bot

changeset-bot Bot commented Sep 8, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f88f2c7

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 8, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-08T13:10:58.725821Z 7bbf860 PR opened
🔒 Security Review Completed 2026-09-08T13:15:17.883568Z 7bbf860 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pkg-pr-new

pkg-pr-new Bot commented Sep 8, 2026

Copy link
Copy Markdown
pnpm dlx https://pkg.pr.new/@moonshot-ai/kimi-code@f88f2c7
npx https://pkg.pr.new/@moonshot-ai/kimi-code@f88f2c7

commit: f88f2c7

@RealKai42
RealKai42 merged commit 6de0cec into main Sep 8, 2026
16 checks passed
@RealKai42
RealKai42 deleted the fix/mcp-structured-results branch September 8, 2026 13:40
@github-actions github-actions Bot mentioned this pull request Sep 8, 2026
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.

1 participant