MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / capabilities

Method capabilities

mcp/server.go:557–605  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

555}
556
557func (s *Server) capabilities() *ServerCapabilities {
558 s.mu.Lock()
559 defer s.mu.Unlock()
560
561 // Start with user-provided capabilities as defaults, or use SDK defaults.
562 var caps *ServerCapabilities
563 if s.opts.Capabilities != nil {
564 // Deep copy the user-provided capabilities to avoid mutation.
565 caps = s.opts.Capabilities.clone()
566 } else {
567 // SDK defaults: only logging capability.
568 caps = &ServerCapabilities{
569 Logging: &LoggingCapabilities{},
570 }
571 }
572
573 // Augment with tools capability if tools exist or legacy HasTools is set.
574 if s.opts.HasTools || s.tools.len() > 0 {
575 if caps.Tools == nil {
576 caps.Tools = &ToolCapabilities{ListChanged: true}
577 }
578 }
579
580 // Augment with prompts capability if prompts exist or legacy HasPrompts is set.
581 if s.opts.HasPrompts || s.prompts.len() > 0 {
582 if caps.Prompts == nil {
583 caps.Prompts = &PromptCapabilities{ListChanged: true}
584 }
585 }
586
587 // Augment with resources capability if resources/templates exist or legacy HasResources is set.
588 if s.opts.HasResources || s.resources.len() > 0 || s.resourceTemplates.len() > 0 {
589 if caps.Resources == nil {
590 caps.Resources = &ResourceCapabilities{ListChanged: true}
591 }
592 if s.opts.SubscribeHandler != nil {
593 caps.Resources.Subscribe = true
594 }
595 }
596
597 // Augment with completions capability if handler is set.
598 if s.opts.CompletionHandler != nil {
599 if caps.Completions == nil {
600 caps.Completions = &CompletionCapabilities{}
601 }
602 }
603
604 return caps
605}
606
607func (s *Server) complete(ctx context.Context, req *CompleteRequest) (*CompleteResult, error) {
608 if s.opts.CompletionHandler == nil {

Callers 2

TestServerCapabilitiesFunction · 0.95
initializeMethod · 0.45

Calls 2

lenMethod · 0.80
cloneMethod · 0.45

Tested by 1

TestServerCapabilitiesFunction · 0.76