initialize method
Registers the features available to a client with initialization.
Mixins and subclasses should register request handlers and other features in this method, as well as editing capabilities.
Transport-specific initialization, including the legacy MCP initialize request, is handled separately.
Implementation
@mustCallSuper
/// Registers the features available to a client with [initialization].
///
/// Mixins and subclasses should register request handlers and other features
/// in this method, as well as editing [capabilities].
///
/// Transport-specific initialization, including the legacy MCP initialize
/// request, is handled separately.
FutureOr<void> initialize(MCPServerInitialization initialization) {
protocolVersion = initialization.protocolVersion;
_inputRequiredProtocolVersion = protocolVersion;
clientCapabilities = initialization.clientCapabilities;
clientInfo = initialization.clientInfo;
if (clientCapabilities.roots?.listChanged == true) {
_rootsListChangedController =
StreamController<RootsListChangedNotification?>.broadcast();
registerNotificationHandler(
RootsListChangedNotification.methodName,
_rootsListChangedController!.sink.add,
);
}
// Registering this handler is itself a statement about the lifecycle, so
// only a server on a request-scoped revision does it. A client probing
// under the stdio backward compatibility rules would read an answer here
// as "this connection is modern".
if (protocolVersion.methodIsValid(DiscoverRequest.methodName)) {
registerRequestHandler(DiscoverRequest.methodName, discover);
}
}