pub struct ExtensionHandlerRegistry { /* private fields */ }Expand description
Frozen, typed server handlers bound to one protocol descriptor registry.
The map is erased only internally. Each Self::register call fixes that
method’s own decoded request and encoded response types in a serde adapter,
so one registry can hold heterogeneous extension methods without weakening
a handler’s typed Rust boundary. Method ownership, direction, negotiated
capability activation, and descriptor receipt are still enforced by the
protocol registry at every invocation.
Implementations§
Source§impl ExtensionHandlerRegistry
impl ExtensionHandlerRegistry
Sourcepub fn new(descriptor_registry: ExtensionDescriptorRegistry) -> Self
pub fn new(descriptor_registry: ExtensionDescriptorRegistry) -> Self
Starts a handler registry around the supplied protocol descriptor registry.
Sourcepub const fn descriptor_registry(&self) -> &ExtensionDescriptorRegistry
pub const fn descriptor_registry(&self) -> &ExtensionDescriptorRegistry
Returns the protocol descriptor registry that governs handler admission.
Sourcepub fn server_metadata_len(&self) -> usize
pub fn server_metadata_len(&self) -> usize
Returns the number of descriptor-bound server metadata entries.
Sourcepub fn register_server_metadata(
&mut self,
extension_id: ExtensionId,
settings: ExtensionSettings,
) -> Result<(), ExtensionHandlerRegistrationError>
pub fn register_server_metadata( &mut self, extension_id: ExtensionId, settings: ExtensionSettings, ) -> Result<(), ExtensionHandlerRegistrationError>
Registers the exact server discovery settings for one extension.
This is intentionally separate from request-handler registration: an extension such as MCP Apps can need a server discovery marker before it owns a client-to-server extension method. The marker is accepted only for a descriptor already linked into this registry, and is immutable once the descriptor receipt is frozen.
Sourcepub fn register<Request, Response, Handler>(
&mut self,
extension_id: ExtensionId,
method: impl Into<String>,
handler: Handler,
) -> Result<(), ExtensionHandlerRegistrationError>where
Request: DeserializeOwned + 'static,
Response: Serialize + 'static,
Handler: ExtensionHandler<Request, Response> + 'static,
pub fn register<Request, Response, Handler>(
&mut self,
extension_id: ExtensionId,
method: impl Into<String>,
handler: Handler,
) -> Result<(), ExtensionHandlerRegistrationError>where
Request: DeserializeOwned + 'static,
Response: Serialize + 'static,
Handler: ExtensionHandler<Request, Response> + 'static,
Registers one typed handler for an extension request method.
Descriptor existence, exact method ownership, and client-to-server
direction are checked immediately. Self::invoke still checks
request-specific admission against the current negotiated extension set
before the handler can run.
Sourcepub fn freeze(
&mut self,
) -> Result<ExtensionRegistryReceipt, ExtensionRegistryError>
pub fn freeze( &mut self, ) -> Result<ExtensionRegistryReceipt, ExtensionRegistryError>
Freezes protocol descriptors and typed handlers under one immutable receipt.
Sourcepub fn freeze_with_server_discovery(
&mut self,
) -> Result<(ExtensionRegistryReceipt, ServerExtensionDiscovery), ExtensionRegistryError>
pub fn freeze_with_server_discovery( &mut self, ) -> Result<(ExtensionRegistryReceipt, ServerExtensionDiscovery), ExtensionRegistryError>
Freezes this registry and returns its matching discovery metadata.
Use this after extension composition is complete to inspect one frozen
descriptor receipt with its matching metadata. During builder
composition, ServerBuilder::extension_registry
derives registered metadata directly so later official Tasks installation
remains mutable.
Sourcepub fn server_discovery(
&self,
) -> Result<ServerExtensionDiscovery, ExtensionHandlerLookupError>
pub fn server_discovery( &self, ) -> Result<ServerExtensionDiscovery, ExtensionHandlerLookupError>
Returns the server discovery data bound to this frozen registry.
This frozen diagnostic/export surface is separate from builder-time composition, which snapshots registered metadata before freeze.
Sourcepub fn lookup(
&self,
extension_id: &ExtensionId,
method: &str,
) -> Result<&ExtensionHandlerKey, ExtensionHandlerLookupError>
pub fn lookup( &self, extension_id: &ExtensionId, method: &str, ) -> Result<&ExtensionHandlerKey, ExtensionHandlerLookupError>
Looks up one handler after freezing has made the registry immutable.
Sourcepub fn invoke(
&self,
negotiated: &NegotiatedExtensionSet,
protocol_era: ProtocolEra,
extension_id: &ExtensionId,
request: &JsonRpcRequest,
context: &McpContext,
) -> Result<Value, ExtensionHandlerInvocationError>
pub fn invoke( &self, negotiated: &NegotiatedExtensionSet, protocol_era: ProtocolEra, extension_id: &ExtensionId, request: &JsonRpcRequest, context: &McpContext, ) -> Result<Value, ExtensionHandlerInvocationError>
Admits and invokes one typed client-to-server extension request.
The protocol admission call binds this invocation to the exact frozen descriptor receipt, current negotiated extension set, modern era, and client-to-server ownership and request envelope before the handler is looked up or executed. A handler can only be registered for a descriptor’s request method, so an id-less notification is rejected generically before its parameters can reach stateful extension code.