My agentic slop goes here. Not intended for anyone else!
at main 4.6 kB view raw
1(* Test MCP configuration serialization and builder functions *) 2 3let test_stdio_config () = 4 let open Claude.Options in 5 let config = Stdio { 6 command = "mcp-server-filesystem"; 7 args = ["/workspace"]; 8 env = Some [("KEY", "value")]; 9 } in 10 let servers = [("filesystem", config)] in 11 12 (* Build options with MCP servers *) 13 let options = Claude.Options.default 14 |> Claude.Options.with_mcp_servers servers 15 in 16 17 (* Verify accessor works *) 18 let retrieved = Claude.Options.mcp_servers options in 19 assert (List.length retrieved = 1); 20 21 (* Test serialization via transport *) 22 let json_str = Claude.Transport.serialize_mcp_config servers in 23 print_endline "✓ Stdio config JSON:"; 24 print_endline json_str; 25 print_endline "" 26 27let test_with_mcp_stdio () = 28 (* Test the with_mcp_stdio convenience function *) 29 let options = Claude.Options.default 30 |> Claude.Options.with_mcp_stdio 31 ~name:"filesystem" 32 ~command:"mcp-server-filesystem" 33 ~args:["/workspace"] 34 ~env:[("VAR", "value")] 35 () 36 in 37 38 let servers = Claude.Options.mcp_servers options in 39 assert (List.length servers = 1); 40 let (name, config) = List.hd servers in 41 assert (name = "filesystem"); 42 (match config with 43 | Claude.Options.Stdio cfg -> 44 assert (cfg.command = "mcp-server-filesystem"); 45 assert (cfg.args = ["/workspace"]); 46 assert (cfg.env = Some [("VAR", "value")]); 47 print_endline "✓ with_mcp_stdio convenience function works" 48 | _ -> failwith "Expected Stdio config"); 49 print_endline "" 50 51let test_sse_config () = 52 let open Claude.Options in 53 let config = SSE { 54 url = "https://api.example.com/mcp"; 55 headers = Some [("Authorization", "Bearer token")]; 56 } in 57 let servers = [("api", config)] in 58 59 let json_str = Claude.Transport.serialize_mcp_config servers in 60 print_endline "✓ SSE config JSON:"; 61 print_endline json_str; 62 print_endline "" 63 64let test_http_config () = 65 let open Claude.Options in 66 let config = HTTP { 67 url = "https://api.example.com/mcp"; 68 headers = Some [("Authorization", "Bearer token")]; 69 } in 70 let servers = [("http_server", config)] in 71 72 let json_str = Claude.Transport.serialize_mcp_config servers in 73 print_endline "✓ HTTP config JSON:"; 74 print_endline json_str; 75 print_endline "" 76 77let test_multiple_servers () = 78 let open Claude.Options in 79 let servers = [ 80 ("filesystem", Stdio { 81 command = "mcp-server-filesystem"; 82 args = ["/workspace"]; 83 env = None; 84 }); 85 ("api", SSE { 86 url = "https://api.example.com/mcp"; 87 headers = Some [("Authorization", "Bearer token")]; 88 }); 89 ("http", HTTP { 90 url = "https://http.example.com/mcp"; 91 headers = None; 92 }); 93 ] in 94 95 let json_str = Claude.Transport.serialize_mcp_config servers in 96 print_endline "✓ Multiple servers config JSON:"; 97 print_endline json_str; 98 print_endline "" 99 100let test_empty_config () = 101 let servers = [] in 102 let json_str = Claude.Transport.serialize_mcp_config servers in 103 print_endline "✓ Empty config JSON:"; 104 print_endline json_str; 105 print_endline "" 106 107let test_with_mcp_server () = 108 (* Test with_mcp_server builder function *) 109 let options = Claude.Options.default 110 |> Claude.Options.with_mcp_server 111 ~name:"test" 112 ~config:(Claude.Options.SSE { 113 url = "https://test.com"; 114 headers = None 115 }) 116 in 117 118 let servers = Claude.Options.mcp_servers options in 119 assert (List.length servers = 1); 120 print_endline "✓ with_mcp_server builder function works"; 121 print_endline "" 122 123let test_replace_server () = 124 (* Test that adding a server with the same name replaces it *) 125 let options = Claude.Options.default 126 |> Claude.Options.with_mcp_stdio ~name:"fs" ~command:"old-cmd" () 127 |> Claude.Options.with_mcp_stdio ~name:"fs" ~command:"new-cmd" () 128 in 129 130 let servers = Claude.Options.mcp_servers options in 131 assert (List.length servers = 1); 132 let (_, config) = List.hd servers in 133 (match config with 134 | Claude.Options.Stdio cfg -> 135 assert (cfg.command = "new-cmd"); 136 print_endline "✓ Server replacement by name works" 137 | _ -> failwith "Expected Stdio config"); 138 print_endline "" 139 140let () = 141 print_endline "Testing MCP Configuration"; 142 print_endline "========================"; 143 print_endline ""; 144 145 test_stdio_config (); 146 test_with_mcp_stdio (); 147 test_with_mcp_stdio (); 148 test_sse_config (); 149 test_http_config (); 150 test_multiple_servers (); 151 test_empty_config (); 152 test_with_mcp_server (); 153 test_replace_server (); 154 155 print_endline "✅ All MCP configuration tests completed successfully!"