Implement fetching resources with array support#209
Open
gophergogo wants to merge 5 commits intomainfrom
Open
Conversation
added 5 commits
April 3, 2026 12:37
ResourceManager previously had no way to supply content for resources/read requests — readResource() returned hardcoded placeholder text. This follows the existing ToolRegistry/PromptRegistry pattern: registerResource() now accepts an optional handler that is invoked when a client reads the resource. readResource() now takes SessionContext& and delegates to the registered handler, throwing if a resource was registered without one.
handleReadResource was manually building {uri, contentCount} instead of
serializing ReadResourceResult. The MCP schema requires {contents: [...]}.
Use to_json(result) → ResponseResult(result_json), matching the pattern
used by handleCallTool and other handlers.
Example servers now pass ResourceReadHandler lambdas when registering resources, demonstrating how to supply actual content for resources/read requests instead of relying on the old placeholder behavior.
…rs (#206) 9 tests covering: - ReadResourceResult serialization produces {contents: [...]} per MCP schema - Text and blob resource contents serialize with correct fields - Multiple and empty contents arrays - ResourceManager dispatches to registered read handlers - Unknown URI returns empty result - Missing handler throws std::runtime_error - Handler receives correct URI for multi-resource dispatch - resources_served stat incremented on successful read
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.
No description provided.