McpManager class final
Owns the McpClient pool and the dynamic MCP tool surface.
Constructors
- McpManager({required McpConfig config, required String cwd, McpTransportFactory? transportFactory, Client? httpClient, void onChanged()?, Duration reconnectBaseDelay = const Duration(seconds: 1), Duration reconnectMaxDelay = const Duration(seconds: 30)})
-
Creates an McpManager.
cwdis the working directory stdio servers are spawned in (the agent'sExecutionEnv.cwd).
Properties
- config ↔ McpConfig
-
The resolved MCP configuration. Updated in place by applyConfig
(the settings flow's live reload, issue #396) so the prompt section
and the
/mcp reloadchange check always reflect the servers actually connected.getter/setter pair - cwd → String
-
Working directory for stdio servers.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- httpClient → Client?
-
HTTP client for remote servers.
final
- onChanged ↔ void Function()?
-
Fires whenever tools or states change (connect, failure,
reconnect) so the host can re-register tools and rebuild the prompt.
getter/setter pair
- reconnectBaseDelay → Duration
-
First reconnect delay (doubles per consecutive failure).
final
- reconnectMaxDelay → Duration
-
Cap on the reconnect backoff.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
states
→ Map<
String, McpServerState> -
Server name → live state, in config order.
no setter
-
tools
→ List<
AgentTool> -
The currently registered MCP tools (connected servers only).
Duplicate sanitized names are dropped first-wins — registration into a
ToolRegistrymust never throw on a collision.no setter -
toolsByServer
→ Map<
String, List< AgentTool> > -
The per-server tool lists (connected servers only), server name →
tools in registration order. Unmodifiable deep view: the availability
wiring re-registers or unregisters a whole server from here without
touching the manager's own state.
no setter
- transportFactory → McpTransportFactory?
-
Spawns stdio server processes; null on process-less hosts.
final
Methods
-
applyConfig(
McpConfig next) → Future< void> -
Live config reload (issue #396): diffs
nextagainst the current section and reconnects ONLY the touched servers — an entry that is value-equal keeps its live connection. Removed servers stop; added and changed ones start fresh loops; a tool-call-timeout change restarts every server (existing clients hold the timeout they were built with). The settings flow persists the section first and calls this right after;/mcp reloadkeeps its whole-wiring swap for boot-level changes (transport factory, section ↔ no-section). -
callTool(
String server, String tool, Map< String, dynamic> arguments) → Future<Map< String, dynamic> > -
Routes one
tools/callto the server. Throws StateError with an actionable message when the server is not connected; server-side and timeout failures surface as McpRequestException. -
dispose(
) → Future< void> - Closes every client and stops reconnecting. Idempotent.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
promptSection(
{bool includeServer(String server)?}) → String -
The system-prompt section listing every configured server and its
status (empty when no servers are configured, and servers rejected by
includeServerare omitted — the availability gate's per-server decision). Kept tiny: one line per server. -
restartServer(
String name) → Future< void> -
Stops and immediately reconnects just
name(the settings flow's reconnect action, issue #396) — a fresh connect attempt, no waiting out the reconnect backoff. Unknown names are a no-op. -
start(
) → void - Starts background connect loops for every configured server. Returns immediately; progress surfaces through states and onChanged.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited