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

Method capabilities

mcp/client.go:203–246  ·  view source on GitHub ↗
(protocolVersion string)

Source from the content-addressed store, hash-verified

201}
202
203func (c *Client) capabilities(protocolVersion string) *ClientCapabilities {
204 // Start with user-provided capabilities as defaults, or use SDK defaults.
205 var caps *ClientCapabilities
206 if c.opts.Capabilities != nil {
207 // Deep copy the user-provided capabilities to avoid mutation.
208 caps = c.opts.Capabilities.clone()
209 } else {
210 // SDK defaults: roots with listChanged.
211 // (this was the default behavior at v1.0.0, and so cannot be changed)
212 caps = &ClientCapabilities{
213 RootsV2: &RootCapabilities{
214 ListChanged: true,
215 },
216 }
217 }
218
219 // Sync Roots from RootsV2 for backward compatibility (#607).
220 if caps.RootsV2 != nil {
221 caps.Roots = *caps.RootsV2
222 }
223
224 // Augment with sampling capability if a handler is set.
225 if c.opts.CreateMessageHandler != nil || c.opts.CreateMessageWithToolsHandler != nil {
226 if caps.Sampling == nil {
227 caps.Sampling = &SamplingCapabilities{}
228 if c.opts.CreateMessageWithToolsHandler != nil {
229 caps.Sampling.Tools = &SamplingToolsCapabilities{}
230 }
231 }
232 }
233
234 // Augment with elicitation capability if handler is set.
235 if c.opts.ElicitationHandler != nil {
236 if caps.Elicitation == nil {
237 caps.Elicitation = &ElicitationCapabilities{}
238 // Form elicitation was added in 2025-11-25; for older versions,
239 // {} is treated the same as {"form":{}}.
240 if protocolVersion >= protocolVersion20251125 {
241 caps.Elicitation.Form = &FormElicitationCapabilities{}
242 }
243 }
244 }
245 return caps
246}
247
248// Connect begins an MCP session by connecting to a server over the given
249// transport. The resulting session is initialized, and ready to use.

Callers 2

TestClientCapabilitiesFunction · 0.95
ConnectMethod · 0.95

Calls 1

cloneMethod · 0.45

Tested by 1

TestClientCapabilitiesFunction · 0.76