pub struct McpClientHandler<S> { /* private fields */ }target_family=wasm only.Expand description
Registers MCP tools in a ManagedToolSink and refreshes them on list changes.
Refreshes replace or remove only registrations still owned by this handler,
preserving newer same-name registrations. Self::connect performs the
initial fetch and returns the service that keeps the connection alive.
Implementations§
Source§impl<S> McpClientHandler<S>
impl<S> McpClientHandler<S>
Sourcepub fn new(client_info: ClientInfo, sink: S) -> Self
pub fn new(client_info: ClientInfo, sink: S) -> Self
Create a new handler with the given client info and tool sink.
With rig-agent, pass a clone of the agent’s ToolServerHandle so tool
updates are reflected in agent requests. Registered tools get
DEFAULT_MCP_TOOL_TIMEOUT; change it with McpClientHandler::with_timeout.
Sourcepub fn with_timeout(self, timeout: impl Into<Option<Duration>>) -> Self
pub fn with_timeout(self, timeout: impl Into<Option<Duration>>) -> Self
Set (or clear) the per-call timeout applied to every MCP tool this handler
registers. Pass a Duration to bound calls, or None to disable.
This applies the same setting to every tool managed by the handler.
Sourcepub fn with_refresh_timeout(self, timeout: Duration) -> Self
pub fn with_refresh_timeout(self, timeout: Duration) -> Self
Set the deadline for initial and list-changed tool-list fetches.
Sourcepub async fn connect<T, E, A>(
self,
transport: T,
) -> Result<RunningService<RoleClient, Self>, McpClientError>
pub async fn connect<T, E, A>( self, transport: T, ) -> Result<RunningService<RoleClient, Self>, McpClientError>
Connect to an MCP server, fetch the initial tool list, and register all tools with the tool server.
Returns the running MCP service. The connection stays alive as long as the
returned RunningService is held. When the server sends
notifications/tools/list_changed, this handler automatically re-fetches
and re-registers tools into the sink.
§Errors
Returns McpClientError if the connection or initial tool fetch fails.