Skip to main content

Module rmcp

Module rmcp 

Source
Available on crate feature rmcp only.
Expand description

MCP (Model Context Protocol) integration via the rmcp crate.

This module provides:

  • McpTool: A wrapper that adapts an rmcp tool for use in Rig’s tool system.
  • McpClientHandler: A client handler that reacts to notifications/tools/list_changed by re-fetching the tool list and updating the ToolServer.

§Example

use rig_core::tool::rmcp::McpClientHandler;
use rig_core::tool::server::ToolServer;
use rmcp::ServiceExt;

// 1. Create a ToolServer and get a handle
let tool_server_handle = ToolServer::new().run();

// 2. Create a handler that auto-updates tools on list changes
let handler = McpClientHandler::new(client_info, tool_server_handle.clone());

// 3. Connect to the MCP server and register initial tools
let mcp_service = handler.connect(transport).await?;

// 4. Build an agent using the shared tool server handle
let agent = openai_client
    .agent(openai::GPT_5_2)
    .preamble("You are a helpful assistant.")
    .tool_server_handle(tool_server_handle)
    .build();

Structs§

McpClientHandler
An MCP client handler that automatically re-fetches the tool list when the server sends a notifications/tools/list_changed notification.
McpTool
A Rig tool adapter wrapping an rmcp MCP tool.
McpToolError

Enums§

McpClientError
Error type for McpClientHandler operations.