initialize method

  1. @override
FutureOr<void> initialize(
  1. MCPServerInitialization initialization
)
override

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

@override
FutureOr<void> initialize(MCPServerInitialization initialization) async {
  if (initialization.protocolVersion < ProtocolVersion.v2026_07_28) {
    loggingLevel ??= LoggingLevel.warning;
    registerRequestHandler(SetLevelRequest.methodName, handleSetLevel);
  } else {
    // Assign instead of `??=`. 2026-07-28 took `logging/setLevel` out, so a
    // default the server picked for itself would otherwise survive here and
    // log on a request that asked for no level.
    loggingLevel = initialization.logLevel;
  }

  await super.initialize(initialization);
  capabilities.logging ??= Logging();
}