Skip to content

Commit 53a6720

Browse files
fix: keep all resources registered for resources/read requests
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.
1 parent 676956f commit 53a6720

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

pkg/inventory/registry.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ const (
9191
// - MCPMethodToolsList: All available tools (no resources/prompts)
9292
// - MCPMethodToolsCall: Only the named tool
9393
// - MCPMethodResourcesList, MCPMethodResourcesTemplatesList: All available resources (no tools/prompts)
94-
// - MCPMethodResourcesRead: Only the named resource template
94+
// - MCPMethodResourcesRead: All resources (SDK handles URI template matching)
9595
// - MCPMethodPromptsList: All available prompts (no tools/resources)
9696
// - MCPMethodPromptsGet: Only the named prompt
9797
// - Unknown methods: Empty (no items registered)
@@ -134,10 +134,8 @@ func (r *Inventory) ForMCPRequest(method string, itemName string) *Inventory {
134134
case MCPMethodResourcesList, MCPMethodResourcesTemplatesList:
135135
result.tools, result.prompts = nil, nil
136136
case MCPMethodResourcesRead:
137+
// Keep all resources registered - SDK handles URI template matching internally
137138
result.tools, result.prompts = nil, nil
138-
if itemName != "" {
139-
result.resourceTemplates = r.filterResourcesByURI(itemName)
140-
}
141139
case MCPMethodPromptsList:
142140
result.tools, result.resourceTemplates = nil, nil
143141
case MCPMethodPromptsGet:

pkg/inventory/registry_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -775,17 +775,15 @@ func TestForMCPRequest_ResourcesRead(t *testing.T) {
775775
}
776776

777777
reg := NewBuilder().SetResources(resources).WithToolsets([]string{"all"}).Build()
778-
filtered := reg.ForMCPRequest(MCPMethodResourcesRead, "repo://{owner}/{repo}")
778+
// Pass a concrete URI - all resources remain registered, SDK handles matching
779+
filtered := reg.ForMCPRequest(MCPMethodResourcesRead, "repo://owner/repo")
779780

781+
// All resources should be available - SDK handles URI template matching internally
780782
available := filtered.AvailableResourceTemplates(context.Background())
781-
if len(available) != 1 {
782-
t.Fatalf("Expected 1 resource for resources/read, got %d", len(available))
783-
}
784-
if available[0].Template.URITemplate != "repo://{owner}/{repo}" {
785-
t.Errorf("Expected URI template 'repo://{owner}/{repo}', got %q", available[0].Template.URITemplate)
783+
if len(available) != 2 {
784+
t.Fatalf("Expected 2 resources for resources/read (SDK handles matching), got %d", len(available))
786785
}
787786
}
788-
789787
func TestForMCPRequest_PromptsList(t *testing.T) {
790788
tools := []ServerTool{
791789
mockTool("tool1", "repos", true),

0 commit comments

Comments
 (0)