turbomcp_protocol/types/
initialization.rs

1//! Types for the MCP connection initialization and handshake process.
2//!
3//! This module defines the data structures used during the initial handshake
4//! between an MCP client and server, where they negotiate capabilities and
5//! exchange implementation details.
6
7use serde::{Deserialize, Serialize};
8
9use super::{
10    capabilities::{ClientCapabilities, ServerCapabilities},
11    core::{Implementation, ProtocolVersion},
12};
13
14/// The `initialize` request is sent by the client as the first message after connection.
15///
16/// It allows the client and server to exchange their capabilities and agree on a
17/// protocol version to use for the duration of the session.
18#[derive(Debug, Clone, Serialize, Deserialize)]
19pub struct InitializeRequest {
20    /// The protocol version the client wishes to use.
21    #[serde(rename = "protocolVersion")]
22    pub protocol_version: ProtocolVersion,
23    /// The capabilities supported by the client.
24    pub capabilities: ClientCapabilities,
25    /// Information about the client's implementation (e.g., name, version).
26    #[serde(rename = "clientInfo")]
27    pub client_info: Implementation,
28    /// Optional metadata for the request.
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub _meta: Option<serde_json::Value>,
31}
32
33/// The response to a successful `initialize` request.
34///
35/// The server sends this message to confirm the connection parameters and
36/// to declare its own capabilities.
37#[derive(Debug, Clone, Serialize, Deserialize)]
38pub struct InitializeResult {
39    /// The protocol version that will be used for the session, chosen by the server.
40    #[serde(rename = "protocolVersion")]
41    pub protocol_version: ProtocolVersion,
42    /// The capabilities supported by the server.
43    pub capabilities: ServerCapabilities,
44    /// Information about the server's implementation (e.g., name, version).
45    #[serde(rename = "serverInfo")]
46    pub server_info: Implementation,
47    /// Optional human-readable instructions for the client.
48    #[serde(skip_serializing_if = "Option::is_none")]
49    pub instructions: Option<String>,
50    /// Optional metadata for the result.
51    #[serde(skip_serializing_if = "Option::is_none")]
52    pub _meta: Option<serde_json::Value>,
53}
54
55/// A notification sent from the client to the server after receiving a successful
56/// `InitializeResult`, confirming that the client is ready to proceed.
57///
58/// This notification has no parameters.
59#[derive(Debug, Clone, Serialize, Deserialize)]
60pub struct InitializedNotification;