Pass params as dict to requests.get, let it deal with encoding

This commit is contained in:
Teal Bauer 2025-03-28 19:08:35 +01:00 committed by GitHub
parent 665ef14b41
commit 13f962a329
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -10,18 +10,15 @@ mcp = FastMCP("ghidra-mcp")
def safe_get(endpoint: str, params: dict = None) -> list: def safe_get(endpoint: str, params: dict = None) -> list:
""" """
Perform a GET request. If 'params' is given, we convert it to a query string. Perform a GET request with optional query parameters.
""" """
if params is None: if params is None:
params = {} params = {}
qs = [f"{k}={v}" for k, v in params.items()]
query_string = "&".join(qs)
url = f"{ghidra_server_url}/{endpoint}" url = f"{ghidra_server_url}/{endpoint}"
if query_string:
url += "?" + query_string
try: try:
response = requests.get(url, timeout=5) response = requests.get(url, params=params, timeout=5)
response.encoding = 'utf-8' response.encoding = 'utf-8'
if response.ok: if response.ok:
return response.text.splitlines() return response.text.splitlines()