Add FileResourceContents for file-based resource results#225
Open
liliankasem wants to merge 3 commits intomainfrom
Open
Add FileResourceContents for file-based resource results#225liliankasem wants to merge 3 commits intomainfrom
liliankasem wants to merge 3 commits intomainfrom
Conversation
2f661d5 to
9fc443b
Compare
08c354c to
8dc82e3
Compare
Introduce FileResourceContents type that allows resource functions to return file paths instead of manually reading files. The framework handles file I/O and text/binary detection automatically. New types: - FileResourceContents: public model with Path (required) and MimeType (optional) - FunctionsMcpResourceResultMiddleware: reads files and converts to TextResourceContents or BlobResourceContents based on MIME type - MimeTypeHelper: determines text vs binary encoding from MIME type - McpResourceResult: SDK-side model matching host's expected shape Features: - Relative paths resolved against AppContext.BaseDirectory automatically - MIME-based encoding: text/* and application/json,xml,js → UTF-8 text; structured suffixes (+json, +xml) → text; everything else → base64 blob - Falls back to attribute MimeType from binding context when not set - Null/empty MIME type defaults to text Closes #158 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
8dc82e3 to
9b8d7ff
Compare
…HelperTests - Seal FileResourceContents to match codebase conventions - Revert WorkerMcpJsonContext rename back to McpJsonContext - Extract MimeTypeHelper tests into dedicated test class - Add test for lowercase mimeType binding data key Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue describing the changes in this PR
resolves #158
Pull request checklist
release_notes.mdAdditional information
Introduces FileResourceContents, a new return type for resource functions that abstracts away file I/O. Instead of manually reading files with
Path.Combine(AppContext.BaseDirectory, ...)+File.ReadAllText/ReadAllBytes, users return a FileResourceContents with just a Path — the framework handles the rest.