pub struct RegistryServer { /* private fields */ }Expand description
MCP server handler backed by a ToolRegistry.
Features:
- Automatic tool discovery from registry
- Optional allowlist filtering
- Configurable output mode (text or structured)
§Output Modes
- Text (default): Returns human-readable text using
TextFormatwhen available, falling back to pretty-printed JSON. Does not publishoutput_schema. - Structured: Publishes
output_schemainlist_toolsand populatesstructured_contentincall_toolresponses (for MCP protocol compliance).
§Example
ⓘ
use agentic_tools_mcp::{RegistryServer, OutputMode};
use agentic_tools_core::ToolRegistry;
use std::sync::Arc;
let registry = Arc::new(ToolRegistry::builder()
.register::<MyTool, ()>(MyTool)
.finish());
// Text mode (default) - optimized for LLM consumption
let server = RegistryServer::new(registry.clone())
.with_allowlist(["my_tool".to_string()]);
// Structured mode - MCP protocol compliance with typed responses
let server = RegistryServer::new(registry)
.with_output_mode(OutputMode::Structured);Implementations§
Source§impl RegistryServer
impl RegistryServer
Sourcepub fn new(registry: Arc<ToolRegistry>) -> Self
pub fn new(registry: Arc<ToolRegistry>) -> Self
Create a new server from a registry.
Sourcepub fn with_allowlist(self, allowlist: impl IntoIterator<Item = String>) -> Self
pub fn with_allowlist(self, allowlist: impl IntoIterator<Item = String>) -> Self
Set an allowlist of tool names.
Only tools in this list will be visible and callable.
Sourcepub fn with_output_mode(self, mode: OutputMode) -> Self
pub fn with_output_mode(self, mode: OutputMode) -> Self
Set the output mode for tool results.
Sourcepub fn with_text_options(self, text_options: TextOptions) -> Self
pub fn with_text_options(self, text_options: TextOptions) -> Self
Set text formatting options for tool results.
Sourcepub fn output_mode(&self) -> OutputMode
pub fn output_mode(&self) -> OutputMode
Get the output mode.
Sourcepub fn effective_tool_names(&self) -> Vec<String>
pub fn effective_tool_names(&self) -> Vec<String>
Get the list of effective tool names (respecting allowlist).
Trait Implementations§
Source§impl ServerHandler for RegistryServer
impl ServerHandler for RegistryServer
fn initialize( &self, _params: InitializeRequestParams, _ctx: RequestContext<RoleServer>, ) -> impl Future<Output = Result<InitializeResult, ErrorData>> + Send + '_
fn list_tools( &self, _req: Option<PaginatedRequestParams>, _ctx: RequestContext<RoleServer>, ) -> impl Future<Output = Result<ListToolsResult, ErrorData>> + Send + '_
fn call_tool( &self, req: CallToolRequestParams, request_context: RequestContext<RoleServer>, ) -> impl Future<Output = Result<CallToolResult, ErrorData>> + Send + '_
fn ping( &self, _ctx: RequestContext<RoleServer>, ) -> impl Future<Output = Result<(), ErrorData>> + Send + '_
fn complete( &self, _req: CompleteRequestParams, _ctx: RequestContext<RoleServer>, ) -> impl Future<Output = Result<CompleteResult, ErrorData>> + Send + '_
fn set_level( &self, _req: SetLevelRequestParams, _ctx: RequestContext<RoleServer>, ) -> impl Future<Output = Result<(), ErrorData>> + Send + '_
fn get_prompt( &self, _req: GetPromptRequestParams, _ctx: RequestContext<RoleServer>, ) -> impl Future<Output = Result<GetPromptResult, ErrorData>> + Send + '_
fn list_prompts( &self, _req: Option<PaginatedRequestParams>, _ctx: RequestContext<RoleServer>, ) -> impl Future<Output = Result<ListPromptsResult, ErrorData>> + Send + '_
fn list_resources( &self, _req: Option<PaginatedRequestParams>, _ctx: RequestContext<RoleServer>, ) -> impl Future<Output = Result<ListResourcesResult, ErrorData>> + Send + '_
fn list_resource_templates( &self, _req: Option<PaginatedRequestParams>, _ctx: RequestContext<RoleServer>, ) -> impl Future<Output = Result<ListResourceTemplatesResult, ErrorData>> + Send + '_
fn read_resource( &self, _req: ReadResourceRequestParams, _ctx: RequestContext<RoleServer>, ) -> impl Future<Output = Result<ReadResourceResult, ErrorData>> + Send + '_
fn subscribe( &self, _req: SubscribeRequestParams, _ctx: RequestContext<RoleServer>, ) -> impl Future<Output = Result<(), ErrorData>> + Send + '_
fn unsubscribe( &self, _req: UnsubscribeRequestParams, _ctx: RequestContext<RoleServer>, ) -> impl Future<Output = Result<(), ErrorData>> + Send + '_
fn enqueue_task( &self, _request: CallToolRequestParams, _context: RequestContext<RoleServer>, ) -> impl Future<Output = Result<CreateTaskResult, ErrorData>> + MaybeSendFuture
fn on_custom_request( &self, request: CustomRequest, context: RequestContext<RoleServer>, ) -> impl Future<Output = Result<CustomResult, ErrorData>> + MaybeSendFuture
fn on_cancelled( &self, notification: CancelledNotificationParam, context: NotificationContext<RoleServer>, ) -> impl Future<Output = ()> + MaybeSendFuture
fn on_progress( &self, notification: ProgressNotificationParam, context: NotificationContext<RoleServer>, ) -> impl Future<Output = ()> + MaybeSendFuture
fn on_initialized( &self, context: NotificationContext<RoleServer>, ) -> impl Future<Output = ()> + MaybeSendFuture
fn on_roots_list_changed( &self, context: NotificationContext<RoleServer>, ) -> impl Future<Output = ()> + MaybeSendFuture
fn on_custom_notification( &self, notification: CustomNotification, context: NotificationContext<RoleServer>, ) -> impl Future<Output = ()> + MaybeSendFuture
fn get_info(&self) -> InitializeResult
fn list_tasks( &self, request: Option<PaginatedRequestParams>, context: RequestContext<RoleServer>, ) -> impl Future<Output = Result<ListTasksResult, ErrorData>> + MaybeSendFuture
fn get_task_info( &self, request: GetTaskInfoParams, context: RequestContext<RoleServer>, ) -> impl Future<Output = Result<GetTaskResult, ErrorData>> + MaybeSendFuture
fn get_task_result( &self, request: GetTaskResultParams, context: RequestContext<RoleServer>, ) -> impl Future<Output = Result<GetTaskPayloadResult, ErrorData>> + MaybeSendFuture
fn cancel_task( &self, request: CancelTaskParams, context: RequestContext<RoleServer>, ) -> impl Future<Output = Result<CancelTaskResult, ErrorData>> + MaybeSendFuture
Auto Trait Implementations§
impl Freeze for RegistryServer
impl !RefUnwindSafe for RegistryServer
impl Send for RegistryServer
impl Sync for RegistryServer
impl Unpin for RegistryServer
impl UnsafeUnpin for RegistryServer
impl !UnwindSafe for RegistryServer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<R, S> DynService<R> for Swhere
R: ServiceRole,
S: Service<R>,
impl<R, S> DynService<R> for Swhere
R: ServiceRole,
S: Service<R>,
fn handle_request( &self, request: <R as ServiceRole>::PeerReq, context: RequestContext<R>, ) -> Pin<Box<dyn Future<Output = Result<<R as ServiceRole>::Resp, ErrorData>> + Send + '_>>
fn handle_notification( &self, notification: <R as ServiceRole>::PeerNot, context: NotificationContext<R>, ) -> Pin<Box<dyn Future<Output = Result<(), ErrorData>> + Send + '_>>
fn get_info(&self) -> <R as ServiceRole>::Info
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<H> Service<RoleServer> for Hwhere
H: ServerHandler,
impl<H> Service<RoleServer> for Hwhere
H: ServerHandler,
async fn handle_request( &self, request: <RoleServer as ServiceRole>::PeerReq, context: RequestContext<RoleServer>, ) -> Result<<RoleServer as ServiceRole>::Resp, ErrorData>
async fn handle_notification( &self, notification: <RoleServer as ServiceRole>::PeerNot, context: NotificationContext<RoleServer>, ) -> Result<(), ErrorData>
fn get_info(&self) -> <RoleServer as ServiceRole>::Info
Source§impl<S> ServiceExt<RoleServer> for Swhere
S: Service<RoleServer>,
impl<S> ServiceExt<RoleServer> for Swhere
S: Service<RoleServer>,
fn serve_with_ct<T, E, A>( self, transport: T, ct: CancellationToken, ) -> impl Future<Output = Result<RunningService<RoleServer, S>, ServerInitializeError>> + MaybeSendFuture
Source§fn into_dyn(self) -> Box<dyn DynService<R>>
fn into_dyn(self) -> Box<dyn DynService<R>>
Convert this service to a dynamic boxed service Read more