Client constructor

Client({
  1. required String name,
  2. required String version,
  3. String? description,
  4. ClientCapabilities capabilities = const ClientCapabilities(),
  5. String? protocolVersion,
})

Creates a new MCP client with the specified parameters

Implementation

Client({
  required this.name,
  required this.version,
  this.description,
  this.capabilities = const ClientCapabilities(),
  String? protocolVersion,
}) : protocolVersion = protocolVersion ?? McpProtocol.defaultVersion {
  // Default `roots/list` handler returns the locally registered roots.
  // Hosts may override with [onListRoots] for dynamic roots.
  _requestHandlers['roots/list'] = (_) async => {
        'roots': _roots.map((r) => r.toJson()).toList(),
      };

  // `ping` is answered by whichever side receives it, with an empty result.
  // Without this a server keepalive gets `Method not found` back.
  _requestHandlers['ping'] = (_) async => const {};
}