use std::sync::Arc;
use serde_json::Value;
use crate::{Permissions, ToolHandler};
#[derive(Clone)]
#[non_exhaustive]
pub struct ToolDescriptor {
handler: Arc<dyn ToolHandler>,
input_schema: Option<Value>,
required_permissions: Permissions,
annotations: Option<Value>,
}
impl ToolDescriptor {
pub fn new<H: ToolHandler + 'static>(handler: H) -> Self {
Self {
handler: Arc::new(handler),
input_schema: None,
required_permissions: Permissions::empty(),
annotations: None,
}
}
pub fn with_input_schema(mut self, schema: Value) -> Self {
self.input_schema = Some(schema);
self
}
pub fn with_required_permissions(mut self, perms: Permissions) -> Self {
self.required_permissions = perms;
self
}
pub fn with_annotations(mut self, ann: Value) -> Self {
self.annotations = Some(ann);
self
}
pub fn name(&self) -> &str {
self.handler.name()
}
pub fn description(&self) -> &str {
self.handler.description()
}
pub fn input_schema(&self) -> Option<&Value> {
self.input_schema.as_ref()
}
pub fn required_permissions(&self) -> Permissions {
self.required_permissions
}
pub fn annotations(&self) -> Option<&Value> {
self.annotations.as_ref()
}
pub fn handler(&self) -> &Arc<dyn ToolHandler> {
&self.handler
}
}
pub trait PluginServer {
fn tools(&self) -> Vec<ToolDescriptor>;
}