Skip to content

Commit 78e71aa

Browse files
authored
Merge pull request #1179 from dhsifss/feat/mcp
fix: get_api response
2 parents 6abcb6b + 857e0c4 commit 78e71aa

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

mcp_server/tools/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ def tool(self) -> Tool:
1818
class ToolRegister:
1919
_dict: dict[str, ABCTool] = {}
2020

21-
@classmethod
2221
def register(self, tool: ABCTool) -> ABCTool:
2322
tool_name = tool.tool().name
2423
logging.info(f"Registering tool: {tool_name}")

mcp_server/utils/request.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,39 @@
11
from httpx import AsyncClient
22
from config import GLOBAL_CONFIG
33
import httpx
4+
import json
45

5-
def check_slce_response(response: httpx.Response) -> str:
6+
def get_response_data(response: httpx.Response) -> dict:
67
if response.status_code != 200:
78
return f"response status code: {response.status_code}"
89

910
data = response.json()
1011
if data["msg"] is not None and data["msg"] != "":
11-
return f"request SafeLine API failed: {data['msg']}"
12+
raise Exception(f"request SafeLine API failed: {data['msg']}")
1213

1314
if data["err"] is not None and data["err"] != "":
14-
return f"request SafeLine API failed: {data['err']}"
15+
raise Exception(f"request SafeLine API failed: {data['err']}")
16+
17+
return data['data']
18+
19+
def check_slce_response(response: httpx.Response) -> str:
20+
try:
21+
get_response_data(response)
22+
except Exception as e:
23+
return str(e)
1524

1625
return "success"
1726

27+
28+
def check_slce_get_response(response: httpx.Response) -> str:
29+
try:
30+
data = get_response_data(response)
31+
if data:
32+
return json.dumps(data)
33+
return "empty response data"
34+
except Exception as e:
35+
return str(e)
36+
1837
async def get_slce_api(path: str) -> str:
1938
if not path.startswith("/"):
2039
path = f"/{path}"
@@ -24,7 +43,7 @@ async def get_slce_api(path: str) -> str:
2443
response = await client.get(f"{GLOBAL_CONFIG.SAFELINE_ADDRESS}{path}", headers={
2544
"X-SLCE-API-TOKEN": f"{GLOBAL_CONFIG.SAFELINE_API_TOKEN}"
2645
})
27-
return check_slce_response(response)
46+
return check_slce_get_response(response)
2847
except Exception as e:
2948
return str(e)
3049

0 commit comments

Comments
 (0)