Skip to content

Commit 44ad14b

Browse files
authored
perf: release Mutex eraly for performance (#213)
1 parent 2915b79 commit 44ad14b

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
@@ -320,11 +320,11 @@ func (s *MCPServer) AddResource(
320320
}
321321

322322
s.resourcesMu.Lock()
323-
defer s.resourcesMu.Unlock()
324323
s.resources[resource.URI] = resourceEntry{
325324
resource: resource,
326325
handler: handler,
327326
}
327+
s.resourcesMu.Unlock()
328328

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

366366

367367
s.resourcesMu.Lock()
368-
defer s.resourcesMu.Unlock()
369368
s.resourceTemplates[template.URITemplate.Raw()] = resourceTemplateEntry{
370369
template: template,
371370
handler: handler,
372371
}
372+
s.resourcesMu.Unlock()
373373

374374
// When the list of available resources changes, servers that declared the listChanged capability SHOULD send a notification
375375
if s.capabilities.resources.listChanged {
@@ -394,9 +394,9 @@ func (s *MCPServer) AddPrompt(prompt mcp.Prompt, handler PromptHandlerFunc) {
394394
}
395395

396396
s.promptsMu.Lock()
397-
defer s.promptsMu.Unlock()
398397
s.prompts[prompt.Name] = prompt
399398
s.promptHandlers[prompt.Name] = handler
399+
s.promptsMu.Unlock()
400400

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

0 commit comments

Comments
 (0)