turbomcp_protocol/types/
requests.rs

1//! Request/response/notification routing types
2//!
3//! This module contains the top-level enums that route different types of
4//! MCP requests and notifications between clients and servers.
5
6use serde::{Deserialize, Serialize};
7
8use super::{
9    completion::CompleteRequestParams,
10    elicitation::ElicitRequestParams,
11    initialization::{InitializeRequest, InitializedNotification},
12    logging::{LoggingNotification, ProgressNotification, SetLevelRequest},
13    ping::PingParams,
14    prompts::{GetPromptRequest, ListPromptsRequest},
15    resources::{
16        ListResourceTemplatesRequest, ListResourcesRequest, ReadResourceRequest,
17        ResourceUpdatedNotification, SubscribeRequest, UnsubscribeRequest,
18    },
19    roots::{ListRootsRequest, RootsListChangedNotification},
20    sampling::CreateMessageRequest,
21    tools::{CallToolRequest, ListToolsRequest},
22};
23
24/// Client-initiated request
25#[derive(Debug, Clone, Serialize, Deserialize)]
26#[serde(tag = "method")]
27pub enum ClientRequest {
28    /// Initialize the connection
29    #[serde(rename = "initialize")]
30    Initialize(InitializeRequest),
31
32    /// List available tools
33    #[serde(rename = "tools/list")]
34    ListTools(ListToolsRequest),
35
36    /// Call a tool
37    #[serde(rename = "tools/call")]
38    CallTool(CallToolRequest),
39
40    /// List available prompts
41    #[serde(rename = "prompts/list")]
42    ListPrompts(ListPromptsRequest),
43
44    /// Get a specific prompt
45    #[serde(rename = "prompts/get")]
46    GetPrompt(GetPromptRequest),
47
48    /// List available resources
49    #[serde(rename = "resources/list")]
50    ListResources(ListResourcesRequest),
51
52    /// List resource templates
53    #[serde(rename = "resources/templates/list")]
54    ListResourceTemplates(ListResourceTemplatesRequest),
55
56    /// Read a resource
57    #[serde(rename = "resources/read")]
58    ReadResource(ReadResourceRequest),
59
60    /// Subscribe to resource updates
61    #[serde(rename = "resources/subscribe")]
62    Subscribe(SubscribeRequest),
63
64    /// Unsubscribe from resource updates
65    #[serde(rename = "resources/unsubscribe")]
66    Unsubscribe(UnsubscribeRequest),
67
68    /// Set logging level
69    #[serde(rename = "logging/setLevel")]
70    SetLevel(SetLevelRequest),
71
72    /// Complete argument
73    #[serde(rename = "completion/complete")]
74    Complete(CompleteRequestParams),
75
76    /// Ping to check connection
77    #[serde(rename = "ping")]
78    Ping(PingParams),
79}
80
81/// Server-initiated request
82#[derive(Debug, Clone, Serialize, Deserialize)]
83#[serde(tag = "method")]
84pub enum ServerRequest {
85    /// Ping to check connection
86    #[serde(rename = "ping")]
87    Ping(PingParams),
88
89    /// Create a message (sampling) - server requests LLM sampling from client
90    #[serde(rename = "sampling/createMessage")]
91    CreateMessage(CreateMessageRequest),
92
93    /// List filesystem roots - server requests root URIs from client
94    #[serde(rename = "roots/list")]
95    ListRoots(ListRootsRequest),
96
97    /// Elicit user input
98    #[serde(rename = "elicitation/create")]
99    ElicitationCreate(ElicitRequestParams),
100}
101
102/// Client-sent notification
103#[derive(Debug, Clone, Serialize, Deserialize)]
104#[serde(tag = "method")]
105pub enum ClientNotification {
106    /// Connection initialized
107    #[serde(rename = "notifications/initialized")]
108    Initialized(InitializedNotification),
109
110    /// Progress update
111    #[serde(rename = "notifications/progress")]
112    Progress(ProgressNotification),
113
114    /// Roots list changed
115    #[serde(rename = "notifications/roots/list_changed")]
116    RootsListChanged(RootsListChangedNotification),
117}
118
119/// Server-sent notification
120#[derive(Debug, Clone, Serialize, Deserialize)]
121#[serde(tag = "method")]
122pub enum ServerNotification {
123    /// Log message
124    #[serde(rename = "notifications/message")]
125    Message(LoggingNotification),
126
127    /// Resource updated
128    #[serde(rename = "notifications/resources/updated")]
129    ResourceUpdated(ResourceUpdatedNotification),
130
131    /// Resource list changed
132    #[serde(rename = "notifications/resources/list_changed")]
133    ResourceListChanged,
134
135    /// Progress update
136    #[serde(rename = "notifications/progress")]
137    Progress(ProgressNotification),
138
139    /// Request cancellation
140    #[serde(rename = "notifications/cancelled")]
141    Cancelled(CancelledNotification),
142
143    /// Prompts list changed
144    #[serde(rename = "notifications/prompts/list_changed")]
145    PromptsListChanged,
146
147    /// Tools list changed
148    #[serde(rename = "notifications/tools/list_changed")]
149    ToolsListChanged,
150
151    /// Roots list changed
152    #[serde(rename = "notifications/roots/list_changed")]
153    RootsListChanged,
154}
155
156/// Cancellation notification
157#[derive(Debug, Clone, Serialize, Deserialize)]
158pub struct CancelledNotification {
159    /// Request ID that was cancelled
160    #[serde(rename = "requestId")]
161    pub request_id: super::core::RequestId,
162    /// Optional reason for cancellation
163    pub reason: Option<String>,
164}