-
Notifications
You must be signed in to change notification settings - Fork 146
feat(mcp): expose server capabilities to client #173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
### Go.AllowList template | ||
# Allowlisting gitignore template for GO projects prevents us | ||
# from adding various unwanted local files, such as generated | ||
# files, developer configurations or IDE-specific files etc. | ||
# | ||
# Recommended: Go.AllowList.gitignore | ||
|
||
# Ignore everything | ||
* | ||
|
||
# But not these files... | ||
!/.gitignore | ||
|
||
!*.go | ||
!go.* | ||
|
||
!*.sh | ||
|
||
!README.md | ||
!CONTRIBUTING.md | ||
!LICENSE | ||
|
||
!design/** | ||
!.github/** | ||
|
||
# ...even if they are in subdirectories | ||
!*/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -174,6 +174,59 @@ func (cs *ClientSession) ID() string { | |
return cs.mcpConn.SessionID() | ||
} | ||
|
||
// ServerCapabilities returns a copy of the server capabilities obtained during initialization. | ||
// If the session has not been initialized or capabilities are not available, it returns nil. | ||
func (cs *ClientSession) ServerCapabilities() *ServerCapabilities { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we can just use an exported field. The doc will say not to modify it, but even if someone does, they're only hurting themselves, as far as I can tell. Or if we're not sure, let's use the function, but not bother copying until we discover a case where it could matter. But really I think the field suffices. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with not copying right now. I think we should go with the cs.ServerCapabilities() function because cs.InitializeResult.Capabilities is a bit cumbersome/less obvious to use. Plus, like you said, we can add copying to ServerCapabilities later. |
||
if cs.initializeResult == nil || cs.initializeResult.Capabilities == nil { | ||
return nil | ||
} | ||
|
||
// Create a copy of the capabilities | ||
caps := &ServerCapabilities{} | ||
|
||
// Copy experimental capabilities | ||
if cs.initializeResult.Capabilities.Experimental != nil { | ||
caps.Experimental = make(map[string]struct{}) | ||
for k, v := range cs.initializeResult.Capabilities.Experimental { | ||
caps.Experimental[k] = v | ||
} | ||
} | ||
|
||
// Copy completion capabilities | ||
if cs.initializeResult.Capabilities.Completions != nil { | ||
caps.Completions = &CompletionCapabilities{} | ||
} | ||
|
||
// Copy logging capabilities | ||
if cs.initializeResult.Capabilities.Logging != nil { | ||
caps.Logging = &LoggingCapabilities{} | ||
} | ||
|
||
// Copy prompt capabilities | ||
if cs.initializeResult.Capabilities.Prompts != nil { | ||
caps.Prompts = &PromptCapabilities{ | ||
ListChanged: cs.initializeResult.Capabilities.Prompts.ListChanged, | ||
} | ||
} | ||
|
||
// Copy resource capabilities | ||
if cs.initializeResult.Capabilities.Resources != nil { | ||
caps.Resources = &ResourceCapabilities{ | ||
ListChanged: cs.initializeResult.Capabilities.Resources.ListChanged, | ||
Subscribe: cs.initializeResult.Capabilities.Resources.Subscribe, | ||
} | ||
} | ||
|
||
// Copy tool capabilities | ||
if cs.initializeResult.Capabilities.Tools != nil { | ||
caps.Tools = &ToolCapabilities{ | ||
ListChanged: cs.initializeResult.Capabilities.Tools.ListChanged, | ||
} | ||
} | ||
|
||
return caps | ||
} | ||
|
||
// Close performs a graceful close of the connection, preventing new requests | ||
// from being handled, and waiting for ongoing requests to return. Close then | ||
// terminates the connection. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -307,7 +307,7 @@ type InitializeResult struct { | |
// This property is reserved by the protocol to allow clients and servers to | ||
// attach additional metadata to their responses. | ||
Meta `json:"_meta,omitempty"` | ||
Capabilities *serverCapabilities `json:"capabilities"` | ||
Capabilities *ServerCapabilities `json:"capabilities"` | ||
// Instructions describing how to use the server and its features. | ||
// | ||
// This can be used by clients to improve the LLM's understanding of available | ||
|
@@ -907,46 +907,51 @@ type Implementation struct { | |
Version string `json:"version"` | ||
} | ||
|
||
// CompletionCapabilities represents server capabilities for argument autocompletion suggestions. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We say "is" or "are" instead of represents. |
||
// Present if the server supports argument autocompletion suggestions. | ||
type completionCapabilities struct{} | ||
type CompletionCapabilities struct{} | ||
|
||
// LoggingCapabilities represents server capabilities for sending log messages to the client. | ||
// Present if the server supports sending log messages to the client. | ||
type loggingCapabilities struct{} | ||
type LoggingCapabilities struct{} | ||
|
||
// PromptCapabilities represents server capabilities for prompt templates. | ||
// Present if the server offers any prompt templates. | ||
type promptCapabilities struct { | ||
type PromptCapabilities struct { | ||
// Whether this server supports notifications for changes to the prompt list. | ||
ListChanged bool `json:"listChanged,omitempty"` | ||
} | ||
|
||
// ResourceCapabilities represents server capabilities for resources. | ||
// Present if the server offers any resources to read. | ||
type resourceCapabilities struct { | ||
type ResourceCapabilities struct { | ||
// Whether this server supports notifications for changes to the resource list. | ||
ListChanged bool `json:"listChanged,omitempty"` | ||
// Whether this server supports subscribing to resource updates. | ||
Subscribe bool `json:"subscribe,omitempty"` | ||
} | ||
|
||
// Capabilities that a server may support. Known capabilities are defined here, | ||
// ServerCapabilities represents the capabilities that a server may support. Known capabilities are defined here, | ||
// in this schema, but this is not a closed set: any server can define its own, | ||
// additional capabilities. | ||
type serverCapabilities struct { | ||
type ServerCapabilities struct { | ||
// Present if the server supports argument autocompletion suggestions. | ||
Completions *completionCapabilities `json:"completions,omitempty"` | ||
Completions *CompletionCapabilities `json:"completions,omitempty"` | ||
// Experimental, non-standard capabilities that the server supports. | ||
Experimental map[string]struct{} `json:"experimental,omitempty"` | ||
// Present if the server supports sending log messages to the client. | ||
Logging *loggingCapabilities `json:"logging,omitempty"` | ||
Logging *LoggingCapabilities `json:"logging,omitempty"` | ||
// Present if the server offers any prompt templates. | ||
Prompts *promptCapabilities `json:"prompts,omitempty"` | ||
Prompts *PromptCapabilities `json:"prompts,omitempty"` | ||
// Present if the server offers any resources to read. | ||
Resources *resourceCapabilities `json:"resources,omitempty"` | ||
Resources *ResourceCapabilities `json:"resources,omitempty"` | ||
// Present if the server offers any tools to call. | ||
Tools *toolCapabilities `json:"tools,omitempty"` | ||
Tools *ToolCapabilities `json:"tools,omitempty"` | ||
} | ||
|
||
// ToolCapabilities represents server capabilities for tools. | ||
// Present if the server offers any tools to call. | ||
type toolCapabilities struct { | ||
type ToolCapabilities struct { | ||
// Whether this server supports notifications for changes to the tool list. | ||
ListChanged bool `json:"listChanged,omitempty"` | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this file from PR