mcp connect issue cert

This commit is contained in:
larssand
2026-06-30 21:37:17 +02:00
parent 6a63de0e37
commit 24561ac984
2 changed files with 28 additions and 6 deletions

View File

@@ -9,13 +9,22 @@ from urllib import error, request
class GraylogMcpClient:
"""Small Streamable HTTP MCP client used for Graylog connection checks."""
def __init__(self, url: str, token: str, *, timeout: int = 15, verify_tls: bool = True) -> None:
def __init__(self, url: str, token: str, *, timeout: int = 15, verify_tls: bool = True, use_proxy: bool = False) -> None:
self.url = url.rstrip("/")
self.token = token
self.timeout = timeout
self.verify_tls = verify_tls
self.use_proxy = use_proxy
self.session_id: str | None = None
def _open(self, req: request.Request, context: ssl.SSLContext | None):
if self.use_proxy:
return request.urlopen(req, timeout=self.timeout, context=context)
handlers = [request.ProxyHandler({})]
if context is not None:
handlers.append(request.HTTPSHandler(context=context))
return request.build_opener(*handlers).open(req, timeout=self.timeout)
def _call(self, method: str, params: dict[str, object] | None = None, *, notification: bool = False) -> dict[str, object]:
payload: dict[str, object] = {"jsonrpc": "2.0", "method": method}
if not notification:
@@ -33,7 +42,7 @@ class GraylogMcpClient:
req = request.Request(self.url, data=json.dumps(payload).encode("utf-8"), method="POST", headers=headers)
try:
context = None if self.verify_tls else ssl._create_unverified_context()
with request.urlopen(req, timeout=self.timeout, context=context) as response:
with self._open(req, context) as response:
self.session_id = response.headers.get("Mcp-Session-Id", self.session_id)
body = response.read().decode("utf-8")
except error.HTTPError as exc: