2025-12-17 17:30:14 -08:00
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
|
|
pub const JSON_RPC_VERSION: &str = "2.0";
|
2025-12-25 21:08:37 -08:00
|
|
|
pub const TOOL_CALL_METHOD: &str = "tools/call";
|
2025-12-17 17:30:14 -08:00
|
|
|
pub const MCP_INITIALIZE: &str = "initialize";
|
2025-12-23 17:14:50 -08:00
|
|
|
pub const MCP_INITIALIZE_NOTIFICATION: &str = "notifications/initialized";
|
2025-12-17 17:30:14 -08:00
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
#[serde(untagged)]
|
|
|
|
|
pub enum JsonRpcId {
|
2025-12-25 21:08:37 -08:00
|
|
|
String(String),
|
|
|
|
|
Number(u64),
|
2025-12-17 17:30:14 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub struct JsonRpcRequest {
|
2025-12-25 21:08:37 -08:00
|
|
|
pub jsonrpc: String,
|
|
|
|
|
pub id: JsonRpcId,
|
|
|
|
|
pub method: String,
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
|
pub params: Option<HashMap<String, serde_json::Value>>,
|
2025-12-17 17:30:14 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub struct JsonRpcNotification {
|
2025-12-25 21:08:37 -08:00
|
|
|
pub jsonrpc: String,
|
|
|
|
|
pub method: String,
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
|
pub params: Option<HashMap<String, serde_json::Value>>,
|
2025-12-17 17:30:14 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub struct JsonRpcError {
|
2025-12-25 21:08:37 -08:00
|
|
|
pub code: i32,
|
|
|
|
|
pub message: String,
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
|
pub data: Option<serde_json::Value>,
|
2025-12-17 17:30:14 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
|
|
|
pub struct JsonRpcResponse {
|
2025-12-25 21:08:37 -08:00
|
|
|
pub jsonrpc: String,
|
|
|
|
|
pub id: JsonRpcId,
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
|
pub result: Option<HashMap<String, serde_json::Value>>,
|
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
|
pub error: Option<JsonRpcError>,
|
2025-12-17 17:30:14 -08:00
|
|
|
}
|