Skip to content

Conversation

@SamMorrowDrums
Copy link
Collaborator

Summary

Fixes resources/read returning "Resource not found" for valid URIs when using ForMCPRequest optimization.

Problem

The ForMCPRequest optimization was incorrectly filtering resources by doing an exact string match between the URI template pattern and the concrete URI in filterResourcesByURI:

// Before: exact string match - never works!
if r.resourceTemplates[i].Template.URITemplate == uri {

This would never match because:

  • Template: repo://{owner}/{repo}/contents{/path*}
  • Concrete URI: repo://SamMorrowDrums/remarkable-mcp/contents/server.py

Solution

Instead of implementing template matching in the inventory, we simply keep all resources registered for resources/read requests and let the SDK handle URI template matching internally (which it already does correctly via uritemplate.Regexp().MatchString()).

This is the same approach used for resources/list and resources/templates/list.

Changes

  • ForMCPRequest no longer filters resources for MCPMethodResourcesRead
  • Updated doc comment to reflect new behavior
  • Updated test to expect all resources to be available

Testing

  • All existing tests pass
  • Verified the SDK's AddResourceTemplate correctly matches URIs using RFC 6570 template patterns

The ForMCPRequest optimization was incorrectly filtering resources by
doing an exact string match between the URI template pattern and the
concrete URI. This would never match because templates like
'repo://{owner}/{repo}/contents{/path*}' don't match concrete URIs
like 'repo://owner/repo/contents/file.py'.

Instead of implementing template matching in the inventory, we simply
keep all resources registered for resources/read requests and let the
SDK handle URI template matching internally (which it already does
correctly via uritemplate.Regexp().MatchString()).

This fixes resources/read returning 'Resource not found' for valid URIs.
@SamMorrowDrums SamMorrowDrums requested a review from a team as a code owner January 12, 2026 10:47
Copilot AI review requested due to automatic review settings January 12, 2026 10:47
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where resources/read requests incorrectly returned "Resource not found" errors for valid URIs when using the ForMCPRequest optimization in the remote server scenario.

Changes:

  • Removed incorrect URI filtering logic that performed exact string matching between URI templates and concrete URIs (which never matched)
  • Updated ForMCPRequest to keep all resources registered for resources/read requests, delegating URI template matching to the SDK
  • Updated test expectations and documentation to reflect the new behavior

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
pkg/inventory/registry.go Removed broken filterResourcesByURI call in ForMCPRequest for MCPMethodResourcesRead case; updated doc comment to document that SDK handles matching
pkg/inventory/registry_test.go Updated TestForMCPRequest_ResourcesRead to pass concrete URI and expect all resources to be available (SDK handles matching)

@SamMorrowDrums SamMorrowDrums merged commit c44ce2e into main Jan 12, 2026
16 checks passed
@SamMorrowDrums SamMorrowDrums deleted the fix-resource-uri-matching branch January 12, 2026 13:19
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.

3 participants