pub struct AuthorizedServer<S: ServerHandler> { /* private fields */ }Expand description
A ServerHandler wrapper that adds authorization-based schema shaping.
Wraps any inner ServerHandler and intercepts list_tools and
call_tool to filter tools and shape schemas based on the user’s
AuthContext (stored in RequestContext::extensions).
ⓘ
let server = AuthorizedServer::new(MyHandler)
.register::<AdvanceStepInput, AdvanceStepOutput>(
"advance_step",
"Advance an applicant",
)
.authorize("advance_step", "manage_workflows");Implementations§
Source§impl<S: ServerHandler> AuthorizedServer<S>
impl<S: ServerHandler> AuthorizedServer<S>
pub fn new(inner: S) -> Self
Sourcepub fn register<I, O>(
self,
name: impl Into<String>,
description: impl Into<String>,
) -> Selfwhere
I: JsonSchema + AuthSchemaMetadata + DeserializeOwned + 'static,
O: JsonSchema + AuthSchemaMetadata + Serialize + 'static,
pub fn register<I, O>(
self,
name: impl Into<String>,
description: impl Into<String>,
) -> Selfwhere
I: JsonSchema + AuthSchemaMetadata + DeserializeOwned + 'static,
O: JsonSchema + AuthSchemaMetadata + Serialize + 'static,
Register a tool with typed input/output for schema generation and authorization metadata.
Set tool-level authorization for a named tool.
The tool will be hidden from list_tools if the user lacks this capability.
Sourcepub fn registry(&self) -> &AuthToolRegistry
pub fn registry(&self) -> &AuthToolRegistry
Get a reference to the authorization registry.
Trait Implementations§
Source§impl<S: ServerHandler> ServerHandler for AuthorizedServer<S>
impl<S: ServerHandler> ServerHandler for AuthorizedServer<S>
fn get_info(&self) -> ServerInfo
fn list_tools( &self, _request: Option<PaginatedRequestParams>, context: RequestContext<RoleServer>, ) -> impl Future<Output = Result<ListToolsResult, McpError>> + MaybeSendFuture + '_
fn call_tool( &self, request: CallToolRequestParams, context: RequestContext<RoleServer>, ) -> impl Future<Output = Result<CallToolResult, McpError>> + MaybeSendFuture + '_
fn initialize( &self, request: InitializeRequestParams, context: RequestContext<RoleServer>, ) -> impl Future<Output = Result<InitializeResult, McpError>> + MaybeSendFuture + '_
fn ping( &self, context: RequestContext<RoleServer>, ) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_
fn complete( &self, request: CompleteRequestParams, context: RequestContext<RoleServer>, ) -> impl Future<Output = Result<CompleteResult, McpError>> + MaybeSendFuture + '_
fn set_level( &self, request: SetLevelRequestParams, context: RequestContext<RoleServer>, ) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_
fn get_prompt( &self, request: GetPromptRequestParams, context: RequestContext<RoleServer>, ) -> impl Future<Output = Result<GetPromptResult, McpError>> + MaybeSendFuture + '_
fn list_prompts( &self, request: Option<PaginatedRequestParams>, context: RequestContext<RoleServer>, ) -> impl Future<Output = Result<ListPromptsResult, McpError>> + MaybeSendFuture + '_
fn list_resources( &self, request: Option<PaginatedRequestParams>, context: RequestContext<RoleServer>, ) -> impl Future<Output = Result<ListResourcesResult, McpError>> + MaybeSendFuture + '_
fn list_resource_templates( &self, request: Option<PaginatedRequestParams>, context: RequestContext<RoleServer>, ) -> impl Future<Output = Result<ListResourceTemplatesResult, McpError>> + MaybeSendFuture + '_
fn read_resource( &self, request: ReadResourceRequestParams, context: RequestContext<RoleServer>, ) -> impl Future<Output = Result<ReadResourceResult, McpError>> + MaybeSendFuture + '_
fn subscribe( &self, request: SubscribeRequestParams, context: RequestContext<RoleServer>, ) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_
fn unsubscribe( &self, request: UnsubscribeRequestParams, context: RequestContext<RoleServer>, ) -> impl Future<Output = Result<(), McpError>> + MaybeSendFuture + '_
fn on_custom_request( &self, request: CustomRequest, context: RequestContext<RoleServer>, ) -> impl Future<Output = Result<CustomResult, McpError>> + 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 enqueue_task( &self, request: CallToolRequestParams, context: RequestContext<RoleServer>, ) -> impl Future<Output = Result<CreateTaskResult, McpError>> + MaybeSendFuture + '_
fn list_tasks( &self, request: Option<PaginatedRequestParams>, context: RequestContext<RoleServer>, ) -> impl Future<Output = Result<ListTasksResult, McpError>> + MaybeSendFuture + '_
fn get_task_info( &self, request: GetTaskInfoParams, context: RequestContext<RoleServer>, ) -> impl Future<Output = Result<GetTaskResult, McpError>> + MaybeSendFuture + '_
fn get_task_result( &self, request: GetTaskResultParams, context: RequestContext<RoleServer>, ) -> impl Future<Output = Result<GetTaskPayloadResult, McpError>> + MaybeSendFuture + '_
fn cancel_task( &self, request: CancelTaskParams, context: RequestContext<RoleServer>, ) -> impl Future<Output = Result<CancelTaskResult, McpError>> + MaybeSendFuture + '_
Auto Trait Implementations§
impl<S> Freeze for AuthorizedServer<S>where
S: Freeze,
impl<S> RefUnwindSafe for AuthorizedServer<S>where
S: RefUnwindSafe,
impl<S> Send for AuthorizedServer<S>
impl<S> Sync for AuthorizedServer<S>
impl<S> Unpin for AuthorizedServer<S>where
S: Unpin,
impl<S> UnsafeUnpin for AuthorizedServer<S>where
S: UnsafeUnpin,
impl<S> UnwindSafe for AuthorizedServer<S>where
S: UnwindSafe,
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