@@ -23,8 +23,10 @@ type ClientSession interface {
2323type SessionWithTools interface {
2424 ClientSession
2525 // GetSessionTools returns the tools specific to this session, if any
26+ // This method must be thread-safe for concurrent access
2627 GetSessionTools () map [string ]ServerTool
2728 // SetSessionTools sets tools specific to this session
29+ // This method must be thread-safe for concurrent access
2830 SetSessionTools (tools map [string ]ServerTool )
2931}
3032
@@ -222,6 +224,7 @@ func (s *MCPServer) AddSessionTools(sessionID string, tools ...ServerTool) error
222224 return ErrSessionDoesNotSupportTools
223225 }
224226
227+ // Get existing tools (this should return a thread-safe copy)
225228 sessionTools := session .GetSessionTools ()
226229
227230 // Create a new map to avoid concurrent modification issues
@@ -239,6 +242,7 @@ func (s *MCPServer) AddSessionTools(sessionID string, tools ...ServerTool) error
239242 newSessionTools [tool .Tool .Name ] = tool
240243 }
241244
245+ // Set the tools (this should be thread-safe)
242246 session .SetSessionTools (newSessionTools )
243247
244248 // Send notification only to this session
@@ -272,6 +276,7 @@ func (s *MCPServer) DeleteSessionTools(sessionID string, names ...string) error
272276 return ErrSessionDoesNotSupportTools
273277 }
274278
279+ // Get existing tools (this should return a thread-safe copy)
275280 sessionTools := session .GetSessionTools ()
276281 if sessionTools == nil {
277282 return nil
@@ -290,6 +295,7 @@ func (s *MCPServer) DeleteSessionTools(sessionID string, names ...string) error
290295 delete (newSessionTools , name )
291296 }
292297
298+ // Set the tools (this should be thread-safe)
293299 session .SetSessionTools (newSessionTools )
294300
295301 // Send notification only to this session
0 commit comments