Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
|
@@ -45,8 +45,8 @@ def parse_mcp_response(response_data):
|
|
| 45 |
"""
|
| 46 |
解析 MCP 协议响应数据
|
| 47 |
支持格式:
|
| 48 |
-
1. {"result": {"content": [{"type": "text", "text": "..."}]}}
|
| 49 |
-
2. {"content": [{"type": "text", "text": "..."}]}
|
| 50 |
3. 直接的 JSON 数据
|
| 51 |
"""
|
| 52 |
if not isinstance(response_data, dict):
|
|
@@ -57,9 +57,7 @@ def parse_mcp_response(response_data):
|
|
| 57 |
content = response_data["result"]["content"]
|
| 58 |
if content and len(content) > 0:
|
| 59 |
text_content = content[0].get("text", "{}")
|
| 60 |
-
#
|
| 61 |
-
if ":\n\n" in text_content:
|
| 62 |
-
text_content = text_content.split(":\n\n", 1)[1]
|
| 63 |
try:
|
| 64 |
return json.loads(text_content)
|
| 65 |
except json.JSONDecodeError:
|
|
@@ -71,8 +69,7 @@ def parse_mcp_response(response_data):
|
|
| 71 |
content = response_data.get("content", [])
|
| 72 |
if content and len(content) > 0:
|
| 73 |
text_content = content[0].get("text", "{}")
|
| 74 |
-
|
| 75 |
-
text_content = text_content.split(":\n\n", 1)[1]
|
| 76 |
try:
|
| 77 |
return json.loads(text_content)
|
| 78 |
except json.JSONDecodeError:
|
|
|
|
| 45 |
"""
|
| 46 |
解析 MCP 协议响应数据
|
| 47 |
支持格式:
|
| 48 |
+
1. {"result": {"content": [{"type": "text", "text": "{...}"}]}}
|
| 49 |
+
2. {"content": [{"type": "text", "text": "{...}"}]}
|
| 50 |
3. 直接的 JSON 数据
|
| 51 |
"""
|
| 52 |
if not isinstance(response_data, dict):
|
|
|
|
| 57 |
content = response_data["result"]["content"]
|
| 58 |
if content and len(content) > 0:
|
| 59 |
text_content = content[0].get("text", "{}")
|
| 60 |
+
# 直接解析 JSON(MCP Server 已移除 emoji 前缀)
|
|
|
|
|
|
|
| 61 |
try:
|
| 62 |
return json.loads(text_content)
|
| 63 |
except json.JSONDecodeError:
|
|
|
|
| 69 |
content = response_data.get("content", [])
|
| 70 |
if content and len(content) > 0:
|
| 71 |
text_content = content[0].get("text", "{}")
|
| 72 |
+
# 直接解析 JSON
|
|
|
|
| 73 |
try:
|
| 74 |
return json.loads(text_content)
|
| 75 |
except json.JSONDecodeError:
|