2.6 KiB
Support for MCP client features
%toc
Roots
MCP allows clients to specify a set of filesystem "roots". The SDK supports this as follows:
Client-side: The SDK client always has the roots.listChanged capability.
To add roots to a client, use the
Client.AddRoots
and
Client.RemoveRoots
methods. If any servers are already connected to the
client, a call to AddRoot or RemoveRoots will result in a
notifications/roots/list_changed notification to each connected server.
Server-side: To query roots from the server, use the
ServerSession.ListRoots
method. To receive notifications about root changes, set
ServerOptions.RootsListChangedHandler.
%include ../../mcp/client_example_test.go roots -
Sampling
Sampling is a way for servers to leverage the client's AI capabilities. It is implemented in the SDK as follows:
Client-side: To add the sampling capability to a client, set
ClientOptions.CreateMessageHandler.
This function is invoked whenever the server requests sampling.
Server-side: To use sampling from the server, call
ServerSession.CreateMessage.
%include ../../mcp/client_example_test.go sampling -
Elicitation
Elicitation allows servers to request user inputs. It is implemented in the SDK as follows:
Client-side: To add the elicitation capability to a client, set
ClientOptions.ElicitationHandler.
The elicitation handler must return a result that matches the requested schema;
otherwise, elicitation returns an error.
Server-side: To use elicitation from the server, call
ServerSession.Elicit.
%include ../../mcp/client_example_test.go elicitation -