PluginRegistry

Struct PluginRegistry 

Source
pub struct PluginRegistry { /* private fields */ }
Expand description

Registry for managing client plugins

The registry maintains an ordered list of plugins and provides methods for:

  • Plugin registration and validation
  • Middleware chain execution
  • Custom method routing
  • Plugin lifecycle management

§Examples

use turbomcp_client::plugins::{PluginRegistry, MetricsPlugin, PluginConfig};
use std::sync::Arc;

let mut registry = PluginRegistry::new();

// Register a metrics plugin
let metrics = Arc::new(MetricsPlugin::new(PluginConfig::Metrics));
registry.register_plugin(metrics).await?;

// Execute middleware chain
// let mut request_context = RequestContext::new(...);
// registry.execute_before_request(&mut request_context).await?;

Implementations§

Source§

impl PluginRegistry

Source

pub fn new() -> Self

Create a new empty plugin registry

Source

pub fn set_client_context(&mut self, context: PluginContext)

Set the client context for plugin initialization

This should be called once when the client is initialized to provide context information to plugins during registration.

Source

pub async fn register_plugin( &mut self, plugin: Arc<dyn ClientPlugin>, ) -> PluginResult<()>

Register a new plugin

Validates the plugin, checks dependencies, and initializes it. Plugins are executed in registration order.

§Arguments
  • plugin - The plugin to register
§Returns

Returns Ok(()) if registration succeeds, or PluginError if it fails.

§Errors
  • Plugin name already registered
  • Plugin dependencies not met
  • Plugin initialization failure
Source

pub async fn unregister_plugin(&mut self, plugin_name: &str) -> PluginResult<()>

Unregister a plugin by name

Removes the plugin from the registry and calls its cleanup method.

§Arguments
  • plugin_name - Name of the plugin to unregister
§Returns

Returns Ok(()) if unregistration succeeds, or PluginError if it fails.

Source

pub fn has_plugin(&self, plugin_name: &str) -> bool

Check if a plugin is registered

Source

pub fn get_plugin(&self, plugin_name: &str) -> Option<Arc<dyn ClientPlugin>>

Get a plugin by name

Source

pub fn get_plugin_names(&self) -> Vec<String>

Get all registered plugin names in execution order

Source

pub fn plugin_count(&self) -> usize

Get the number of registered plugins

Source

pub async fn execute_before_request( &self, context: &mut RequestContext, ) -> PluginResult<()>

Execute before_request middleware chain

Calls before_request on all registered plugins in order. If any plugin returns an error, the chain is aborted and the error is returned.

§Arguments
  • context - Mutable request context that can be modified by plugins
§Returns

Returns Ok(()) if all plugins succeed, or the first PluginError encountered.

Source

pub async fn execute_after_response( &self, context: &mut ResponseContext, ) -> PluginResult<()>

Execute after_response middleware chain

Calls after_response on all registered plugins in order. Unlike before_request, this continues execution even if a plugin fails, logging errors but not aborting the chain.

§Arguments
  • context - Mutable response context that can be modified by plugins
§Returns

Returns Ok(()) unless all plugins fail, in which case returns the last error.

Source

pub async fn handle_custom_method( &self, method: &str, params: Option<Value>, ) -> PluginResult<Option<Value>>

Handle custom method by routing to appropriate plugin

Attempts to handle the custom method by calling handle_custom on each plugin in order until one returns Some(Value).

§Arguments
  • method - The custom method name
  • params - Optional parameters for the method
§Returns

Returns Some(Value) if a plugin handled the method, None if no plugin handled it, or PluginError if handling failed.

Source

pub fn get_plugin_info(&self) -> Vec<(String, String, Option<String>)>

Get plugin information for debugging

Source

pub fn validate_dependencies(&self) -> Result<(), Vec<String>>

Validate plugin dependencies

Checks that all registered plugins have their dependencies satisfied. This is useful for debugging plugin configuration issues.

Source

pub async fn clear(&mut self) -> PluginResult<()>

Clear all registered plugins

Calls cleanup on all plugins and removes them from the registry. This is primarily useful for testing and shutdown scenarios.

Trait Implementations§

Source§

impl Debug for PluginRegistry

Source§

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

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

impl Default for PluginRegistry

Source§

fn default() -> Self

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

Auto Trait Implementations§

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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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