Skip to main content

rig_rmcp/
lib.rs

1//! Native MCP tool adapters and managed tool-list synchronization for Rig.
2//! [`McpTool`] converts to a context-aware
3//! [`DynamicTool`](rig_core::tool::DynamicTool); [`McpClientHandler`] refreshes
4//! registrations when the server reports tool-list changes.
5//!
6//! [`McpMeta`] supplies request metadata outside model-visible arguments.
7//! Responses publish raw results, structured content, and response metadata
8//! to the context result map; model output uses ordered presentation content.
9//!
10//! ```
11//! use rig_core::tool::ToolContext;
12//! use rig_rmcp::{McpMeta, Meta};
13//!
14//! let mut context = ToolContext::new();
15//! context.insert(McpMeta(Meta::default()))?;
16//! # Ok::<(), rig_core::tool::ToolContextError>(())
17//! ```
18
19#![cfg_attr(docsrs, feature(doc_cfg))]
20#![cfg_attr(
21    test,
22    allow(
23        clippy::expect_used,
24        clippy::indexing_slicing,
25        clippy::panic,
26        clippy::unwrap_used,
27        clippy::unreachable
28    )
29)]
30
31// rmcp requires Send + Sync handlers even with local futures, while Rig's
32// WASM tool registry does not provide those bounds.
33#[cfg(target_family = "wasm")]
34compile_error!(
35    "the `rmcp` feature is native-only: rmcp's `ClientHandler` requires \
36     `Send + Sync` unconditionally (its `local` feature relaxes only futures), \
37     which rig's wasm tool registry cannot satisfy. Disable `rmcp` for wasm targets."
38);
39
40#[cfg(not(target_family = "wasm"))]
41mod native;
42#[cfg(not(target_family = "wasm"))]
43pub use native::*;
44
45#[cfg(not(target_family = "wasm"))]
46mod handler;
47#[cfg(not(target_family = "wasm"))]
48pub use handler::McpClientHandler;
49
50#[cfg(all(test, not(target_family = "wasm")))]
51mod tests;
52
53/// The rmcp SDK this crate is built against, so callers and rig agree on one version.
54#[cfg(not(target_family = "wasm"))]
55pub use rmcp;