turbomcp_protocol/
test_helpers.rs1use crate::jsonrpc::*;
29use crate::types::*;
30use crate::validation::*;
31
32pub fn test_request() -> JsonRpcRequest {
36 JsonRpcRequest {
37 jsonrpc: JsonRpcVersion,
38 method: "tools/list".to_string(),
39 params: None,
40 id: RequestId::String("test-123".to_string()),
41 }
42}
43
44pub fn test_tool() -> Tool {
46 Tool {
47 name: "test_tool".to_string(),
48 title: Some("Test Tool".to_string()),
49 description: Some("A test tool for validation".to_string()),
50 input_schema: ToolInputSchema {
51 schema_type: "object".to_string(),
52 properties: None,
53 required: None,
54 additional_properties: None,
55 },
56 output_schema: None,
57 annotations: None,
58 meta: None,
59 }
60}
61
62pub fn test_prompt() -> Prompt {
64 Prompt {
65 name: "test_prompt".to_string(),
66 title: Some("Test Prompt".to_string()),
67 description: Some("A test prompt".to_string()),
68 arguments: None,
69 meta: None,
70 }
71}
72
73pub fn test_prompt_argument(name: &str) -> PromptArgument {
75 PromptArgument {
76 name: name.to_string(),
77 title: Some(format!("Argument {name}")),
78 description: Some(format!("Description for {name}")),
79 required: Some(true),
80 }
81}
82
83pub fn test_resource() -> Resource {
85 Resource {
86 name: "test_resource".to_string(),
87 title: Some("Test Resource".to_string()),
88 uri: "file://test/resource.txt".to_string(),
89 description: Some("A test resource".to_string()),
90 mime_type: Some("text/plain".to_string()),
91 annotations: None,
92 size: Some(1024),
93 meta: None,
94 }
95}
96
97pub fn test_initialize_request() -> InitializeRequest {
99 InitializeRequest {
100 protocol_version: "2025-06-18".to_string(),
101 capabilities: ClientCapabilities::default(),
102 client_info: Implementation {
103 name: "test-client".to_string(),
104 title: Some("Test Client".to_string()),
105 version: "1.0.0".to_string(),
106 },
107 _meta: None,
108 }
109}
110
111#[allow(dead_code)]
115pub fn assert_valid(result: &ValidationResult) {
116 assert!(
117 result.is_valid(),
118 "Expected validation to pass, but got errors: {:?}",
119 result.errors()
120 );
121}
122
123#[allow(dead_code)]
125pub fn assert_invalid(result: &ValidationResult) {
126 assert!(
127 result.is_invalid(),
128 "Expected validation to fail, but it passed"
129 );
130}