rs_utcp/
spec.rs

1use serde::{Deserialize, Serialize};
2
3/// v1.0 call template model (simplified to cover current transports).
4#[derive(Debug, Clone, Serialize, Deserialize)]
5#[serde(rename_all = "snake_case")]
6pub struct CallTemplate {
7    /// The type of the call template (e.g., "http", "cli").
8    pub call_template_type: String,
9    /// Optional name for the template.
10    #[serde(default)]
11    pub name: Option<String>,
12    /// URL for HTTP-based templates.
13    #[serde(default)]
14    pub url: Option<String>,
15    /// HTTP method for HTTP-based templates.
16    #[serde(default)]
17    pub http_method: Option<String>,
18    /// Command string for CLI-based templates.
19    #[serde(default)]
20    pub command: Option<String>,
21    /// List of commands for multi-step CLI templates.
22    #[serde(default)]
23    pub commands: Option<Vec<TemplateCommand>>,
24    /// Environment variables to set for the command.
25    #[serde(default)]
26    pub env_vars: Option<std::collections::HashMap<String, String>>,
27    /// Working directory for the command.
28    #[serde(default)]
29    pub working_dir: Option<String>,
30    /// List of allowed communication protocol types (e.g., ["http", "cli"]).
31    /// If undefined, null, or empty, defaults to only allowing this template's own call_template_type.
32    /// This provides secure-by-default behavior where a manual can only register/call tools
33    /// that use its own protocol unless explicitly configured otherwise.
34    #[serde(skip_serializing_if = "Option::is_none")]
35    #[serde(default)]
36    pub allowed_communication_protocols: Option<Vec<String>>,
37}
38
39/// Represents a single command in a multi-step CLI template.
40#[derive(Debug, Clone, Serialize, Deserialize)]
41pub struct TemplateCommand {
42    /// The command string to execute.
43    pub command: String,
44    /// Whether to append the output of this command to the final result.
45    #[serde(default)]
46    pub append_to_final_output: Option<bool>,
47}
48
49/// Metadata information about a manual.
50#[derive(Debug, Clone, Serialize, Deserialize)]
51pub struct ManualInfo {
52    /// Title of the manual.
53    pub title: String,
54    /// Version of the manual.
55    pub version: String,
56    #[serde(default)]
57    /// Optional description of the manual.
58    pub description: Option<String>,
59}
60
61/// Represents a tool definition within a manual.
62#[derive(Debug, Clone, Serialize, Deserialize)]
63pub struct ManualTool {
64    /// Name of the tool.
65    pub name: String,
66    /// Description of what the tool does.
67    pub description: String,
68    /// JSON schema for the tool's inputs.
69    pub inputs: serde_json::Value,
70    /// JSON schema for the tool's outputs.
71    pub outputs: serde_json::Value,
72    /// Tags associated with the tool.
73    #[serde(default)]
74    pub tags: Vec<String>,
75    /// The call template defining how to execute the tool.
76    #[serde(default)]
77    pub tool_call_template: Option<CallTemplate>,
78    /// Legacy provider definition (deprecated).
79    #[serde(default)]
80    pub provider: Option<CallTemplate>, // legacy in-tool provider
81}
82
83/// Represents a v1.0 Manual structure containing tool definitions and metadata.
84#[derive(Debug, Clone, Serialize, Deserialize)]
85pub struct ManualV1 {
86    /// Version of the manual format.
87    pub manual_version: String,
88    /// Version of the UTCP protocol.
89    pub utcp_version: String,
90    /// Metadata about the manual.
91    pub info: ManualInfo,
92    /// List of tools defined in the manual.
93    pub tools: Vec<ManualTool>,
94    /// List of allowed communication protocol types for tools in this manual.
95    /// If undefined, null, or empty, defaults to only allowing each tool's own protocol type.
96    /// This provides secure-by-default behavior.
97    #[serde(skip_serializing_if = "Option::is_none")]
98    #[serde(default)]
99    pub allowed_communication_protocols: Option<Vec<String>>,
100}