Skip to content

Commit 2fb8669

Browse files
committed
add error handling for MCP error responses
1 parent ca32e25 commit 2fb8669

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

web-gui/public/index.html

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -505,13 +505,32 @@ <h1 class="serif text-4xl md:text-5xl mb-2 gradient-text">
505505
};
506506

507507
const extractStructured = (result) => {
508-
if (!result) return null;
508+
if (!result) {
509+
console.error("extractStructured: result is null/undefined");
510+
return null;
511+
}
512+
513+
if (result.isError) {
514+
console.error("MCP returned error:", result);
515+
const errorText = result.content?.[0]?.text || "Unknown MCP error";
516+
console.error("Error text:", errorText);
517+
throw new Error(errorText);
518+
}
519+
509520
if (result.structuredContent) return result.structuredContent;
521+
510522
const text = result.content?.[0]?.text;
511-
if (!text) return null;
523+
if (!text) {
524+
console.error("extractStructured: no text in result.content[0]");
525+
return null;
526+
}
527+
512528
try {
513-
return JSON.parse(text);
514-
} catch {
529+
const parsed = JSON.parse(text);
530+
console.log("Successfully parsed JSON from MCP response");
531+
return parsed;
532+
} catch (e) {
533+
console.error("Failed to parse JSON:", e, "Text was:", text);
515534
return null;
516535
}
517536
};

0 commit comments

Comments
 (0)