Aligns Resources and Resource Templates with the pattern used by Tools and Prompts, and introduces auto-routing. #217
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.
Aligns Resources and Resource Templates with the pattern used by Tools and Prompts, and introduces auto-routing.
Motivation and Context
Using Tools in this SDK was straightforward, but when I tried adding Resources, it was confusing. The interface is totally different, the documentation is sparse, and there are barely any examples.
Unlike Tools, the lack of support for encapsulating resources into dedicated classes, combined with the need for manual registration, made it difficult to organize code efficiently.
I checked the issues and found I'm not the only one with this problem (see #98).
How Has This Been Tested?
Breaking Changes
No. Backward compatibility is fully preserved.
Types of changes
Checklist
Additional context
While researching the MCP documentation, I noticed a reference to -32002 for "Resource not found" errors. I initially began refactoring JsonRpcHandler to centralize exception handling to support this. However, I suspect the documentation might be outdated and that the standard JSON-RPC error -32602 (Invalid params) is actually the correct implementation.
Since I am not completely sure which code is correct, I reverted the error handling refactor to keep this PR focused. Could you confirm if -32602 is the standard? I can submit a separate PR if a broader change to error codes is required.