Skip to content

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

Conversation

spachava753
Copy link
Contributor

This change introduces a new method, ServerCapabilities(), on the ClientSession. This allows a client to inspect the capabilities of the connected server after the initialization handshake.

Previously, the capability-related structs were unexported, and the client session did not provide a way to access them. This change exports the ServerCapabilities type and related structs, making them part of the public API. The ServerCapabilities() method returns a deep copy of the capabilities to prevent accidental modification of the session's internal state.

In addition, this commit also introduces a .gitignore file to prevent tracking of unwanted local files, such as generated files and IDE-specific configurations.

This change introduces a new method, `ServerCapabilities()`, on the `ClientSession`. This allows a client to inspect the capabilities of the connected server after the initialization handshake.

Previously, the capability-related structs were unexported, and the client session did not provide a way to access them. This change exports the `ServerCapabilities` type and related structs, making them part of the public API. The `ServerCapabilities()` method returns a deep copy of the capabilities to prevent accidental modification of the session's internal state.

In addition, this commit also introduces a `.gitignore` file to prevent tracking of unwanted local files, such as generated files and IDE-specific configurations.
@spachava753
Copy link
Contributor Author

I filed an issue (#166) earlier, and wanted to create a PR that could serve as a possible implementation, if the feature from the issue gets approved to be implemented

@@ -0,0 +1,27 @@
### Go.AllowList template
Copy link
Contributor

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

@@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

/cc @samthanawalla @findleyr

Copy link
Contributor

@samthanawalla samthanawalla Jul 30, 2025

Choose a reason for hiding this comment

The 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.

@@ -907,46 +907,51 @@ type Implementation struct {
Version string `json:"version"`
}

// CompletionCapabilities represents server capabilities for argument autocompletion suggestions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We say "is" or "are" instead of represents.
Change throughout.

@spachava753
Copy link
Contributor Author

@jba @samthanawalla @findleyr I've opened a new PR to address the comments and expose the entire initialized result rather than just the server capabilities via a ClientSession method at #228

@jba
Copy link
Contributor

jba commented Aug 11, 2025

Can we close this PR, since #228 is a replacement?

@jba
Copy link
Contributor

jba commented Aug 18, 2025

superseded

@jba jba closed this Aug 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants