Skip to content

Refactor Actor response to use structured content per MCP spec#745

Draft
jirispilka wants to merge 1 commit intomasterfrom
claude/analyze-and-fix-issue-UsO32
Draft

Refactor Actor response to use structured content per MCP spec#745
jirispilka wants to merge 1 commit intomasterfrom
claude/analyze-and-fix-issue-UsO32

Conversation

@jirispilka
Copy link
Copy Markdown
Collaborator

Summary

Refactored buildActorResponseContent to align with MCP spec 2025-11-25 by returning structured content as the canonical data payload, with backwards-compatibility support for clients that don't yet support structured content.

Key Changes

  • Structured Content First: Introduced structuredContent object containing runId, datasetId, totalItemCount, items, and instructions as the canonical response payload
  • Backwards Compatibility: Added serialized JSON of structuredContent as the first TextContent block per MCP spec recommendations for clients that don't support structured content yet
  • Improved Documentation: Updated JSDoc to clarify the response structure and MCP spec compliance
  • Better Empty State Handling: Consolidated empty preview message logic into a single emptyPreviewNote variable that's included in instructions
  • Content Block Ordering: Reordered content blocks so serialized JSON comes first, followed by human-readable metadata/instructions (which must be last for LLM acknowledgment)
  • Test Coverage: Added comprehensive unit tests verifying structured content serialization, backwards compatibility, and empty state handling

Implementation Details

  • The response now returns both structuredContent (structured data) and content array (text blocks for LLM consumption)
  • Empty preview states are now clearly communicated in the instructions rather than as separate message blocks
  • All metadata and instructions remain in the final text block to ensure LLMs properly acknowledge them

https://claude.ai/code/session_01XqXmsBHXsMi5ycLsWm7AUX

Per MCP spec 2025-11-25, a tool returning structuredContent SHOULD also
return the serialized JSON in a TextContent block. content[0] was
JSON.stringify(previewItems) — only part of structuredContent — so
backwards-compat clients saw a different payload than structured clients.

Make content[0] = JSON.stringify(structuredContent). Keep the
human-readable metadata/instructions block as content[1] (unchanged
content, still at the end). Move the empty-preview note into
structuredContent.instructions so structuredContent-only clients see it.

Narrow fix for #709. Broader tool-result standardization tracked in #744.
@github-actions github-actions Bot added t-ai Issues owned by the AI team. tested Temporary label used only programatically for some analytics. labels Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-ai Issues owned by the AI team. tested Temporary label used only programatically for some analytics.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants