mcp_runner/sse_proxy/types.rs
1//! Type definitions for the SSE proxy implementation.
2//!
3//! This module contains the core data structures used by the SSE proxy.
4
5use crate::server::ServerId;
6use serde::{Deserialize, Serialize};
7
8/// Server information
9#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct ServerInfo {
11 /// Server name
12 pub name: String,
13 /// Server ID (as string for serialization)
14 pub id: String,
15 /// Server status (as string for serialization)
16 pub status: String,
17}
18
19/// Server-Sent Event types
20#[derive(Debug, Clone, Serialize, Deserialize)]
21#[serde(tag = "type")]
22pub enum SSEEvent {
23 /// Server status update event
24 #[serde(rename = "server-status")]
25 ServerStatus {
26 /// Server name
27 server_name: String,
28 /// Server ID
29 server_id: String,
30 /// Status description
31 status: String,
32 },
33
34 /// General notification event
35 #[serde(rename = "notification")]
36 Notification {
37 /// Notification title
38 title: String,
39 /// Notification message
40 message: String,
41 /// Notification level (info, warn, error)
42 level: String,
43 },
44}
45
46/// Server-Sent Event message
47#[derive(Debug, Clone, Serialize, Deserialize)]
48pub struct SSEMessage {
49 /// Event type
50 pub event: String,
51 /// Event data as JSON string
52 pub data: String,
53 /// Optional event ID
54 pub id: Option<String>,
55}
56
57impl SSEMessage {
58 /// Creates a new SSE message with the given event type, data payload, and optional ID
59 ///
60 /// # Arguments
61 ///
62 /// * `event` - The event type (e.g., "tool-response", "tool-error", "server-status")
63 /// * `data` - The data payload as a JSON string
64 /// * `id` - Optional event ID for correlation
65 ///
66 /// # Returns
67 ///
68 /// A new `SSEMessage` instance
69 pub fn new(event: &str, data: &str, id: Option<&str>) -> Self {
70 Self {
71 event: event.to_string(),
72 data: data.to_string(),
73 id: id.map(String::from),
74 }
75 }
76}
77
78/// Server information update message sent between
79/// McpRunner and the SSEProxy
80#[derive(Debug, Clone)]
81pub enum ServerInfoUpdate {
82 /// Update information about a specific server
83 UpdateServer {
84 /// Server name
85 name: String,
86 /// Server ID
87 id: Option<ServerId>,
88 /// Server status
89 status: String,
90 },
91
92 /// Add a new server to the proxy cache
93 AddServer {
94 /// Server name
95 name: String,
96 /// Server information
97 info: ServerInfo,
98 },
99
100 /// Shutdown the proxy
101 Shutdown,
102}