turbomcp_protocol/context/
completion.rs1use std::collections::HashMap;
7
8use serde::{Deserialize, Serialize};
9use uuid::Uuid;
10
11#[derive(Debug, Clone, Serialize, Deserialize)]
13pub struct CompletionContext {
14 pub completion_id: String,
16 pub completion_ref: CompletionReference,
18 pub argument_name: Option<String>,
20 pub partial_value: Option<String>,
22 pub resolved_arguments: HashMap<String, String>,
24 pub completions: Vec<CompletionOption>,
26 pub cursor_position: Option<usize>,
28 pub max_completions: Option<usize>,
30 pub has_more: bool,
32 pub total_completions: Option<usize>,
34 pub client_capabilities: Option<CompletionCapabilities>,
36 pub metadata: HashMap<String, serde_json::Value>,
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
42pub struct CompletionCapabilities {
43 pub supports_pagination: bool,
45 pub supports_fuzzy: bool,
47 pub max_batch_size: usize,
49 pub supports_descriptions: bool,
51}
52
53#[derive(Debug, Clone, Serialize, Deserialize)]
55pub enum CompletionReference {
56 Prompt {
58 name: String,
60 argument: String,
62 },
63 ResourceTemplate {
65 name: String,
67 parameter: String,
69 },
70 Tool {
72 name: String,
74 argument: String,
76 },
77 Custom {
79 ref_type: String,
81 metadata: HashMap<String, serde_json::Value>,
83 },
84}
85
86#[derive(Debug, Clone, Serialize, Deserialize)]
88pub struct CompletionOption {
89 pub value: String,
91 pub label: Option<String>,
93 pub completion_type: Option<String>,
95 pub documentation: Option<String>,
97 pub sort_priority: Option<i32>,
99 pub insert_text: Option<String>,
101}
102
103impl CompletionContext {
104 pub fn new(completion_ref: CompletionReference) -> Self {
106 Self {
107 completion_id: Uuid::new_v4().to_string(),
108 completion_ref,
109 argument_name: None,
110 partial_value: None,
111 resolved_arguments: HashMap::new(),
112 completions: Vec::new(),
113 cursor_position: None,
114 max_completions: Some(100),
115 has_more: false,
116 total_completions: None,
117 client_capabilities: None,
118 metadata: HashMap::new(),
119 }
120 }
121
122 pub fn add_completion(&mut self, option: CompletionOption) {
124 self.completions.push(option);
125 }
126
127 pub fn with_resolved_arguments(mut self, args: HashMap<String, String>) -> Self {
129 self.resolved_arguments = args;
130 self
131 }
132}