Skip to content

Commit bde7c06

Browse files
committed
perf: release Mutex eraly for performance
1 parent 33c98f1 commit bde7c06

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

server/server.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -421,11 +421,11 @@ func (s *MCPServer) AddResource(
421421
}
422422

423423
s.resourcesMu.Lock()
424-
defer s.resourcesMu.Unlock()
425424
s.resources[resource.URI] = resourceEntry{
426425
resource: resource,
427426
handler: handler,
428427
}
428+
s.resourcesMu.Unlock()
429429

430430
// When the list of available resources changes, servers that declared the listChanged capability SHOULD send a notification
431431
if s.capabilities.resources.listChanged {
@@ -466,11 +466,11 @@ func (s *MCPServer) AddResourceTemplate(
466466

467467

468468
s.resourcesMu.Lock()
469-
defer s.resourcesMu.Unlock()
470469
s.resourceTemplates[template.URITemplate.Raw()] = resourceTemplateEntry{
471470
template: template,
472471
handler: handler,
473472
}
473+
s.resourcesMu.Unlock()
474474

475475
// When the list of available resources changes, servers that declared the listChanged capability SHOULD send a notification
476476
if s.capabilities.resources.listChanged {
@@ -495,9 +495,9 @@ func (s *MCPServer) AddPrompt(prompt mcp.Prompt, handler PromptHandlerFunc) {
495495
}
496496

497497
s.promptsMu.Lock()
498-
defer s.promptsMu.Unlock()
499498
s.prompts[prompt.Name] = prompt
500499
s.promptHandlers[prompt.Name] = handler
500+
s.promptsMu.Unlock()
501501

502502
// When the list of available resources changes, servers that declared the listChanged capability SHOULD send a notification.
503503
if s.capabilities.prompts.listChanged {

0 commit comments

Comments
 (0)