-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate.py
More file actions
42 lines (34 loc) · 1.2 KB
/
validate.py
File metadata and controls
42 lines (34 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import base64
import os
import sys
import requests
base_url = os.getenv("MCP_BASE_URL", "http://localhost:8000")
api_key_name = os.getenv("MCP_API_KEY_PARAMETER_NAME", "x-api-key")
api_key_value = os.getenv("MCP_API_KEY_VALUE")
username = os.getenv("MCP_BASIC_AUTH_USERNAME")
password = os.getenv("MCP_BASIC_AUTH_PASSWORD")
headers = {
"Accept": "application/json, text/event-stream",
"Content-Type": "application/json",
}
if username and password:
token = base64.b64encode(f"{username}:{password}".encode()).decode()
headers["Authorization"] = f"Basic {token}"
if api_key_value:
headers[api_key_name] = api_key_value
if os.getenv("NGROK_SKIP_BROWSER_WARNING"):
headers["ngrok-skip-browser-warning"] = os.getenv("NGROK_SKIP_BROWSER_WARNING")
if "Authorization" not in headers and api_key_name not in headers:
print(
"Set either MCP_BASIC_AUTH_USERNAME+MCP_BASIC_AUTH_PASSWORD or "
"MCP_API_KEY_VALUE before running validate.py.",
file=sys.stderr,
)
sys.exit(2)
resp = requests.post(
f"{base_url}/mcp",
headers=headers,
json={"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}},
timeout=20,
)
print(resp.status_code, resp.text[:500])