prism_mcp_rs/plugin/
mod.rs

1//! Plugin System for Dynamic Tool Loading
2//!
3//! This module provides a complete plugin system for dynamically loading and managing
4//! MCP tools at runtime. It supports:
5//!
6//! - Dynamic library loading (.so, .dll, .dylib)
7//! - Hot reloading without server restart
8//! - Configuration-based plugin management
9//! - Automatic tool discovery and registration
10//! - Plugin isolation and lifecycle management
11
12pub mod api;
13pub mod config;
14pub mod loader;
15pub mod manager;
16pub mod registry;
17pub mod types;
18pub mod watcher;
19
20#[cfg(test)]
21mod comprehensive_test;
22#[cfg(test)]
23mod loader_test;
24#[cfg(test)]
25mod manager_test;
26
27pub use api::{
28    PluginBuilder, PluginCapabilities, PluginDependency, PluginFactory, PluginMetadata,
29    StandardPluginBuilder, ToolPlugin,
30};
31// Re-export ToolResult from protocol types
32pub use crate::protocol::types::CallToolResult as ToolResult;
33pub use config::{PluginConfig, PluginManifest};
34pub use loader::PluginLoader;
35pub use manager::PluginManager;
36pub use registry::ToolRegistry;
37pub use types::*;
38pub use watcher::PluginWatcher;
39
40// Re-export the macro
41pub use crate::export_plugin;
42
43use crate::core::error::McpError;
44
45/// Plugin system errors
46#[derive(Debug, Clone, thiserror::Error)]
47pub enum PluginError {
48    #[error("Plugin load failed: {0}")]
49    LoadFailed(String),
50
51    #[error("Plugin not found: {0}")]
52    NotFound(String),
53
54    #[error("Plugin already loaded: {0}")]
55    AlreadyLoaded(String),
56
57    #[error("Plugin initialization failed: {0}")]
58    InitializationFailed(String),
59
60    #[error("Invalid plugin: {0}")]
61    InvalidPlugin(String),
62
63    #[error("Version mismatch: expected {expected}, got {actual}")]
64    VersionMismatch { expected: String, actual: String },
65
66    #[error("Missing dependency: {0}")]
67    MissingDependency(String),
68
69    #[error("Plugin communication error: {0}")]
70    CommunicationError(String),
71}
72
73impl From<PluginError> for McpError {
74    fn from(err: PluginError) -> Self {
75        McpError::Protocol(err.to_string())
76    }
77}
78
79/// Plugin lifecycle events
80#[derive(Debug, Clone)]
81pub enum PluginEvent {
82    /// Plugin was loaded
83    Loaded { plugin_id: String },
84
85    /// Plugin was unloaded
86    Unloaded { plugin_id: String },
87
88    /// Plugin was reloaded
89    Reloaded { plugin_id: String },
90
91    /// Plugin encountered an error
92    Error { plugin_id: String, error: String },
93
94    /// Plugin tool was registered
95    ToolRegistered {
96        plugin_id: String,
97        tool_name: String,
98    },
99
100    /// Plugin tool was unregistered
101    ToolUnregistered {
102        plugin_id: String,
103        tool_name: String,
104    },
105}
106
107/// Result type for plugin operations
108pub type PluginResult<T> = Result<T, PluginError>;