use serde::{Deserialize, Serialize};
use serde_json::Value;
#[derive(Debug, Clone, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct InitializeParams {
#[serde(default)]
pub protocol_version: Option<String>,
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct InitializeResult {
pub protocol_version: String,
pub capabilities: ServerCapabilities,
pub server_info: ServerInfo,
}
#[derive(Debug, Clone, Serialize, Default)]
pub struct ServerCapabilities {
pub tools: ToolsCapability,
pub resources: ResourcesCapability,
}
#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct ToolsCapability {
pub list_changed: bool,
}
#[derive(Debug, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct ResourcesCapability {
pub list_changed: bool,
pub subscribe: bool,
}
#[derive(Debug, Clone, Serialize)]
pub struct ServerInfo {
pub name: String,
pub version: String,
}
#[derive(Debug, Clone, Serialize)]
pub struct ToolsListResult {
pub tools: Vec<ToolDescriptor>,
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ToolDescriptor {
pub name: &'static str,
pub description: &'static str,
pub input_schema: Value,
}
#[derive(Debug, Clone, Deserialize)]
pub struct ToolsCallParams {
pub name: String,
#[serde(default)]
pub arguments: Value,
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ToolsCallResult {
pub content: Vec<ContentBlock>,
#[serde(skip_serializing_if = "std::ops::Not::not")]
pub is_error: bool,
}
#[derive(Debug, Clone, Serialize)]
#[serde(tag = "type")]
pub enum ContentBlock {
#[serde(rename = "text")]
Text { text: String },
}
impl ContentBlock {
pub fn text(s: impl Into<String>) -> Self {
ContentBlock::Text { text: s.into() }
}
}
impl ToolsCallResult {
pub fn ok(payload: Value) -> Self {
let s = serde_json::to_string(&payload).expect("payload always serializable");
Self {
content: vec![ContentBlock::text(s)],
is_error: false,
}
}
pub fn error(message: impl Into<String>) -> Self {
Self {
content: vec![ContentBlock::text(message)],
is_error: true,
}
}
}
#[derive(Debug, Clone, Serialize)]
pub struct ResourcesListResult {
pub resources: Vec<ResourceDescriptor>,
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ResourceDescriptor {
pub uri: String,
pub name: String,
pub description: String,
pub mime_type: &'static str,
}
#[derive(Debug, Clone, Deserialize)]
pub struct ResourcesReadParams {
pub uri: String,
}
#[derive(Debug, Clone, Serialize)]
pub struct ResourcesReadResult {
pub contents: Vec<ResourceContent>,
}
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ResourceContent {
pub uri: String,
pub mime_type: &'static str,
pub text: String,
}