Client constructor
Client({
- required String name,
- required String version,
- String? description,
- String? title,
- String? websiteUrl,
- List<
McpIcon> ? icons, - ClientCapabilities capabilities = const ClientCapabilities(),
- String? protocolVersion,
- Duration requestTimeout = const Duration(seconds: 30),
- Duration maxRequestTimeout = const Duration(minutes: 10),
Creates a new MCP client with the specified parameters
Implementation
Client({
required this.name,
required this.version,
this.description,
this.title,
this.websiteUrl,
this.icons,
this.capabilities = const ClientCapabilities(),
String? protocolVersion,
this.requestTimeout = const Duration(seconds: 30),
this.maxRequestTimeout = const Duration(minutes: 10),
}) : 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 {};
_installTaskHandlers();
}