Client
Category: Mcp_client
Source: client.dart
MCP JSON-RPC client.
Speaks MCP over an injectable [JsonRpcTransport] from glue_server so the same client works against stdio, HTTP+SSE, WebSocket, or an in-memory transport in tests.
Responsibilities: • initialize handshake + protocol version negotiation • tools/list, tools/call with a concurrent-id pending map • rate-limit retry-once • notifications fan-out (tools/list_changed, future server events) • drop detection → pending calls fail with retryable metadata
Classes
McpNotification
A peer-side notification flowing from the server. tools/list_changed is the only one we currently care about, but we surface everything so callers can route as they like.
Constructor
const McpNotification({required this.method, this.params})Properties
| Property | Type | Description |
|---|---|---|
method | String | |
params | Map<String, dynamic>? |
McpCallFailure
Failure shape thrown by [McpClient.callTool] / [listTools] / [initialize] when the call cannot complete. The agent loop maps this onto ToolResult(success: false, ...).
Constructor
const McpCallFailure({
required this.reason,
this.code,
this.message,
this.retryable = false,
this.wwwAuthenticate,
})Properties
| Property | Type | Description |
|---|---|---|
reason | String | Short machine reason. Stable. Drives metadata. |
code | int? | JSON-RPC error code if this came from the server. |
message | String? | Human-readable message. |
retryable | bool | Whether the agent loop may retry the same call. |
wwwAuthenticate | String? | Raw WWW-Authenticate header, when this failure originated from a 401 transport error. Consumed by the pool to drive RFC 9728 discovery and refresh-token grant. |
Methods
String toString()
McpClient
Constructor
McpClient({
required this.transport,
this.clientInfo = const McpClientInfo(name: 'glue', version: '0.0.0'),
this.clientCapabilities = const McpClientCapabilities(
roots: McpRootsCapability(listChanged: true),
),
this.callTimeout = const Duration(seconds: 30),
})Properties
| Property | Type | Description |
|---|---|---|
transport | JsonRpcTransport | |
clientInfo | McpClientInfo | |
clientCapabilities | McpClientCapabilities | |
callTimeout | Duration | |
notifications | Stream<McpNotification> get | |
initResult | McpInitializeResult? get | Set after a successful [initialize]. Null otherwise. |
notifications | Stream<McpNotification> get | |
initResult | McpInitializeResult? get | Set after a successful [initialize]. Null otherwise. |
Methods
Future<McpInitializeResult> initialize()
Sends initialize + notifications/initialized. Negotiates the protocol version per the design doc: equal → continue; older within minimum-supported → continue with downgrade; newer → continue, upgrade-tolerant; older than minimum → refuse.
Future<List<McpToolDescriptor>> listTools()
`Future<McpToolCallResult> callTool(
String name,
Map<String, dynamic> arguments,
)`
Calls a tool. On JSON-RPC rate-limit (-32011) we honour the hint and retry once. On transport drop, all pending calls (including this one) resolve with [McpCallFailure(retryable: true)].