use mcp_protocol_sdk::protocol::types::*;
use serde_json::json;
use std::collections::HashMap;
#[test]
fn test_basic_protocol_types() {
let text_content = Content::text("Hello, world!");
let serialized = serde_json::to_string(&text_content).unwrap();
assert!(serialized.contains("Hello, world!"));
let tool = Tool {
name: "test_tool".to_string(),
description: Some("A test tool".to_string()),
input_schema: ToolInputSchema {
schema_type: "object".to_string(),
properties: Some(HashMap::new()),
required: None,
additional_properties: HashMap::new(),
},
annotations: None,
title: Some("Test Tool".to_string()),
meta: None,
};
assert_eq!(tool.name, "test_tool");
let request = JsonRpcRequest {
jsonrpc: JSONRPC_VERSION.to_string(),
id: json!(1),
method: "test_method".to_string(),
params: Some(json!({"test": "value"})),
};
assert_eq!(request.method, "test_method");
assert_eq!(request.id, json!(1));
let response = JsonRpcResponse {
jsonrpc: JSONRPC_VERSION.to_string(),
id: json!(1),
result: Some(json!({"result": "success"})),
};
assert_eq!(response.id, json!(1));
let request_json = serde_json::to_string(&request).unwrap();
assert!(request_json.contains("test_method"));
let response_json = serde_json::to_string(&response).unwrap();
assert!(response_json.contains("success"));
println!("✅ All basic protocol types work correctly!");
}
#[test]
fn test_2025_features() {
let audio_content = Content::audio("base64audiodata", "audio/wav");
let serialized = serde_json::to_value(&audio_content).unwrap();
assert_eq!(serialized["type"], "audio");
assert_eq!(serialized["data"], "base64audiodata");
assert_eq!(serialized["mimeType"], "audio/wav");
let resource_content = Content::resource_link("file:///test.txt", "Test File");
let serialized = serde_json::to_value(&resource_content).unwrap();
assert_eq!(serialized["type"], "resource_link");
assert_eq!(serialized["uri"], "file:///test.txt");
assert_eq!(serialized["name"], "Test File");
let annotations = Annotations::new().with_priority(0.8);
assert_eq!(annotations.priority, Some(0.8));
let tool = Tool {
name: "safe_tool".to_string(),
description: Some("A safe tool".to_string()),
input_schema: ToolInputSchema {
schema_type: "object".to_string(),
properties: Some(HashMap::new()),
required: None,
additional_properties: HashMap::new(),
},
annotations: None, title: Some("Safe Tool".to_string()),
meta: None,
};
assert_eq!(tool.name, "safe_tool");
println!("✅ All 2025-06-18 features work correctly!");
}
#[test]
fn test_server_capabilities() {
let capabilities = ServerCapabilities {
tools: Some(ToolsCapability {
list_changed: Some(true),
}),
resources: Some(ResourcesCapability {
subscribe: Some(true),
list_changed: Some(true),
}),
completions: None,
..Default::default()
};
let serialized = serde_json::to_value(&capabilities).unwrap();
assert_eq!(serialized["tools"]["listChanged"], true);
assert_eq!(serialized["resources"]["subscribe"], true);
println!("✅ Server capabilities work correctly!");
}
#[test]
fn test_constants() {
assert_eq!(LATEST_PROTOCOL_VERSION, "2025-06-18");
assert_eq!(JSONRPC_VERSION, "2.0");
assert_eq!(PROTOCOL_VERSION, LATEST_PROTOCOL_VERSION);
println!("✅ Protocol constants are correct!");
}