Skip to content

Commit d4c7c62

Browse files
author
junjie.miao
committed
add response is not success throw exception
1 parent 07fa812 commit d4c7c62

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

utils/mcp_client.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,11 @@ def send_message(self, data: dict):
110110
json=data,
111111
headers={'Content-Type': 'application/json', 'trace-id': data["id"] if "id" in data else ""},
112112
timeout=self.timeout,
113-
follow_redirects=True
113+
follow_redirects=True,
114114
)
115115
response.raise_for_status()
116-
logging.debug(f"{self.name} - Client message sent successfully: {response.status_code}")
116+
if not response.is_success:
117+
raise ValueError(f"{self.name} - MCP Server response: {response.status_code} {response.reason_phrase}")
117118
if "id" in data:
118119
message_id = data["id"]
119120
while True:
@@ -233,8 +234,10 @@ def send_message(self, data: dict):
233234
json=data,
234235
headers=headers,
235236
timeout=self.timeout,
236-
follow_redirects=True
237+
follow_redirects=True,
237238
)
239+
if not response.is_success:
240+
raise ValueError(f"{self.name} - MCP Server response: {response.status_code} {response.reason_phrase}")
238241
self.session_id = response.headers.get("mcp-session-id", None)
239242
content_type = response.headers.get("content-type", "None")
240243
if content_type == "text/event-stream":

0 commit comments

Comments
 (0)