10
10
import argparse
11
11
import os
12
12
import sys
13
+ import traceback
13
14
from pathlib import Path
14
15
15
16
# Add the project root to the Python path
20
21
21
22
def main ():
22
23
"""Run compliance tests against an HTTP MCP server."""
23
- parser = argparse .ArgumentParser (description = "Run tests against an HTTP MCP server" )
24
- parser .add_argument (
25
- "--server-url" ,
26
- default = "http://localhost:9000/mcp" ,
27
- help = "URL of the MCP HTTP server (default: http://localhost:9000/mcp)"
28
- )
29
- parser .add_argument (
30
- "--protocol-version" ,
31
- choices = ["2024-11-05" , "2025-03-26" ],
32
- default = "2025-03-26" ,
33
- help = "Protocol version to use (default: 2025-03-26)"
34
- )
35
- parser .add_argument (
36
- "--debug" ,
37
- action = "store_true" ,
38
- help = "Enable debug logging"
39
- )
40
- parser .add_argument (
41
- "--output-dir" ,
42
- help = "Directory to write test results"
43
- )
44
- parser .add_argument (
45
- "--max-retries" ,
46
- type = int ,
47
- default = 3 ,
48
- help = "Maximum number of connection retries"
49
- )
50
- parser .add_argument (
51
- "--retry-interval" ,
52
- type = int ,
53
- default = 2 ,
54
- help = "Seconds to wait between connection retries"
55
- )
56
-
57
- args = parser .parse_args ()
58
-
59
- # Create output directory if needed
60
- if args .output_dir :
61
- os .makedirs (args .output_dir , exist_ok = True )
62
-
63
- # Check server connection first
64
- if not wait_for_server (
65
- args .server_url ,
66
- max_retries = args .max_retries ,
67
- retry_interval = args .retry_interval
68
- ):
69
- return 1
70
-
71
- # Run the HTTP tests
72
- tester = MCPHttpTester (args .server_url , args .debug )
73
- tester .protocol_version = args .protocol_version
74
-
75
- success = tester .run_all_tests ()
76
-
77
- # Generate report if needed
78
- if args .output_dir :
79
- report_path = os .path .join (args .output_dir , f"http_test_report_{ args .protocol_version } .md" )
24
+ try :
25
+ parser = argparse .ArgumentParser (description = "Run tests against an HTTP MCP server" )
26
+ parser .add_argument (
27
+ "--server-url" ,
28
+ default = "http://localhost:9000/mcp" ,
29
+ help = "URL of the MCP HTTP server (default: http://localhost:9000/mcp)"
30
+ )
31
+ parser .add_argument (
32
+ "--protocol-version" ,
33
+ choices = ["2024-11-05" , "2025-03-26" ],
34
+ default = "2025-03-26" ,
35
+ help = "Protocol version to use (default: 2025-03-26)"
36
+ )
37
+ parser .add_argument (
38
+ "--debug" ,
39
+ action = "store_true" ,
40
+ help = "Enable debug logging"
41
+ )
42
+ parser .add_argument (
43
+ "--output-dir" ,
44
+ help = "Directory to write test results"
45
+ )
46
+ parser .add_argument (
47
+ "--max-retries" ,
48
+ type = int ,
49
+ default = 3 ,
50
+ help = "Maximum number of connection retries"
51
+ )
52
+ parser .add_argument (
53
+ "--retry-interval" ,
54
+ type = int ,
55
+ default = 2 ,
56
+ help = "Seconds to wait between connection retries"
57
+ )
58
+
59
+ args = parser .parse_args ()
60
+
61
+ # Create output directory if needed
62
+ if args .output_dir :
63
+ os .makedirs (args .output_dir , exist_ok = True )
64
+
65
+ # Check server connection first
66
+ if not wait_for_server (
67
+ args .server_url ,
68
+ max_retries = args .max_retries ,
69
+ retry_interval = args .retry_interval
70
+ ):
71
+ return 1
80
72
81
- with open (report_path , "w" ) as f :
82
- f .write (f"# MCP HTTP Compliance Test Report\n \n " )
83
- f .write (f"- Server: { args .server_url } \n " )
84
- f .write (f"- Protocol Version: { args .protocol_version } \n " )
85
- f .write (f"- Date: { __import__ ('datetime' ).datetime .now ().strftime ('%Y-%m-%d %H:%M:%S' )} \n \n " )
73
+ # Run the HTTP tests
74
+ tester = MCPHttpTester (args .server_url , args .debug )
75
+ tester .protocol_version = args .protocol_version
76
+
77
+ success = tester .run_all_tests ()
78
+
79
+ # Generate report if needed
80
+ if args .output_dir :
81
+ report_path = os .path .join (args .output_dir , f"http_test_report_{ args .protocol_version } .md" )
86
82
87
- f .write (f"## Test Results\n \n " )
88
- f .write (f"All tests { 'PASSED' if success else 'FAILED' } \n \n " )
83
+ with open (report_path , "w" ) as f :
84
+ f .write (f"# MCP HTTP Compliance Test Report\n \n " )
85
+ f .write (f"- Server: { args .server_url } \n " )
86
+ f .write (f"- Protocol Version: { args .protocol_version } \n " )
87
+ f .write (f"- Date: { __import__ ('datetime' ).datetime .now ().strftime ('%Y-%m-%d %H:%M:%S' )} \n \n " )
88
+
89
+ f .write (f"## Test Results\n \n " )
90
+ f .write (f"All tests { 'PASSED' if success else 'FAILED' } \n \n " )
91
+
92
+ f .write (f"## Notes\n \n " )
93
+ f .write (f"This report was generated using the MCP HTTP testing framework.\n " )
94
+ f .write (f"For more detailed test results, run with the --debug flag.\n " )
89
95
90
- f .write (f"## Notes\n \n " )
91
- f .write (f"This report was generated using the MCP HTTP testing framework.\n " )
92
- f .write (f"For more detailed test results, run with the --debug flag.\n " )
96
+ print (f"Test report written to { report_path } " )
93
97
94
- print (f"Test report written to { report_path } " )
95
-
96
- return 0 if success else 1
98
+ return 0 if success else 1
99
+ except Exception as e :
100
+ print ("Error during HTTP test:" , file = sys .stderr )
101
+ print (str (e ), file = sys .stderr )
102
+ traceback .print_exc (file = sys .stderr )
103
+ return 1
97
104
98
105
if __name__ == "__main__" :
99
106
sys .exit (main ())
0 commit comments