Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions mcp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ type ServerOptions struct {
SubscribeHandler func(context.Context, *SubscribeParams) error
// Function called when a client session unsubscribes from a resource.
UnsubscribeHandler func(context.Context, *UnsubscribeParams) error
// If true, advertises the prompts capability during initialization,
// even if no prompts have been registered.
HasPrompts bool
// If true, advertises the resources capability during initialization,
// even if no resources have been registered.
HasResources bool
// If true, advertises the tools capability during initialization,
// even if no tools have been registered.
HasTools bool
}

// NewServer creates a new MCP server. The resulting server has no features:
Expand Down Expand Up @@ -230,16 +239,17 @@ func (s *Server) capabilities() *serverCapabilities {
defer s.mu.Unlock()

caps := &serverCapabilities{
// TODO(samthanawalla): check for completionHandler before advertising capability.
Completions: &completionCapabilities{},
Logging: &loggingCapabilities{},
}
if s.tools.len() > 0 {
if s.opts.HasTools || s.tools.len() > 0 {
caps.Tools = &toolCapabilities{ListChanged: true}
}
if s.prompts.len() > 0 {
if s.opts.HasPrompts || s.prompts.len() > 0 {
caps.Prompts = &promptCapabilities{ListChanged: true}
}
if s.resources.len() > 0 || s.resourceTemplates.len() > 0 {
if s.opts.HasResources || s.resources.len() > 0 || s.resourceTemplates.len() > 0 {
caps.Resources = &resourceCapabilities{ListChanged: true}
if s.opts.SubscribeHandler != nil {
caps.Resources.Subscribe = true
Expand Down
16 changes: 16 additions & 0 deletions mcp/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,22 @@ func TestServerCapabilities(t *testing.T) {
Tools: &toolCapabilities{ListChanged: true},
},
},
{
name: "With initial capabilities",
configureServer: func(s *Server) {},
serverOpts: ServerOptions{
HasPrompts: true,
HasResources: true,
HasTools: true,
},
wantCapabilities: &serverCapabilities{
Completions: &completionCapabilities{},
Logging: &loggingCapabilities{},
Prompts: &promptCapabilities{ListChanged: true},
Resources: &resourceCapabilities{ListChanged: true},
Tools: &toolCapabilities{ListChanged: true},
},
},
}

for _, tc := range testCases {
Expand Down
Loading