prism_mcp_rs/plugin/
types.rs1use crate::core::error::McpResult;
4use crate::core::prompt::Prompt;
5use crate::core::resource::Resource;
6use crate::core::tool::Tool;
7use async_trait::async_trait;
8use serde::{Deserialize, Serialize};
9use serde_json::Value;
10use std::collections::HashMap;
11
12#[derive(Debug, Clone)]
14pub struct LoadResult {
15 pub count: usize,
17 pub plugins: Vec<LoadedPluginInfo>,
19 pub errors: Vec<(String, crate::plugin::PluginError)>,
21}
22
23#[derive(Debug, Clone)]
25pub struct LoadedPluginInfo {
26 pub name: String,
28 pub version: String,
30 pub path: std::path::PathBuf,
32 pub enabled: bool,
34}
35use std::path::PathBuf;
36use std::sync::Arc;
37
38#[async_trait]
40pub trait Plugin: Send + Sync {
41 fn name(&self) -> &str;
43
44 fn version(&self) -> &str;
46
47 fn description(&self) -> &str;
49
50 async fn initialize(&mut self) -> McpResult<()>;
52
53 async fn shutdown(&mut self) -> McpResult<()>;
55
56 async fn configure(&mut self, config: Value) -> McpResult<()>;
58
59 fn capabilities(&self) -> PluginCapabilities;
61
62 fn metadata(&self) -> PluginMetadata;
64}
65
66#[derive(Debug, Clone, Default, Serialize, Deserialize)]
68pub struct PluginCapabilities {
69 pub provides_tools: bool,
71
72 pub provides_resources: bool,
74
75 pub provides_prompts: bool,
77
78 pub supports_hot_reload: bool,
80}
81
82#[derive(Debug, Clone, Default, Serialize, Deserialize)]
84pub struct PluginMetadata {
85 pub author: Option<String>,
87
88 pub license: Option<String>,
90
91 pub homepage: Option<String>,
93
94 pub repository: Option<String>,
96
97 pub keywords: Vec<String>,
99
100 pub categories: Vec<String>,
102}
103
104#[derive(Debug, Clone, Serialize, Deserialize)]
106pub struct PluginInfo {
107 pub name: String,
109
110 pub version: String,
112
113 pub path: PathBuf,
115
116 pub enabled: bool,
118
119 pub capabilities: PluginCapabilities,
121
122 pub metadata: PluginMetadata,
124}
125
126#[derive(Debug, Clone, Serialize, Deserialize)]
128pub struct PluginConfig {
129 pub enabled: bool,
131
132 pub auto_reload: bool,
134
135 pub config_path: Option<PathBuf>,
137
138 pub settings: Value,
140}
141
142impl Default for PluginConfig {
143 fn default() -> Self {
144 Self {
145 enabled: true,
146 auto_reload: false,
147 config_path: None,
148 settings: Value::Null,
149 }
150 }
151}
152
153pub struct LoadedPlugin {
155 pub plugin: Box<dyn Plugin>,
157
158 pub config: PluginConfig,
160
161 pub tools: HashMap<String, Arc<Tool>>,
163
164 pub resources: HashMap<String, Arc<Resource>>,
166
167 pub prompts: HashMap<String, Arc<Prompt>>,
169}