1use async_trait::async_trait;
8use serde::{Deserialize, Serialize};
9use std::collections::HashMap;
10use std::time::{Duration, SystemTime};
11
12use crate::core::error::McpError;
13use crate::protocol::types::*;
14
15#[derive(Debug, Clone)]
21pub struct RetryConfig {
22 pub max_attempts: u32,
23 pub initial_delay: Duration,
24 pub max_delay: Duration,
25 pub backoff_multiplier: f32,
26}
27
28impl Default for RetryConfig {
29 fn default() -> Self {
30 Self {
31 max_attempts: 3,
32 initial_delay: Duration::from_millis(100),
33 max_delay: Duration::from_secs(10),
34 backoff_multiplier: 2.0,
35 }
36 }
37}
38
39#[derive(Debug, Clone)]
41pub struct ConnectionConfig {
42 pub timeout: Duration,
43 pub keep_alive: bool,
44 pub max_idle_time: Duration,
45 pub retry_config: RetryConfig,
46}
47
48impl Default for ConnectionConfig {
49 fn default() -> Self {
50 Self {
51 timeout: Duration::from_secs(30),
52 keep_alive: true,
53 max_idle_time: Duration::from_secs(300),
54 retry_config: RetryConfig::default(),
55 }
56 }
57}
58
59#[derive(Debug, Clone)]
61pub struct SessionConfig {
62 pub heartbeat_interval_ms: Duration,
63 pub max_concurrent_requests: usize,
64 pub connection_config: ConnectionConfig,
65}
66
67impl Default for SessionConfig {
68 fn default() -> Self {
69 Self {
70 heartbeat_interval_ms: Duration::from_secs(30),
71 max_concurrent_requests: 100,
72 connection_config: ConnectionConfig::default(),
73 }
74 }
75}
76
77#[derive(Debug, Clone, PartialEq)]
79pub enum ClientState {
80 Disconnected,
81 Connecting,
82 Initializing,
83 Ready,
84 Disconnecting,
85 Error(String),
86}
87
88#[derive(Debug, Clone, PartialEq)]
90pub enum SessionState {
91 Created,
92 Active,
93 Suspended,
94 Terminated,
95}
96
97#[derive(Debug, Clone, PartialEq)]
103pub enum HealthStatus {
104 Healthy,
105 Warning(String),
106 Unhealthy(String),
107}
108
109#[derive(Debug, Clone)]
111pub struct HealthReport {
112 pub status: HealthStatus,
113 pub checks: HashMap<String, HealthStatus>,
114 pub timestamp: SystemTime,
115}
116
117pub struct HealthChecker {
119 checks: HashMap<String, Box<dyn Fn() -> Result<HealthStatus, McpError> + Send + Sync>>,
120}
121
122impl Default for HealthChecker {
123 fn default() -> Self {
124 Self::new()
125 }
126}
127
128impl HealthChecker {
129 pub fn new() -> Self {
130 Self {
131 checks: HashMap::new(),
132 }
133 }
134
135 pub fn add_check(
136 &mut self,
137 name: &str,
138 check: Box<dyn Fn() -> Result<HealthStatus, McpError> + Send + Sync>,
139 ) {
140 self.checks.insert(name.to_string(), check);
141 }
142
143 pub async fn check_health(&self) -> HealthReport {
144 let mut results = HashMap::new();
145 let mut overall_status = HealthStatus::Healthy;
146
147 for (name, check) in &self.checks {
148 match check() {
149 Ok(status) => {
150 match &status {
151 HealthStatus::Unhealthy(_) => {
152 overall_status =
153 HealthStatus::Unhealthy("Some checks failed".to_string());
154 }
155 HealthStatus::Warning(_)
156 if matches!(overall_status, HealthStatus::Healthy) =>
157 {
158 overall_status = status.clone();
159 }
160 _ => {}
161 }
162 results.insert(name.clone(), status);
163 }
164 Err(e) => {
165 let unhealthy = HealthStatus::Unhealthy(format!("Check failed: {e}"));
166 overall_status = HealthStatus::Unhealthy("Some checks failed".to_string());
167 results.insert(name.clone(), unhealthy);
168 }
169 }
170 }
171
172 HealthReport {
173 status: overall_status,
174 checks: results,
175 timestamp: SystemTime::now(),
176 }
177 }
178}
179
180#[derive(Debug, Clone, PartialEq)]
186pub enum ServerState {
187 Stopped,
188 Starting,
189 Running,
190 Stopping,
191 Error(String),
192}
193
194#[derive(Debug, Clone)]
196pub struct ServerConfig {
197 pub name: String,
198 pub version: String,
199 pub max_connections: usize,
200 pub request_timeout: Duration,
201 pub enable_logging: bool,
202 pub log_level: String,
203 pub smooth_shutdown_timeout: Duration,
204}
205
206#[derive(Debug, Clone)]
208pub struct SmoothShutdownConfig {
209 pub timeout: Duration,
210 pub force_after_timeout: bool,
211 pub notify_clients: bool,
212 pub save_state: bool,
213}
214
215#[derive(Debug, Clone, Serialize, Deserialize)]
217pub struct ServerPersistentState {
218 pub active_connections: Vec<String>,
219 pub registered_tools: Vec<String>,
220 pub cached_resources: HashMap<String, String>,
221 pub metrics: ServerMetricsSnapshot,
222}
223
224#[derive(Debug, Clone, Serialize, Deserialize)]
226pub struct ServerMetricsSnapshot {
227 pub total_requests: u64,
228 pub total_errors: u64,
229 pub uptime: Duration,
230 pub last_restart: SystemTime,
231}
232
233#[derive(Debug, Clone)]
235pub struct SecurityConfig {
236 pub require_authentication: bool,
237 pub rate_limiting: RateLimitConfig,
238 pub input_validation: ValidationConfig,
239 pub allowed_methods: Vec<String>,
240}
241
242#[derive(Debug, Clone)]
244pub struct RateLimitConfig {
245 pub requests_per_minute: u32,
246 pub burst_size: u32,
247 pub per_client: bool,
248}
249
250#[derive(Debug, Clone)]
252pub struct ValidationConfig {
253 pub max_request_size: usize,
254 pub max_string_length: usize,
255 pub max_array_length: usize,
256 pub sanitize_input: bool,
257}
258
259type LifecycleCallback = Box<dyn Fn() -> Result<(), McpError> + Send + Sync>;
265
266pub struct LifecycleManager {
268 state: ServerState,
269 listeners: HashMap<String, Vec<LifecycleCallback>>,
270 hooks: HashMap<String, Vec<LifecycleCallback>>,
271}
272
273impl Default for LifecycleManager {
274 fn default() -> Self {
275 Self::new()
276 }
277}
278
279impl LifecycleManager {
280 pub fn new() -> Self {
281 Self {
282 state: ServerState::Stopped,
283 listeners: HashMap::new(),
284 hooks: HashMap::new(),
285 }
286 }
287
288 pub fn get_state(&self) -> &ServerState {
289 &self.state
290 }
291
292 pub async fn transition_to(&mut self, new_state: ServerState) {
293 self.state = new_state;
294 }
295
296 pub async fn start(&mut self) -> Result<(), McpError> {
297 self.transition_to(ServerState::Starting).await;
298 self.transition_to(ServerState::Running).await;
299 Ok(())
300 }
301
302 pub async fn stop(&mut self) -> Result<(), McpError> {
303 self.transition_to(ServerState::Stopping).await;
304 self.transition_to(ServerState::Stopped).await;
305 Ok(())
306 }
307
308 pub fn on_start(&mut self, callback: Box<dyn Fn() -> Result<(), McpError> + Send + Sync>) {
309 self.listeners
310 .entry("start".to_string())
311 .or_default()
312 .push(callback);
313 }
314
315 pub fn on_stop(&mut self, callback: Box<dyn Fn() -> Result<(), McpError> + Send + Sync>) {
316 self.listeners
317 .entry("stop".to_string())
318 .or_default()
319 .push(callback);
320 }
321
322 pub fn get_listener_count(&self, event: &str) -> usize {
323 self.listeners.get(event).map(|v| v.len()).unwrap_or(0)
324 }
325
326 pub fn add_pre_start_hook(
327 &mut self,
328 hook: Box<dyn Fn() -> Result<(), McpError> + Send + Sync>,
329 ) {
330 self.hooks
331 .entry("pre_start".to_string())
332 .or_default()
333 .push(hook);
334 }
335
336 pub fn add_post_start_hook(
337 &mut self,
338 hook: Box<dyn Fn() -> Result<(), McpError> + Send + Sync>,
339 ) {
340 self.hooks
341 .entry("post_start".to_string())
342 .or_default()
343 .push(hook);
344 }
345
346 pub fn add_pre_stop_hook(&mut self, hook: Box<dyn Fn() -> Result<(), McpError> + Send + Sync>) {
347 self.hooks
348 .entry("pre_stop".to_string())
349 .or_default()
350 .push(hook);
351 }
352
353 pub fn add_post_stop_hook(
354 &mut self,
355 hook: Box<dyn Fn() -> Result<(), McpError> + Send + Sync>,
356 ) {
357 self.hooks
358 .entry("post_stop".to_string())
359 .or_default()
360 .push(hook);
361 }
362
363 pub fn get_hook_count(&self, hook_type: &str) -> usize {
364 self.hooks.get(hook_type).map(|v| v.len()).unwrap_or(0)
365 }
366}
367
368pub struct ServerRunner {
370 config: ServerConfig,
371}
372
373impl ServerRunner {
374 pub fn new(config: ServerConfig) -> Result<Self, McpError> {
375 Ok(Self { config })
376 }
377
378 pub fn get_config(&self) -> &ServerConfig {
379 &self.config
380 }
381}
382
383#[derive(Debug, Clone, PartialEq)]
389pub enum SignalType {
390 Interrupt,
391 Terminate,
392 Hangup,
393 Quit,
394}
395
396pub struct ShutdownSignalHandler {
398 signals: Vec<SignalType>,
399 shutdown_config: Option<SmoothShutdownConfig>,
400}
401
402impl Default for ShutdownSignalHandler {
403 fn default() -> Self {
404 Self::new()
405 }
406}
407
408impl ShutdownSignalHandler {
409 pub fn new() -> Self {
410 Self {
411 signals: Vec::new(),
412 shutdown_config: None,
413 }
414 }
415
416 pub fn register_signal_handler(&mut self, signal_type: SignalType) {
417 self.signals.push(signal_type);
418 }
419
420 pub fn set_shutdown_config(&mut self, config: SmoothShutdownConfig) {
421 self.shutdown_config = Some(config);
422 }
423
424 pub fn get_shutdown_config(&self) -> &SmoothShutdownConfig {
425 self.shutdown_config.as_ref().unwrap()
426 }
427}
428
429pub struct ResourceCleanupManager {
435 cleanup_tasks: HashMap<String, Box<dyn Fn() -> Result<(), McpError> + Send + Sync>>,
436}
437
438impl Default for ResourceCleanupManager {
439 fn default() -> Self {
440 Self::new()
441 }
442}
443
444impl ResourceCleanupManager {
445 pub fn new() -> Self {
446 Self {
447 cleanup_tasks: HashMap::new(),
448 }
449 }
450
451 pub fn register_cleanup(
452 &mut self,
453 name: &str,
454 task: Box<dyn Fn() -> Result<(), McpError> + Send + Sync>,
455 ) {
456 self.cleanup_tasks.insert(name.to_string(), task);
457 }
458
459 pub async fn cleanup_all(&self) -> Result<(), McpError> {
460 for (name, task) in &self.cleanup_tasks {
461 if let Err(e) = task() {
462 eprintln!("Cleanup task '{name}' failed: {e}");
463 }
464 }
465 Ok(())
466 }
467
468 pub fn get_cleanup_task_count(&self) -> usize {
469 self.cleanup_tasks.len()
470 }
471}
472
473pub struct ServerMetrics {
479 total_requests: u64,
480 request_counts: HashMap<String, u64>,
481 response_times: Vec<Duration>,
482 error_count: u64,
483 active_connections: u64,
484 start_time: SystemTime,
485}
486
487#[derive(Debug, Clone)]
489pub struct MetricsStats {
490 pub total_requests: u64,
491 pub request_counts: HashMap<String, u64>,
492 pub error_count: u64,
493 pub active_connections: u64,
494 pub average_response_time: Duration,
495 pub uptime: Duration,
496}
497
498impl Default for ServerMetrics {
499 fn default() -> Self {
500 Self::new()
501 }
502}
503
504impl ServerMetrics {
505 pub fn new() -> Self {
506 Self {
507 total_requests: 0,
508 request_counts: HashMap::new(),
509 response_times: Vec::new(),
510 error_count: 0,
511 active_connections: 0,
512 start_time: SystemTime::now(),
513 }
514 }
515
516 pub fn record_request(&mut self, method: &str) {
517 self.total_requests += 1;
518 *self.request_counts.entry(method.to_string()).or_insert(0) += 1;
519 }
520
521 pub fn record_response_time(&mut self, _method: &str, duration: Duration) {
522 self.response_times.push(duration);
523 }
524
525 pub fn record_error(&mut self, _method: &str, _error: &str) {
526 self.error_count += 1;
527 }
528
529 pub fn record_connection(&mut self) {
530 self.active_connections += 1;
531 }
532
533 pub fn record_disconnection(&mut self) {
534 if self.active_connections > 0 {
535 self.active_connections -= 1;
536 }
537 }
538
539 pub fn get_stats(&self) -> MetricsStats {
540 let average_response_time = if self.response_times.is_empty() {
541 Duration::ZERO
542 } else {
543 let total: Duration = self.response_times.iter().sum();
544 total / self.response_times.len() as u32
545 };
546
547 let uptime = SystemTime::now()
548 .duration_since(self.start_time)
549 .unwrap_or(Duration::ZERO);
550
551 MetricsStats {
552 total_requests: self.total_requests,
553 request_counts: self.request_counts.clone(),
554 error_count: self.error_count,
555 active_connections: self.active_connections,
556 average_response_time,
557 uptime,
558 }
559 }
560
561 pub fn get_most_popular_endpoints(&self, limit: usize) -> Vec<(String, u64)> {
562 let mut sorted: Vec<_> = self.request_counts.iter().collect();
563 sorted.sort_by(|a, b| b.1.cmp(a.1));
564 sorted
565 .into_iter()
566 .take(limit)
567 .map(|(k, v)| (k.clone(), *v))
568 .collect()
569 }
570}
571
572pub struct ConfigurationManager {
578 current_config: Option<ServerConfig>,
579}
580
581impl Default for ConfigurationManager {
582 fn default() -> Self {
583 Self::new()
584 }
585}
586
587impl ConfigurationManager {
588 pub fn new() -> Self {
589 Self {
590 current_config: None,
591 }
592 }
593
594 pub async fn load_config(&mut self, config: ServerConfig) -> Result<(), McpError> {
595 self.current_config = Some(config);
596 Ok(())
597 }
598
599 pub fn get_config(&self) -> &ServerConfig {
600 self.current_config.as_ref().unwrap()
601 }
602
603 pub async fn hot_reload(&mut self, new_config: ServerConfig) -> Result<(), McpError> {
604 self.current_config = Some(new_config);
605 Ok(())
606 }
607}
608
609pub struct StatePersistenceManager {
615 stored_state: Option<ServerPersistentState>,
616}
617
618impl Default for StatePersistenceManager {
619 fn default() -> Self {
620 Self::new()
621 }
622}
623
624impl StatePersistenceManager {
625 pub fn new() -> Self {
626 Self { stored_state: None }
627 }
628
629 pub async fn save_state(&mut self, state: &ServerPersistentState) -> Result<(), McpError> {
630 self.stored_state = Some(state.clone());
631 Ok(())
632 }
633
634 pub async fn load_state(&self) -> Result<ServerPersistentState, McpError> {
635 self.stored_state
636 .clone()
637 .ok_or_else(|| McpError::internal("No state stored"))
638 }
639}
640
641#[async_trait]
647pub trait Plugin: Send + Sync {
648 fn name(&self) -> &str;
649 fn version(&self) -> &str;
650 fn is_enabled(&self) -> bool;
651 async fn initialize(&mut self) -> Result<(), McpError>;
652 async fn shutdown(&mut self) -> Result<(), McpError>;
653}
654
655pub struct PluginManager {
657 plugins: Vec<Box<dyn Plugin>>,
658}
659
660impl Default for PluginManager {
661 fn default() -> Self {
662 Self::new()
663 }
664}
665
666impl PluginManager {
667 pub fn new() -> Self {
668 Self {
669 plugins: Vec::new(),
670 }
671 }
672
673 pub fn register_plugin(&mut self, plugin: Box<dyn Plugin>) {
674 self.plugins.push(plugin);
675 }
676
677 pub fn get_plugin_count(&self) -> usize {
678 self.plugins.len()
679 }
680
681 pub async fn initialize_all(&mut self) -> Result<(), McpError> {
682 for plugin in &mut self.plugins {
683 plugin.initialize().await?;
684 }
685 Ok(())
686 }
687
688 pub async fn shutdown_all(&mut self) -> Result<(), McpError> {
689 for plugin in &mut self.plugins {
690 plugin.shutdown().await?;
691 }
692 Ok(())
693 }
694
695 pub fn get_enabled_plugins(&self) -> Vec<String> {
696 self.plugins
697 .iter()
698 .filter(|p| p.is_enabled())
699 .map(|p| p.name().to_string())
700 .collect()
701 }
702}
703
704pub struct TaskHandle {
710 name: String,
711 handle: tokio::task::JoinHandle<()>,
712}
713
714impl TaskHandle {
715 pub fn name(&self) -> &str {
717 &self.name
718 }
719
720 pub fn is_finished(&self) -> bool {
722 self.handle.is_finished()
723 }
724}
725
726pub struct AsyncTaskManager {
728 tasks: HashMap<String, TaskHandle>,
729}
730
731impl Default for AsyncTaskManager {
732 fn default() -> Self {
733 Self::new()
734 }
735}
736
737impl AsyncTaskManager {
738 pub fn new() -> Self {
739 Self {
740 tasks: HashMap::new(),
741 }
742 }
743
744 pub fn spawn_task<F>(&mut self, name: &str, future: F) -> &TaskHandle
745 where
746 F: std::future::Future<Output = ()> + Send + 'static,
747 {
748 let handle = tokio::spawn(future);
749 let task_handle = TaskHandle {
750 name: name.to_string(),
751 handle,
752 };
753 self.tasks.insert(name.to_string(), task_handle);
754 self.tasks.get(name).unwrap()
755 }
756
757 pub fn get_active_task_count(&self) -> usize {
758 self.tasks
759 .iter()
760 .filter(|(_, task)| !task.is_finished())
761 .count()
762 }
763
764 pub fn is_task_running(&self, name: &str) -> bool {
765 self.tasks
766 .get(name)
767 .map(|task| !task.is_finished())
768 .unwrap_or(false)
769 }
770
771 pub fn get_task_names(&self) -> Vec<String> {
772 self.tasks.keys().cloned().collect()
773 }
774
775 pub fn get_running_task_names(&self) -> Vec<String> {
776 self.tasks
777 .iter()
778 .filter(|(_, task)| !task.is_finished())
779 .map(|(name, _)| name.clone())
780 .collect()
781 }
782
783 pub async fn cancel_task(&mut self, name: &str) {
784 if let Some(task) = self.tasks.remove(name) {
785 task.handle.abort();
786 }
787 }
788
789 pub async fn wait_for_task_completion(&self, name: &str) -> Result<(), McpError> {
790 if let Some(_task) = self.tasks.get(name) {
791 Ok(())
793 } else {
794 Err(McpError::internal("Task not found"))
795 }
796 }
797
798 pub async fn shutdown_all_tasks(&mut self, _timeout: Duration) -> Result<(), McpError> {
799 let tasks = std::mem::take(&mut self.tasks);
800 for (_, task) in tasks {
801 task.handle.abort();
802 }
803 Ok(())
804 }
805}
806
807#[derive(Debug, Clone)]
813pub enum TransportError {
814 ConnectionFailed(String),
815 SendFailed(String),
816 ReceiveFailed(String),
817 Timeout,
818 Closed,
819 InvalidMessage(String),
820}
821
822impl std::fmt::Display for TransportError {
823 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
824 match self {
825 TransportError::ConnectionFailed(msg) => write!(f, "Connection failed: {msg}"),
826 TransportError::SendFailed(msg) => write!(f, "Send failed: {msg}"),
827 TransportError::ReceiveFailed(msg) => write!(f, "Receive failed: {msg}"),
828 TransportError::Timeout => write!(f, "Operation timed out"),
829 TransportError::Closed => write!(f, "Connection closed"),
830 TransportError::InvalidMessage(msg) => write!(f, "Invalid message: {msg}"),
831 }
832 }
833}
834
835impl std::error::Error for TransportError {}
836
837#[derive(Debug, Clone)]
839pub struct HttpServerConfig {
840 pub host: String,
841 pub port: u16,
842 pub max_connections: usize,
843 pub timeout: Duration,
844}
845
846#[derive(Debug, Clone)]
848pub struct HttpRequest {
849 pub method: String,
850 pub path: String,
851 pub headers: HashMap<String, String>,
852 pub body: Option<Vec<u8>>,
853}
854
855#[derive(Debug, Clone)]
857pub struct HttpResponse {
858 pub status: u16,
859 pub headers: HashMap<String, String>,
860 pub body: Option<Vec<u8>>,
861}
862
863#[derive(Debug, Clone)]
865pub struct WebSocketServerConfig {
866 pub host: String,
867 pub port: u16,
868 pub max_connections: usize,
869 pub ping_interval: Duration,
870}
871
872#[derive(Debug, Clone)]
874pub struct WebSocketCloseFrame {
875 pub code: u16,
876 pub reason: String,
877}
878
879#[derive(Debug, Clone)]
881pub enum WebSocketMessage {
882 Text(String),
883 Binary(Vec<u8>),
884 Ping(Vec<u8>),
885 Pong(Vec<u8>),
886 Close(Option<WebSocketCloseFrame>),
887}
888
889#[derive(Debug, Clone)]
891pub struct StdioTransportConfig {
892 pub buffer_size: usize,
893 pub line_ending: String,
894}
895
896#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
902pub enum CompletionTriggerKind {
903 Invoked,
904 TriggerCharacter,
905 TriggerForIncompleteCompletions,
906}
907
908#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
910pub struct CompletionParams {
911 pub position: Option<CompletionPosition>,
912 pub context: Option<CompletionContext>,
913}
914
915#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
917pub struct CompletionPosition {
918 pub line: u32,
919 pub character: u32,
920}
921
922#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
924pub struct CompletionContext {
925 pub trigger_kind: CompletionTriggerKind,
926 pub trigger_character: Option<String>,
927}
928
929#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
931pub enum CompletionItemKind {
932 Text = 1,
933 Method = 2,
934 Function = 3,
935 Constructor = 4,
936 Field = 5,
937 Variable = 6,
938 Class = 7,
939 Interface = 8,
940 Module = 9,
941 Property = 10,
942 Unit = 11,
943 Value = 12,
944 Enum = 13,
945 Keyword = 14,
946 Snippet = 15,
947 Color = 16,
948 File = 17,
949 Reference = 18,
950 Folder = 19,
951 EnumMember = 20,
952 Constant = 21,
953 Struct = 22,
954 Event = 23,
955 Operator = 24,
956 TypeParameter = 25,
957}
958
959#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
961pub struct TextEdit {
962 pub range: Range,
963 pub new_text: String,
964}
965
966#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
968pub struct Range {
969 pub start: Position,
970 pub end: Position,
971}
972
973#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
975pub struct Position {
976 pub line: u32,
977 pub character: u32,
978}
979
980#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
982pub struct Command {
983 pub title: String,
984 pub command: String,
985 pub arguments: Option<Vec<serde_json::Value>>,
986}
987
988#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
990pub struct CompletionItem {
991 pub label: String,
992 pub kind: Option<CompletionItemKind>,
993 pub detail: Option<String>,
994 pub documentation: Option<String>,
995 pub sort_text: Option<String>,
996 pub filter_text: Option<String>,
997 pub insert_text: Option<String>,
998 pub text_edit: Option<TextEdit>,
999 pub command: Option<Command>,
1000}
1001
1002#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1004pub struct CompletionResult {
1005 pub items: Vec<CompletionItem>,
1006 pub is_incomplete: Option<bool>,
1007}
1008
1009#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1011pub struct EmbeddedResourceContent {
1012 pub uri: String,
1013 pub mime_type: Option<String>,
1014 pub content: String,
1015}
1016
1017#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1019pub struct ImprovedProgressNotification {
1020 pub token: ProgressToken,
1021 pub message: Option<String>,
1022 pub percentage: Option<f32>,
1023 pub total: Option<u64>,
1024 pub current: u64,
1025}
1026
1027#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1029pub struct ImprovedServerCapabilities {
1030 pub completion: Option<CompletionCapabilities>,
1031 pub streaming: Option<StreamingCapabilities>,
1032 pub batch_operations: Option<BatchCapabilities>,
1033}
1034
1035#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
1037pub struct CompletionCapabilities {
1038 pub trigger_characters: Option<Vec<String>>,
1039 pub all_commit_characters: Option<Vec<String>>,
1040}
1041
1042#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
1044pub struct StreamingCapabilities {
1045 pub supported: bool,
1046 pub max_chunk_size: Option<usize>,
1047}
1048
1049#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Default)]
1051pub struct BatchCapabilities {
1052 pub max_operations: Option<usize>,
1053 pub supported_operations: Option<Vec<String>>,
1054}
1055
1056#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1058pub struct BatchOperationRequest {
1059 pub operations: Vec<BatchOperation>,
1060}
1061
1062#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1064pub struct BatchOperation {
1065 pub id: String,
1066 pub method: String,
1067 pub params: Option<serde_json::Value>,
1068}
1069
1070#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1072pub struct BatchOperationResponse {
1073 pub results: Vec<BatchOperationResult>,
1074}
1075
1076#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1078pub struct BatchOperationResult {
1079 pub id: String,
1080 pub result: Option<serde_json::Value>,
1081 pub error: Option<JsonRpcError>,
1082}
1083
1084#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
1086pub struct StreamingResponse {
1087 pub chunk_id: u64,
1088 pub total_chunks: Option<u64>,
1089 pub is_final: bool,
1090 pub data: serde_json::Value,
1091}
1092
1093pub type RootsCapabilities = RootsCapability;
1098pub type PromptsCapabilities = PromptsCapability;
1099pub type ResourcesCapabilities = ResourcesCapability;
1100pub type ToolsCapabilities = ToolsCapability;
1101pub type LoggingCapabilities = LoggingCapability;