Skip to main content

eln_plugin_sdk/
tool.rs

1//! Tool 호출 표면 — plugin이 노출하는 단위 tool의 trait.
2
3use async_trait::async_trait;
4use serde_json::Value;
5
6use crate::{Identity, Permissions, ToolError};
7
8/// Tool 호출 시 plugin handler에 전달되는 컨텍스트.
9///
10/// `session_id`는 transport가 발급 (stdio: UUID v4, HTTP: `Mcp-Session-Id`).
11/// `permissions`는 caller에게 부여된 권한 비트 — S2는 stdio=ADMIN, HTTP=READ
12/// hard-code, S3에서 ApiKey-derived로 교체.
13#[derive(Debug, Clone)]
14#[non_exhaustive]
15pub struct CallContext {
16    pub session_id: String,
17    pub identity: Identity,
18    pub permissions: Permissions,
19}
20
21impl CallContext {
22    pub fn new(session_id: String, identity: Identity, permissions: Permissions) -> Self {
23        Self {
24            session_id,
25            identity,
26            permissions,
27        }
28    }
29}
30
31#[async_trait]
32pub trait ToolHandler: Send + Sync {
33    /// Tool 이름 (MCP tool name과 매핑).
34    fn name(&self) -> &str;
35
36    /// Tool 한 줄 설명 (MCP description).
37    fn description(&self) -> &str;
38
39    /// 핸들러 본체.
40    async fn call(&self, ctx: &CallContext, args: Value) -> Result<Value, ToolError>;
41}