Client constructor
Client({
- required String name,
- required String version,
- String? description,
- ClientCapabilities capabilities = const ClientCapabilities(),
- 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 {};
}