17
17
class MCPHttpTester :
18
18
"""Class to test an MCP HTTP server implementation."""
19
19
20
- def __init__ (self , url , debug = False ):
20
+ def __init__ (self , url , debug = False , bearer_token = None ):
21
21
"""
22
22
Initialize the tester with the server URL.
23
23
@@ -36,16 +36,25 @@ def __init__(self, url, debug=False):
36
36
# Session information
37
37
self .session_id = None
38
38
self .initialized = False
39
+ self .bearer_token = bearer_token
39
40
40
41
# Protocol information
41
42
self .protocol_version = "2025-03-26"
42
43
43
44
# Create a persistent session for all requests
44
45
self .request_session = requests .Session ()
45
- self .request_session .headers .update ({
46
+ # Common headers
47
+ headers = {
46
48
"Content-Type" : "application/json" ,
49
+ "Origin" : "http://localhost" ,
47
50
"Accept" : "application/json, text/event-stream"
48
- })
51
+ }
52
+
53
+ # Add Authorization header only if bearer_token is provided
54
+ if self .bearer_token is not None :
55
+ headers ["Authorization" ] = f"Bearer { self .bearer_token } "
56
+
57
+ self .request_session .headers .update (headers )
49
58
50
59
self .log (f"MCP HTTP Tester initialized for { url } " )
51
60
self .log (f"Host: { self .host } , Path: { self .path } " )
@@ -628,4 +637,4 @@ def run_all_tests(self):
628
637
print (f"Error during test execution: { str (e )} " )
629
638
import traceback
630
639
traceback .print_exc ()
631
- return False
640
+ return False
0 commit comments