Skip to content

feat: add progress token support and extend Request interface #352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

tzolov
Copy link
Contributor

@tzolov tzolov commented Jun 29, 2025

Update McpSchema to enable progress tracking capabilities for long-running MCP operations.
Add progress token support and extend Request interface with meta parameter functionality. Related to the MCP Progression Specification

  • Add PaginatedRequest and ReadResourceRequest to Request sealed interface
  • Add default meta() and progressToken() methods to Request interface
  • Add _meta parameter support to request classes:
    • ReadResourceRequest, GetPromptRequest, CallToolRequest
    • CreateMessageRequest, ElicitRequest, CompleteRequest, PaginatedRequest
  • Add builder methods for progress token configuratio
  • Add message field to ProgressNotification
  • Maintain backward compatibility with existing constructors

Related to #300, #351

Motivation and Context

This change updates the McpSchema to provide the foundational schema support needed for progress tracking in long-running MCP operations. By adding meta parameter support and extending the Request interface, this enables future implementation of progress notifications for operations like resource reading, tool execution, and message creation. This schema update is a prerequisite for implementing progress tracking functionality that will improve user experience during long-running operations.

How Has This Been Tested?

  • Added unit tests for all new request types with meta parameter support
  • Tested progress token extraction from meta parameters
  • Validated builder pattern implementations for all affected request classes
  • Confirmed schema changes don't break existing functionality

Breaking Changes

Yes, this contains breaking changes:

  1. Sealed Interface Extension: Added PaginatedRequest and ReadResourceRequest to the Request sealed interface permits list. This is a breaking change because:

    • Existing pattern matching or switch expressions on Request types will need to handle the new cases
    • Code with exhaustive switch statements without default cases will fail to compile
    • Any code that performs exhaustive checks on Request implementations will need updates
  2. Recommended Migration:

    • Add default cases to existing switch statements on Request types
    • Update pattern matching to handle new request types
    • Review any code that performs exhaustive checks on Request implementations

Non-breaking schema additions:

  • All existing constructors and methods remain functional
  • New meta parameter support is fully backward compatible
  • Default implementations for meta() and progressToken() methods return null when not set

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

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

Additional context

Schema Updates Overview:

This PR focuses solely on updating the McpSchema class to provide the necessary schema foundation for progress tracking. The actual progress tracking implementation will be built on top of these schema changes.

Key Schema Changes:

  • Request Interface Extension: Added PaginatedRequest and ReadResourceRequest to the sealed interface permits list ⚠️ BREAKING CHANGE
  • Meta Parameter Schema: Added _meta field support to all major request types for carrying progress tokens and other metadata
  • Progress Token Convenience Methods: Added default progressToken() method that extracts progress tokens from meta parameters
  • Builder Pattern Enhancement: Extended builders with meta() and progressToken() methods for fluent API usage
  • Progress Notification Schema: Enhanced ProgressNotification with optional message field for contextual updates

Migration Guide:

For users with existing switch statements on Request types:

Before:

switch (request) {
    case InitializeRequest init -> handleInit(init);
    case CallToolRequest call -> handleCall(call);
    // ... other cases
}

After:

switch (request) {
    case InitializeRequest init -> handleInit(init);
    case CallToolRequest call -> handleCall(call);
    case PaginatedRequest paginated -> handlePaginated(paginated);
    case ReadResourceRequest read -> handleRead(read);
    // ... other cases
    default -> throw new IllegalArgumentException("Unknown request type: " + request);
}

- Add PaginatedRequest and ReadResourceRequest to Request sealed interface
- Add default meta() and progressToken() methods to Request interface
- Add _meta parameter support to request classes:
  - ReadResourceRequest, GetPromptRequest, CallToolRequest
  - CreateMessageRequest, ElicitRequest, CompleteRequest, PaginatedRequest
- Add builder methods for progress token configuration
- Add message field to ProgressNotification
- Maintain backward compatibility with existing constructors

Signed-off-by: Christian Tzolov <[email protected]>
@tzolov tzolov added this to the 0.11.0 milestone Jun 29, 2025
This was referenced Jun 29, 2025
Copy link

@134130 134130 left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants