Skip to content

Conversation

@e0ipso
Copy link
Contributor

@e0ipso e0ipso commented Jan 18, 2026

Split formatting logic from Reference classes into dedicated formatter classes:

  • ToolResultFormatter: Formats tool execution results into Content items
  • PromptResultFormatter: Formats prompt results into PromptMessage items
  • ResourceResultFormatter: Formats resource results into ResourceContents items

This refactor is a spin-off of #180 that:

  • Removes code duplication
  • Makes formatters independently testable and reusable
  • Reduces Reference classes

Motivation and Context

This will be needed to avoid code duplication in the upcoming runtime providers.

How Has This Been Tested?

Since this is a refactor, passing automated tests should be enough.

Breaking Changes

None.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactor

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Copy link
Member

@chr-hertel chr-hertel left a comment

Choose a reason for hiding this comment

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

Thanks @e0ipso 👍

@chr-hertel
Copy link
Member

Please sign your commits & I can merge :)

@chr-hertel chr-hertel added the Server Issues & PRs related to the Server component label Jan 18, 2026
@chr-hertel chr-hertel changed the title refactor: extract formatters into dedicated classes [Server] refactor: extract formatters into dedicated classes Jan 18, 2026
Split formatting logic from Reference classes into dedicated formatter classes:
- ToolResultFormatter: Formats tool execution results into Content items
- PromptResultFormatter: Formats prompt results into PromptMessage items
- ResourceResultFormatter: Formats resource results into ResourceContents items

This refactor:
- Eliminates 122 lines of code duplication between ResourceReference and
  ResourceTemplateReference (identical formatting logic)
- Improves code organization by separating formatting concerns from
  capability reference management
- Makes formatters independently testable and reusable
- Reduces Reference classes by ~450 lines while maintaining all functionality

Changes:
- Create src/Capability/Formatter/* with three formatter classes
- Update Reference classes to delegate to formatters instead of inline logic
- Add comprehensive test coverage for all formatter classes
- All existing tests pass; no behavioral changes
@e0ipso e0ipso force-pushed the refactor/extract-formatters branch from d41fa09 to 4b65a03 Compare January 18, 2026 21:07
@e0ipso
Copy link
Contributor Author

e0ipso commented Jan 18, 2026

@chr-hertel thanks for the review! I have rebased the commits into a single signed commit.

@chr-hertel chr-hertel merged commit ab4f686 into modelcontextprotocol:main Jan 18, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Server Issues & PRs related to the Server component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants