Skip to content

Commit ac81405

Browse files
committed
fix: parse embedded JSON in answer field as fallback
Some tools return structured JSON in 'answer' field (escaped string) instead of 'structured_output' field. Updated parser to: 1. Check for structured_output field (preferred) 2. Fallback: Try parsing answer field as JSON 3. Extract file locations from either format This handles both: - New format: {"structured_output": {...}} - Old wrapper: {"answer": "{\"analysis\": ..., \"hub_nodes\": [...]}"} Ensures all tools are parsed correctly regardless of format variation.
1 parent b0284a2 commit ac81405

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

test_http_mcp.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,22 @@ async def run_tests():
8484
result_text = result.content[0].text
8585
data = json.loads(result_text)
8686

87+
# Check for structured_output field
8788
if "structured_output" in data:
8889
structured_output = data["structured_output"]
8990
success = True
90-
91-
# Extract file locations
91+
# Fallback: Check if "answer" field contains JSON
92+
elif "answer" in data and isinstance(data["answer"], str):
93+
try:
94+
# Try to parse answer as JSON (old wrapper format)
95+
structured_output = json.loads(data["answer"])
96+
success = True
97+
except json.JSONDecodeError:
98+
# Answer is plain text, not JSON
99+
pass
100+
101+
# Extract file locations from structured output
102+
if structured_output:
92103
for field in ['components', 'hub_nodes', 'evidence', 'core_components']:
93104
if field in structured_output:
94105
for item in structured_output[field]:

0 commit comments

Comments
 (0)