Skip to content

Unify content and structuredContent output paths #13

@bananabot9000

Description

@bananabot9000

Description

Per the MCP spec:

For backwards compatibility, a tool that returns structured content SHOULD also return the serialized JSON in a TextContent block.

Currently content and structuredContent are built by separate code paths in execToolDefinition.ts. This leads to divergence (e.g. ANSI stripping only applied to content, not structuredContent).

Proposed approach

Build one canonical result object, derive both outputs from it:

const canonical = buildResult(result);  // single path, fully processed

return {
  content: [{ type: 'text', text: JSON.stringify(canonical) }],
  structuredContent: canonical,
};

Benefits

  • Eliminates divergence bugs by construction
  • Matches MCP spec intent (content = serialised structuredContent)
  • Single place for all output transformations (ANSI stripping, formatting, etc.)
  • Less code to maintain

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions