Skip to content

Add structured MCP tool outputs - #411

Closed
Lauritz-Timm wants to merge 3 commits into
rtk-ai:developfrom
Lauritz-Timm:feat/mcp-structured-output
Closed

Add structured MCP tool outputs#411
Lauritz-Timm wants to merge 3 commits into
rtk-ai:developfrom
Lauritz-Timm:feat/mcp-structured-output

Conversation

@Lauritz-Timm

@Lauritz-Timm Lauritz-Timm commented Jul 30, 2026

Copy link
Copy Markdown

Summary

Add direct typed MCP output for recall, topic listing, and statistics.

Motivation

Modern clients can consume typed results directly instead of parsing prose. The previous generic structured envelope duplicated complete payloads, increased token use, and provided a weak contract.

Changes

  • define the memory-domain output contract as typed Rust DTOs and tool markers in output/memory.rs
  • derive the precise per-tool JSON Schemas from those DTOs with schemars instead of maintaining handwritten schema JSON
  • register each typed marker's output-schema hook in the shared ToolSpec catalog
  • return each typed value directly in structuredContent
  • use concise modern text instead of duplicating complete payloads
  • preserve full human-readable legacy text
  • keep text-only tools unstructured
  • omit embedding vectors
  • preserve hints in modern and legacy output

Compatibility and safety

MCP 2024-11-05 clients receive the same full text and no structured fields. Newer supported revisions receive typed output for exactly the three discovery tools. This changes transport shape, not retrieval ranking.

Validation

cargo test -p icm-mcp --locked --offline
cargo clippy -p icm-mcp --all-targets --locked --offline -- -D warnings
cargo fmt --all -- --check

Focused regressions validate real emitted Rust DTO values against their generated schemas and cover the three-schema allowlist, direct typed values, concise modern text, exact legacy text, hint preservation, text-only omission, and a large-fixture duplication saving.

The evaluation measured recall wire tokens falling from 1,411 to 619 (-56.1%) while Hit@3, Recall@3, nDCG@3, ordering parity, and required-field coverage remained at 100%.

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