Skip to content
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

Add an optional 'size' field to the Resource type. #132

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

evalstate
Copy link

Adds an optional 'size' field to the Resource type. The 'size' represents the raw size in bytes (before encoding or tokenization).

This can be used by the Client/Host Application to pre-emptively estimate Context Window usage and make informed decisions about resource handling before attempting to load or process resources.

Motivation and Context

When working with LLMs, it's crucial to manage context window limitations effectively. This addition allows Host/Client applications to make smarter decisions about resource handling before attempting to process them.

For example:

  • UI clients can warn users before attempting to process files that would exceed context limits
  • Host applications can implement pre-filtering or chunking strategies based on resource sizes
  • Better progress indicators for resource loading and processing
  • Applications like Claude Analysis Tool would be able to estimate whether an application log file could be handled within the context window, or needs to be mounted in a Root or summarized first.

How Has This Been Tested?

Schema change only - no runtime implications to test. SDK implementations will need their own testing coverage when incorporating this field.

Breaking Changes

No breaking changes:

  • Field is optional in the schema
  • Existing implementations will continue to work without modification
  • SDK updates can be made in minor version updates

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

This change aligns with common patterns in file system and storage APIs where size information is readily available. It provides valuable metadata for client applications while maintaining backward compatibility.

The size field specifically represents raw byte size to avoid confusion with token counts or other encoded sizes. This distinction is documented in the schema comments to prevent misuse.

@evalstate evalstate changed the title Feature/resource size Add an optional 'size' field to the Resource type. Jan 7, 2025
jspahrsummers
jspahrsummers previously approved these changes Jan 8, 2025
Copy link
Member

@jspahrsummers jspahrsummers left a comment

Choose a reason for hiding this comment

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

Thanks, this is a great idea! Just one wording nit, but I'm happy with this.

Tagging in @dsp-ant for second approval.

schema/schema.ts Outdated Show resolved Hide resolved
@jspahrsummers jspahrsummers requested a review from dsp-ant January 8, 2025 13:12
Improved wording

Co-authored-by: Justin Spahr-Summers <[email protected]>
@dsp-ant
Copy link
Member

dsp-ant commented Jan 10, 2025

This needs to rebased to be moved into draft

@jspahrsummers
Copy link
Member

@dsp-ant This is backwards compatible, so I think it can be additive to the last release, no?

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.

4 participants