add base64 for token and mcp headre
This commit is contained in:
@@ -20,9 +20,9 @@ class GraylogMcpClient:
|
||||
payload["id"] = 1
|
||||
if params is not None:
|
||||
payload["params"] = params
|
||||
credentials = base64.b64encode(f"{self.token}:token".encode("utf-8")).decode("ascii")
|
||||
authorization = self._authorization_header()
|
||||
headers = {
|
||||
"Authorization": f"Basic {credentials}",
|
||||
"Authorization": authorization,
|
||||
"Content-Type": "application/json",
|
||||
"Accept": "application/json, text/event-stream",
|
||||
}
|
||||
@@ -49,6 +49,20 @@ class GraylogMcpClient:
|
||||
raise RuntimeError(f"mcp_error: {response_data['error']}")
|
||||
return response_data
|
||||
|
||||
def _authorization_header(self) -> str:
|
||||
"""Accept a raw token or the Basic/Base64 form commonly copied from MCP clients."""
|
||||
value = self.token.strip()
|
||||
if value.lower().startswith("basic "):
|
||||
return value
|
||||
try:
|
||||
decoded = base64.b64decode(value, validate=True).decode("utf-8")
|
||||
except (ValueError, UnicodeDecodeError):
|
||||
decoded = ""
|
||||
if decoded.endswith(":token"):
|
||||
return f"Basic {value}"
|
||||
credentials = base64.b64encode(f"{value}:token".encode("utf-8")).decode("ascii")
|
||||
return f"Basic {credentials}"
|
||||
|
||||
def probe(self) -> dict[str, object]:
|
||||
initialized = self._call(
|
||||
"initialize",
|
||||
|
||||
Reference in New Issue
Block a user