Skip to main content

McpToolRegistry

Struct McpToolRegistry 

Source
pub struct McpToolRegistry<Counterpart: Role> { /* private fields */ }
Available on crate feature schemars only.
Expand description

Runtime-neutral registry for MCP tools.

Implementations§

Source§

impl<Counterpart: Role> McpToolRegistry<Counterpart>

Source

pub fn set_instructions(&mut self, instructions: impl ToString)

Set the server instructions that are provided to the client.

Source

pub fn instructions(&self) -> Option<&str>

Server instructions provided to the client.

Source

pub fn register_tool(&mut self, tool: impl McpTool<Counterpart> + 'static)

Register a tool.

Source

pub fn tools(&self) -> impl Iterator<Item = &RegisteredMcpTool<Counterpart>>

Return all registered tools in registration order.

Source

pub fn enabled_tools( &self, ) -> impl Iterator<Item = &RegisteredMcpTool<Counterpart>>

Return enabled registered tools in registration order.

Source

pub fn tool(&self, name: &str) -> Option<&RegisteredMcpTool<Counterpart>>

Return a registered tool by name, even if it is disabled.

Source

pub fn enabled_tool( &self, name: &str, ) -> Option<&RegisteredMcpTool<Counterpart>>

Return an enabled tool by name.

Source

pub fn contains_tool(&self, name: &str) -> bool

Check whether a tool is registered.

Source

pub fn add_tool_admission<F>( &mut self, name: &str, admit: F, to_future_hack: impl for<'a> Fn(&'a F, McpAdmission) -> BoxFuture<'a, Result<(), McpRejection>> + Send + Sync + 'static, ) -> Result<(), UnknownToolError>
where F: AsyncFn(McpAdmission) -> Result<(), McpRejection> + Send + Sync + 'static,

Available on crate feature unstable_mcp_over_acp only.

Adds an admission check for one registered tool, for a tool that cannot state its rule in McpTool::admit, such as a function tool.

The check is an async closure of the request. Pass mcp_admission! as the last argument.

The check runs after the tool’s own McpTool::admit and after the checks added for the tool before. Registering another tool under the same name removes it.

§Errors

Returns UnknownToolError if no tool with this name is registered.

Source

pub fn admit( &self, request: McpAdmission, ) -> BoxFuture<'_, Result<(), McpRejection>>

Available on crate feature unstable_mcp_over_acp only.

Decides whether a request to a server built from this registry is admitted.

For a tools/call request that names an enabled tool, this is that tool’s RegisteredMcpTool::admit. Every other request is admitted, including a call of a tool that is unknown or disabled.

§Errors

The future returns the tool’s McpRejection.

Source

pub fn disable_all_tools(&mut self)

Disable all tools. After calling this, only tools explicitly enabled with enable_tool will be available.

Source

pub fn enable_all_tools(&mut self)

Enable all tools. After calling this, all tools will be available except those explicitly disabled with disable_tool.

Source

pub fn disable_tool(&mut self, name: &str) -> Result<(), UnknownToolError>

Disable a specific tool by name.

§Errors

Returns UnknownToolError if no tool with this name is registered.

Source

pub fn enable_tool(&mut self, name: &str) -> Result<(), UnknownToolError>

Enable a specific tool by name.

§Errors

Returns UnknownToolError if no tool with this name is registered.

Trait Implementations§

Source§

impl<Counterpart: Debug + Role> Debug for McpToolRegistry<Counterpart>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Counterpart: Role> Default for McpToolRegistry<Counterpart>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<Counterpart> !RefUnwindSafe for McpToolRegistry<Counterpart>

§

impl<Counterpart> !UnwindSafe for McpToolRegistry<Counterpart>

§

impl<Counterpart> Forget for McpToolRegistry<Counterpart>

§

impl<Counterpart> Freeze for McpToolRegistry<Counterpart>
where Vec<RegisteredMcpTool<Counterpart>>: Freeze,

§

impl<Counterpart> Move for McpToolRegistry<Counterpart>

§

impl<Counterpart> Send for McpToolRegistry<Counterpart>
where Vec<RegisteredMcpTool<Counterpart>>: Send,

§

impl<Counterpart> Sync for McpToolRegistry<Counterpart>
where Vec<RegisteredMcpTool<Counterpart>>: Sync,

§

impl<Counterpart> Unpin for McpToolRegistry<Counterpart>
where Vec<RegisteredMcpTool<Counterpart>>: Unpin,

§

impl<Counterpart> UnsafeUnpin for McpToolRegistry<Counterpart>
where Vec<RegisteredMcpTool<Counterpart>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoMaybeUndefined<T> for T

Source§

fn into_maybe_undefined(self) -> MaybeUndefined<T>

Converts this value into a three-state builder argument.
Source§

impl<T> IntoOption<T> for T

Source§

fn into_option(self) -> Option<T>

Converts this value into an optional builder argument.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more