Skip to content

Commit 29af4f0

Browse files
committed
[session-resources] address feedback
1 parent d865b5c commit 29af4f0

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

server/server.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -823,18 +823,18 @@ func (s *MCPServer) handleListResources(
823823
s.resourcesMu.RLock()
824824
resources := make([]mcp.Resource, 0, len(s.resources))
825825

826-
// Get all resource names for consistent ordering
827-
resourceNames := make([]string, 0, len(s.resources))
828-
for name := range s.resources {
829-
resourceNames = append(resourceNames, name)
826+
// Get all resource URIs for consistent ordering
827+
resourceURIs := make([]string, 0, len(s.resources))
828+
for uri := range s.resources {
829+
resourceURIs = append(resourceURIs, uri)
830830
}
831831

832-
// Sort the resource names for consistent ordering
833-
sort.Strings(resourceNames)
832+
// Sort the resource URIs for consistent ordering
833+
sort.Strings(resourceURIs)
834834

835835
// Add resources in sorted order
836-
for _, name := range resourceNames {
837-
resources = append(resources, s.resources[name].resource)
836+
for _, uri := range resourceURIs {
837+
resources = append(resources, s.resources[uri].resource)
838838
}
839839
s.resourcesMu.RUnlock()
840840

@@ -849,12 +849,12 @@ func (s *MCPServer) handleListResources(
849849

850850
// Add global resources first
851851
for _, resource := range resources {
852-
resourceMap[resource.Name] = resource
852+
resourceMap[resource.URI] = resource
853853
}
854854

855855
// Then override with session-specific resources
856-
for name, serverResource := range sessionResources {
857-
resourceMap[name] = serverResource.Resource
856+
for uri, serverResource := range sessionResources {
857+
resourceMap[uri] = serverResource.Resource
858858
}
859859

860860
// Convert back to slice
@@ -865,7 +865,7 @@ func (s *MCPServer) handleListResources(
865865

866866
// Sort again to maintain consistent ordering
867867
sort.Slice(resources, func(i, j int) bool {
868-
return resources[i].Name < resources[j].Name
868+
return resources[i].URI < resources[j].URI
869869
})
870870
}
871871
}

server/session_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@ func (f *sessionTestClientWithTools) SetSessionTools(tools map[string]ServerTool
101101
f.sessionTools = toolsCopy
102102
}
103103

104-
// sessionTestClientWithTools implements the SessionWithTools interface for testing
104+
// sessionTestClientWithResources implements the SessionWithResources interface for testing
105105
type sessionTestClientWithResources struct {
106106
sessionID string
107107
notificationChannel chan mcp.JSONRPCNotification
108108
initialized bool
109109
sessionResources map[string]ServerResource
110-
mu sync.RWMutex // Mutex to protect concurrent access to sessionTools
110+
mu sync.RWMutex // Mutex to protect concurrent access to sessionResources
111111
}
112112

113113
func (f *sessionTestClientWithResources) SessionID() string {
@@ -206,7 +206,7 @@ func (f *sessionTestClientWithClientInfo) SetClientCapabilities(clientCapabiliti
206206
f.clientCapabilities.Store(clientCapabilities)
207207
}
208208

209-
// sessionTestClientWithTools implements the SessionWithLogging interface for testing
209+
// sessionTestClientWithLogging implements the SessionWithLogging interface for testing
210210
type sessionTestClientWithLogging struct {
211211
sessionID string
212212
notificationChannel chan mcp.JSONRPCNotification
@@ -245,6 +245,7 @@ func (f *sessionTestClientWithLogging) GetLogLevel() mcp.LoggingLevel {
245245
var (
246246
_ ClientSession = (*sessionTestClient)(nil)
247247
_ SessionWithTools = (*sessionTestClientWithTools)(nil)
248+
_ SessionWithResources = (*sessionTestClientWithResources)(nil)
248249
_ SessionWithLogging = (*sessionTestClientWithLogging)(nil)
249250
_ SessionWithClientInfo = (*sessionTestClientWithClientInfo)(nil)
250251
)

0 commit comments

Comments
 (0)