pub trait StatefulPlugin:
Send
+ Sync
+ 'static {
type Context: PluginContext;
// Required methods
fn name(&self) -> &'static str;
fn list_tools(&self) -> Vec<Tool>;
fn tool_descriptors(&self) -> Vec<ToolDescriptor>;
fn context(&self) -> Arc<Self::Context>;
}Expand description
A stateful plugin with a typed context.
Implement this trait (instead of ElicitPlugin directly) when your
plugin needs server-side state — a DB pool, HTTP client, etc. The context
lives in an Arc<Self::Context> that is cloned into each tool handler.
A blanket impl of ElicitPlugin is provided for all StatefulPlugin
types. The context is type-erased at dispatch time using Arc<dyn Any>.
§Example
pub struct MyCtx { pub client: String }
impl PluginContext for MyCtx {}
pub struct MyPlugin(Arc<MyCtx>);
impl StatefulPlugin for MyPlugin {
type Context = MyCtx;
fn name(&self) -> &'static str { "my" }
fn list_tools(&self) -> Vec<Tool> { vec![] }
fn tool_descriptors(&self) -> Vec<ToolDescriptor> { vec![] }
fn context(&self) -> Arc<MyCtx> { self.0.clone() }
}Required Associated Types§
Sourcetype Context: PluginContext
type Context: PluginContext
The plugin’s context type.
Required Methods§
Sourcefn list_tools(&self) -> Vec<Tool>
fn list_tools(&self) -> Vec<Tool>
All tools provided by this plugin (MCP schema layer).
Sourcefn tool_descriptors(&self) -> Vec<ToolDescriptor>
fn tool_descriptors(&self) -> Vec<ToolDescriptor>
All descriptors provided by this plugin (handler layer).
Named tool_descriptors to avoid collision with DescriptorPlugin::descriptors.