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 execution: None,
58 annotations: None,
59 #[cfg(feature = "mcp-icons")]
60 icons: None,
61 meta: None,
62 }
63}
64
65pub fn test_prompt() -> Prompt {
67 Prompt {
68 name: "test_prompt".to_string(),
69 title: Some("Test Prompt".to_string()),
70 description: Some("A test prompt".to_string()),
71 arguments: None,
72 meta: None,
73 }
74}
75
76pub fn test_prompt_argument(name: &str) -> PromptArgument {
78 PromptArgument {
79 name: name.to_string(),
80 title: Some(format!("Argument {name}")),
81 description: Some(format!("Description for {name}")),
82 required: Some(true),
83 }
84}
85
86pub fn test_resource() -> Resource {
88 Resource {
89 name: "test_resource".to_string(),
90 title: Some("Test Resource".to_string()),
91 uri: "file://test/resource.txt".to_string(),
92 description: Some("A test resource".to_string()),
93 mime_type: Some("text/plain".to_string()),
94 annotations: None,
95 size: Some(1024),
96 meta: None,
97 }
98}
99
100pub fn test_initialize_request() -> InitializeRequest {
102 InitializeRequest {
103 protocol_version: "2025-06-18".to_string(),
104 capabilities: ClientCapabilities::default(),
105 client_info: Implementation {
106 name: "test-client".to_string(),
107 title: Some("Test Client".to_string()),
108 version: "1.0.0".to_string(),
109 #[cfg(feature = "mcp-draft")]
110 description: None,
111 #[cfg(feature = "mcp-icons")]
112 icons: None,
113 },
114 _meta: None,
115 }
116}
117
118#[allow(dead_code)]
122pub fn assert_valid(result: &ValidationResult) {
123 assert!(
124 result.is_valid(),
125 "Expected validation to pass, but got errors: {:?}",
126 result.errors()
127 );
128}
129
130#[allow(dead_code)]
132pub fn assert_invalid(result: &ValidationResult) {
133 assert!(
134 result.is_invalid(),
135 "Expected validation to fail, but it passed"
136 );
137}