Skip to content

Implement fetching resources with array support#209

Open
gophergogo wants to merge 5 commits intomainfrom
impl-fetch-resources
Open

Implement fetching resources with array support#209
gophergogo wants to merge 5 commits intomainfrom
impl-fetch-resources

Conversation

@gophergogo
Copy link
Copy Markdown
Collaborator

No description provided.

gophergogo 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
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.

1 participant