McpClient class final

A live connection to one MCP server.

Constructors

McpClient({required String serverName, required McpTransport transport, Duration requestTimeout = const Duration(seconds: 60)})
Creates an McpClient over transport. The read loop starts immediately; call initialize before issuing tool requests.

Properties

closed → Future<void>
Completes when the connection dies, expectedly or not.
no setter
hashCode → int
The hash code for this object.
no setterinherited
requestTimeout → Duration
Default timeout for requests without an explicit one.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
serverName → String
The configured name of the server this client talks to.
final
status ↔ McpClientStatus
Lifecycle state.
getter/setter pair
transport → McpTransport
The message channel to the server.
final

Methods

callTool(String tool, Map<String, dynamic> arguments, {Duration? timeout}) → Future<Map<String, dynamic>>
Calls tool with arguments; the raw result map (content, isError, structuredContent, ...) is returned for the tool wrapper to interpret.
close() → Future<void>
Closes the connection. Always safe to call.
initialize({Duration? timeout}) → Future<McpInitializeResult>
Runs the initialize/notifications/initialized handshake. Throws McpRequestException on failure.
listTools({Duration? timeout}) → Future<List<McpToolInfo>>
Lists the server's tools, following nextCursor pagination.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notify(String method, Object? params) → void
Sends a notification (no response expected).
request(String method, Object? params, {Duration? timeout}) → Future<Object?>
Sends a request and awaits its result. Throws McpRequestException on a server error response, on timeout, or when the connection dies mid-flight.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited