fix: handle non-JSON responses (logs endpoint returns text)
All checks were successful
Build and Push Gitea MCP Docker Image / build (push) Successful in 20s
All checks were successful
Build and Push Gitea MCP Docker Image / build (push) Successful in 20s
- Check content-type header before parsing as JSON - Return raw text wrapped in dict for non-JSON responses - Also accept both GITEA_URL and GITEA_HOST env vars
This commit is contained in:
10
server.py
10
server.py
@@ -62,7 +62,7 @@ class GiteaClient:
|
|||||||
endpoint: str,
|
endpoint: str,
|
||||||
params: dict[str, Any] | None = None,
|
params: dict[str, Any] | None = None,
|
||||||
json_body: dict[str, Any] | None = None,
|
json_body: dict[str, Any] | None = None,
|
||||||
) -> dict[str, Any]:
|
) -> dict[str, Any] | list[Any]:
|
||||||
"""Execute an API request to Gitea."""
|
"""Execute an API request to Gitea."""
|
||||||
client = await self._get_client()
|
client = await self._get_client()
|
||||||
url = f"{self.api_url}{endpoint}"
|
url = f"{self.api_url}{endpoint}"
|
||||||
@@ -79,7 +79,13 @@ class GiteaClient:
|
|||||||
if response.status_code == 204:
|
if response.status_code == 204:
|
||||||
return {"status": "success", "message": "No content"}
|
return {"status": "success", "message": "No content"}
|
||||||
|
|
||||||
return response.json()
|
# Try to parse as JSON, fall back to text for endpoints like /logs
|
||||||
|
content_type = response.headers.get("content-type", "")
|
||||||
|
if "application/json" in content_type:
|
||||||
|
return response.json()
|
||||||
|
else:
|
||||||
|
# Return raw text wrapped in a dict for non-JSON responses
|
||||||
|
return {"content": response.text, "content_type": content_type}
|
||||||
except httpx.HTTPStatusError as e:
|
except httpx.HTTPStatusError as e:
|
||||||
return {
|
return {
|
||||||
"error": True,
|
"error": True,
|
||||||
|
|||||||
Reference in New Issue
Block a user