Skip to content

Commit 98d4e6c

Browse files
committed
fix(run): Auto-parse JSON text responses from MCP tools
When MCP tools return text-only responses (hasStructured: false), attempt to parse as JSON for better workflow UX. Falls back to { text: ... } if parsing fails. This fixes workflows silently returning 0 results when tools return JSON data as text instead of structured responses.
1 parent ed4c824 commit 98d4e6c

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

  • templates/skills/droid-mode/lib

templates/skills/droid-mode/lib/run.mjs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,17 @@ export function createToolApi(opts) {
8181
hasStructured: !!res?.structured,
8282
textLength: (res?.text || "").length,
8383
};
84-
return res.structured ?? (res.text ? { text: res.text } : res.raw);
84+
// Return structured data if available
85+
if (res.structured) return res.structured;
86+
// Auto-parse JSON text responses for better workflow UX
87+
if (res.text) {
88+
try {
89+
return JSON.parse(res.text);
90+
} catch {
91+
return { text: res.text };
92+
}
93+
}
94+
return res.raw;
8595
} catch (err) {
8696
lastError = err;
8797
traceItem.retries = attempt;

0 commit comments

Comments
 (0)