Skip to content

feat: MCP text format v2 — XML envelopes, relevance tiers, source context (R71)#197

Merged
EtanHey merged 1 commit intomainfrom
feat/mcp-text-format-v2
Apr 3, 2026
Merged

feat: MCP text format v2 — XML envelopes, relevance tiers, source context (R71)#197
EtanHey merged 1 commit intomainfrom
feat/mcp-text-format-v2

Conversation

@EtanHey
Copy link
Copy Markdown
Owner

@EtanHey EtanHey commented Apr 3, 2026

Summary

Complete redesign of MCP text output format based on R71 research spec. Same data, much better presentation.

Before → After

brain_search:

Before: ├─ [1] rt-9102edee-  score:20.81  imp: 4  2026-04-03
         │  orchestrator     │ This chunk displays knowledge graph...

After:  ### ◇ [1] This chunk displays knowledge graph information about Cantaloupe AI...
        ●●● │ from: conversation │ 2026-04-03 │ project: orchestrator

brain_entity:

Before: ┌─ Entity: Etan Heyman
        │ id: 018c1da2868e75db  type: person
        ├─ Relations (10)
        │   ← coaches: coachClaude
        │   → owns: brainClaude

After:  ## ◆ Etan Heyman [Person]
        ### Outgoing relationships (9)
        → OWNS: brainClaude, voicelayer, etanheyman.com, songscript, domica, golems
        ### Incoming relationships (1)
        ← COACHES: coachClaude

Changes

  • XML envelopes: <brain_search query=... tool="brain_search"> / <brain_entity name=... tool="brain_entity">
  • Markers: ◆ entities, ◇ chunks (pattern-matchable)
  • Relevance tiers: ●●●/●●○/●○○ (replaces raw score numbers)
  • Source + date: "from: conversation │ 2026-04-03 │ project: orchestrator"
  • Grouped relations: outgoing/incoming sections, UPPERCASE labels
  • Smart sentence-boundary content cutting
  • Chunk IDs hidden from display (still in XML attributes)

Test plan

  • swift build compiles
  • Live socat: brain_search('who works at Cantaloupe AI') → v2 format with KG + XML
  • Live socat: brain_entity('brainlayer') → grouped relations, metadata, XML envelope
  • Live socat: brain_entity('Etan Heyman') → outgoing/incoming sections
  • Live socat: brain_search('best practices TDD') → no KG card, clean text results

Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com

🤖 Generated with Claude Code

Note

Reformat MCP text output to use XML envelopes, relevance tiers, and source context

  • Rewrites TextFormatter.formatSearchResults to emit a <brain_search> XML envelope with markdown-style content, including relevance tier indicators (●●●/●●○/●○○), source labels, tags, and smart word/sentence-boundary truncation.
  • Rewrites TextFormatter.formatEntitySimple to emit a <brain_entity> XML envelope with grouped outgoing/incoming relationships and bullet-list metadata, replacing ASCII box drawing.
  • Rewrites TextFormatter.formatKGFacts to group facts into outgoing/incoming sections with uppercased relation type labels and arrow indicators.
  • Adds relevanceTier and sourceLabel computed properties to SearchResult, and parses content_type and session_id from search payloads.
  • In MCPRouter.handleBrainSearch, KG facts are now separated from the <brain_search> block with a horizontal rule.
  • Behavioral Change: All MCP text output format changes are breaking for any downstream consumer parsing the previous ASCII box-drawn format.

Macroscope summarized b5bd9ba.

Summary by CodeRabbit

New Features

  • Enhanced search results display with improved structured formatting and clearer organization of related information
  • Added relevance tier indicators and source labels to help identify result context and origin
  • Improved knowledge graph facts presentation with directional relationship indicators for better clarity
  • Better entity information display with cleaner formatting and well-organized metadata sections

…text (R71)

TextFormatter.swift:
- brain_search: XML envelope, markers (◇ chunks, ◆ entities),
  relevance tiers (high/medium/low dots), source label + date + project,
  smart sentence-boundary content cutting
- brain_entity: XML envelope, outgoing/incoming relation sections,
  UPPERCASE relation labels, grouped by type
- KG facts: UPPERCASE labels, outgoing/incoming split
- New helpers: escapeXML(), smartCutoff() for sentence boundaries

SearchResult.swift:
- Add contentType, sessionID fields (from existing SQL SELECT)
- Add relevanceTier and sourceLabel computed properties

MCPRouter.swift:
- Divider between KG section and search results

Before: score:28.52  imp:4  rt-9102edee-
After:  high-relevance | from: conversation | 2026-04-03 | project: orchestrator

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@EtanHey
Copy link
Copy Markdown
Owner Author

EtanHey commented Apr 3, 2026

@coderabbitai review

Copy link
Copy Markdown

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 3, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 3, 2026

📝 Walkthrough

Walkthrough

Output formatting has been overhauled across the TextFormatter to use XML-like wrappers and structured metadata rendering. SearchResult model now includes content type and session tracking with derived relevance tier and source labels. MCPRouter integrates a separator line between knowledge graph facts and search results.

Changes

Cohort / File(s) Summary
TextFormatter Formatting Overhaul
brain-bar/Sources/BrainBar/Formatting/TextFormatter.swift
Replaced box-drawing output with XML-like wrappers (<brain_search>, <brain_entity>). Refactored formatSearchResults to include metadata composition from relevance tier, source label, and project. Updated formatKGFacts with section headers and directional relation arrows. Enhanced formatEntitySimple with grouped outgoing/incoming relations and bullet-list metadata. Added escapeXML(_:) and smartTruncate(_:maxLen:) helper functions.
MCPRouter Integration
brain-bar/Sources/BrainBar/MCPRouter.swift
Added separator line (━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━) between KG facts and search result sections in handleBrainSearch output.
SearchResult Model Extension
brain-bar/Sources/BrainBar/Models/SearchResult.swift
Added stored properties contentType and sessionID to track content source and session context. Added computed properties relevanceTier (score-derived discrete levels) and sourceLabel (human-readable content type mapping). Updated all initializer paths to populate new fields with defaults.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 Twitches whiskers with glee
XML tags wrap the search so neat,
Relevance tiers hop with grace,
Relations arrow through the space,
Smart truncation bounds our words—
The finest formatting ever heard! 🌟

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.18% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: a redesign of MCP text output format to v2 with XML envelopes, relevance tiers, and source context, as confirmed by the detailed changes across TextFormatter, SearchResult, and MCPRouter files.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/mcp-text-format-v2

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@EtanHey EtanHey merged commit 58ea11c into main Apr 3, 2026
5 checks passed
@EtanHey EtanHey deleted the feat/mcp-text-format-v2 branch April 3, 2026 23:28
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