Skip to main content

eln_plugin_sdk/
server.rs

1//! Plugin server 표면 — tool 집합 노출.
2
3use std::sync::Arc;
4
5use serde_json::Value;
6
7use crate::{Permissions, ToolHandler};
8
9/// Tool descriptor — handler + metadata.
10///
11/// `#[non_exhaustive]`: 미래에 field 추가가 caller code를 깨지 않도록 (codex review 1
12/// 권고). 외부에서는 `ToolDescriptor::new(handler).with_*` builder로만 구성.
13#[derive(Clone)]
14#[non_exhaustive]
15pub struct ToolDescriptor {
16    handler: Arc<dyn ToolHandler>,
17    input_schema: Option<Value>,
18    required_permissions: Permissions,
19    annotations: Option<Value>,
20}
21
22impl ToolDescriptor {
23    pub fn new<H: ToolHandler + 'static>(handler: H) -> Self {
24        Self {
25            handler: Arc::new(handler),
26            input_schema: None,
27            required_permissions: Permissions::empty(),
28            annotations: None,
29        }
30    }
31
32    pub fn with_input_schema(mut self, schema: Value) -> Self {
33        self.input_schema = Some(schema);
34        self
35    }
36
37    pub fn with_required_permissions(mut self, perms: Permissions) -> Self {
38        self.required_permissions = perms;
39        self
40    }
41
42    pub fn with_annotations(mut self, ann: Value) -> Self {
43        self.annotations = Some(ann);
44        self
45    }
46
47    pub fn name(&self) -> &str {
48        self.handler.name()
49    }
50
51    pub fn description(&self) -> &str {
52        self.handler.description()
53    }
54
55    pub fn input_schema(&self) -> Option<&Value> {
56        self.input_schema.as_ref()
57    }
58
59    pub fn required_permissions(&self) -> Permissions {
60        self.required_permissions
61    }
62
63    pub fn annotations(&self) -> Option<&Value> {
64        self.annotations.as_ref()
65    }
66
67    /// transport adapter 전용 handler accessor.
68    /// SDK consumer는 일반적으로 `name/description/...` 만 보면 충분.
69    pub fn handler(&self) -> &Arc<dyn ToolHandler> {
70        &self.handler
71    }
72}
73
74pub trait PluginServer {
75    fn tools(&self) -> Vec<ToolDescriptor>;
76}