pub struct McpServiceRegistry { /* private fields */ }Expand description
Manages MCP services offered to successor proxies and agents.
Use the Self::add_mcp_server method to register MCP servers. For rmcp-based servers,
use the sacp-rmcp crate which provides convenient extension methods.
This struct is a handle to the underlying registry. Cloning the struct produces a second handle to the same registry.
§Handling requests
You must add the registry (or a clone of it) to the JrHandlerChain so that it can intercept MCP requests.
Typically you do this by providing it as an argument to the handler chain methods.
Implementations§
Source§impl McpServiceRegistry
impl McpServiceRegistry
Sourcepub fn with_mcp_server(
self,
name: impl ToString,
server: McpServer,
) -> Result<Self, Error>
pub fn with_mcp_server( self, name: impl ToString, server: McpServer, ) -> Result<Self, Error>
Sourcepub fn add_mcp_server<C: Component>(
&self,
name: impl ToString,
new_fn: impl Fn() -> C + Send + Sync + 'static,
) -> Result<(), Error>
pub fn add_mcp_server<C: Component>( &self, name: impl ToString, new_fn: impl Fn() -> C + Send + Sync + 'static, ) -> Result<(), Error>
Add an MCP server to the registry using a custom constructor function.
This server will be added to all new sessions where this registry is in the handler chain.
This method is for independent MCP servers that do not make use of ACP.
You may wish to use the sacp-rmcp crate which provides convenient
extension methods for working with MCP servers implemented using the rmcp crate.
§Parameters
name: The name of the server.new_fn: Constructor function that creates the MCP server and returns aComponentfor connecting to it.
Sourcepub fn add_mcp_server_with_context<C: Component>(
&self,
name: impl ToString,
new_fn: impl Fn(McpContext) -> C + Send + Sync + 'static,
) -> Result<(), Error>
pub fn add_mcp_server_with_context<C: Component>( &self, name: impl ToString, new_fn: impl Fn(McpContext) -> C + Send + Sync + 'static, ) -> Result<(), Error>
Add an MCP server to the registry that wishes to receive a McpContext when created.
This server will be added to all new sessions where this registry is in the handler chain.
This method is for MCP servers that require information about the ACP connection and/or the ability to make ACP requests.
§Parameters
name: The name of the server.new_fn: Constructor function that creates the MCP server and returns aComponentfor connecting to it.
Sourcepub fn add_registered_mcp_servers_to(&self, request: &mut NewSessionRequest)
pub fn add_registered_mcp_servers_to(&self, request: &mut NewSessionRequest)
Adds all registered MCP servers to the given NewSessionRequest.
This method appends the MCP server configurations for all servers registered
with this registry to the mcp_servers field of the request. This is useful
when you want to manually populate a request with MCP servers outside of the
automatic handler chain processing.
§Example
let registry = McpServiceRegistry::new();
registry.add_mcp_server("my-server", || MyMcpServer)?;
let mut request = NewSessionRequest {
registry.add_registered_mcp_servers_to(&mut request);
// request.mcp_servers now contains "my-server"Trait Implementations§
Source§impl AsRef<McpServiceRegistry> for McpServiceRegistry
impl AsRef<McpServiceRegistry> for McpServiceRegistry
Source§fn as_ref(&self) -> &McpServiceRegistry
fn as_ref(&self) -> &McpServiceRegistry
Source§impl Clone for McpServiceRegistry
impl Clone for McpServiceRegistry
Source§fn clone(&self) -> McpServiceRegistry
fn clone(&self) -> McpServiceRegistry
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more