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