Client class
Main MCP Client class that handles all client-side protocol operations
- Available extensions
Constructors
- Client({required String name, required String version, ClientCapabilities capabilities = const ClientCapabilities()})
- Creates a new MCP client with the specified parameters
Properties
- capabilities → ClientCapabilities
-
Client capabilities configuration
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- isConnected → bool
-
Whether the client is currently connected
no setter
- name → String
-
Name of the MCP client
final
-
onConnect
→ Stream<
ServerInfo> -
Stream of connection events
no setter
-
onDisconnect
→ Stream<
DisconnectReason> -
Stream of disconnection events
no setter
-
onError
→ Stream<
McpError> -
Stream of error events
no setter
- protocolVersion → String
-
Protocol version this client implements
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- serverCapabilities → ServerCapabilities?
-
Get the server capabilities
no setter
-
serverInfo
→ Map<
String, dynamic> ? -
Get the server information
no setter
- version → String
-
Version of the MCP client implementation
final
Methods
-
addRoot(
Root root) → Future< void> - Add a root
-
callTool(
String name, Map< String, dynamic> toolArguments) → Future<CallToolResult> - Call a tool on the server
-
callToolWithTracking(
String name, Map< String, dynamic> arguments, {bool trackProgress = true}) → Future<ToolCallTracking> - Call a tool and get the operation ID for tracking progress
-
cancelOperation(
String operationId) → Future< void> - Cancel an operation that is in progress on the server
-
connect(
ClientTransport transport) → Future< void> - Connect the client to a transport
-
connectWithRetry(
ClientTransport transport, {int maxRetries = 3, Duration delay = const Duration(seconds: 2)}) → Future< void> - Connect with retry mechanism
-
createMessage(
CreateMessageRequest request) → Future< CreateMessageResult> - Request model sampling from the server
-
disconnect(
) → void - Disconnect the client from its transport
-
dispose(
) → void - Dispose client resources
-
getPrompt(
String name, [Map< String, dynamic> ? promptArguments]) → Future<GetPromptResult> - Get a prompt from the server
-
getResourceWithTemplate(
String templateUri, Map< String, dynamic> params) → Future<ReadResourceResult> - Get a resource using a template
-
healthCheck(
) → Future< ServerHealth> - Request the current health status of the server
-
initialize(
) → Future< void> - Initialize the connection to the server
-
listPrompts(
) → Future< List< Prompt> > - List available prompts on the server
-
listResources(
) → Future< List< Resource> > - List available resources on the server
-
listResourceTemplates(
) → Future< List< ResourceTemplate> > - List resource templates on the server
-
listRoots(
) → Future< List< Root> > - List roots
-
listTools(
) → Future< List< Tool> > - List available tools on the server
-
listToolsMetadata(
ToolRegistry registry) → Future< List< ToolMetadata> > -
Available on Client, provided by the ClientToolMetadataExtension extension
Fetch tools and return metadata only Caches full tools in provided registry for later schema lookup -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onLogging(
dynamic handler(McpLogLevel, String, String?, Map< String, dynamic> ?)) → void - Handle logging notification
-
onNotification(
String method, dynamic handler(Map< String, dynamic> )) → void - Register a notification handler
-
onProgress(
dynamic handler(String requestId, double progress, String message)) → void - Register a handler for progress updates from the server
-
onPromptsListChanged(
dynamic handler()) → void - Handle prompts list changed notification
-
onResourceContentUpdated(
dynamic handler(String uri, ResourceContentInfo content)) → void - Register a handler for resource update notifications with content
-
onResourcesListChanged(
dynamic handler()) → void - Handle resources list changed notification
-
onResourceUpdated(
dynamic handler(String)) → void - Handle resource updated notification
-
onRootsListChanged(
dynamic handler()) → void - Handle roots list changed notification
-
onSamplingResponse(
dynamic handler(String requestId, CreateMessageResult result)) → void - Register a handler for sampling response notifications
-
onToolsListChanged(
dynamic handler()) → void - Handle tools list changed notification
-
readResource(
String uri) → Future< ReadResourceResult> - Read a resource from the server
-
removeRoot(
String uri) → Future< void> - Remove a root
-
setLoggingLevel(
McpLogLevel level) → Future< void> - Set the logging level for the server
-
subscribeResource(
String uri) → Future< void> - Subscribe to a resource
-
toString(
) → String -
A string representation of this object.
inherited
-
unsubscribeResource(
String uri) → Future< void> - Unsubscribe from a resource
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited