Skip to content

Commit 17bd38f

Browse files
committed
add console logging for debugging tool selection
1 parent 282de72 commit 17bd38f

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

web-gui/public/index.html

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,10 @@ <h1 class="serif text-4xl md:text-5xl mb-2 gradient-text">
556556
try {
557557
const result = await callMcp("tools/list", {});
558558
state.availableTools = result.tools || [];
559+
console.log("Available MCP tools:", state.availableTools.map(t => t.name));
559560
setStatus("ok", `Online (${state.availableTools.length} tools)`);
560561
} catch (error) {
562+
console.error("MCP check error:", error);
561563
setStatus("error", "Offline");
562564
state.availableTools = [];
563565
}
@@ -641,14 +643,21 @@ <h1 class="serif text-4xl md:text-5xl mb-2 gradient-text">
641643

642644
const data = await response.json();
643645
const text = data.candidates?.[0]?.content?.parts?.[0]?.text || "";
646+
console.log("Gemini raw response:", text);
644647
const jsonStart = text.indexOf("{");
645648
const jsonEnd = text.lastIndexOf("}");
646649
if (jsonStart === -1 || jsonEnd === -1) {
650+
console.error("No JSON found in Gemini response");
647651
throw new Error("Invalid Gemini response");
648652
}
649653

650-
const parsed = JSON.parse(text.slice(jsonStart, jsonEnd + 1));
654+
const jsonText = text.slice(jsonStart, jsonEnd + 1);
655+
console.log("Extracted JSON:", jsonText);
656+
const parsed = JSON.parse(jsonText);
657+
console.log("Parsed Gemini response:", parsed);
658+
651659
if (!parsed.tool || !parsed.arguments) {
660+
console.error("Missing tool or arguments in response");
652661
throw new Error("Gemini did not return tool and arguments");
653662
}
654663

@@ -660,7 +669,9 @@ <h1 class="serif text-4xl md:text-5xl mb-2 gradient-text">
660669
let toolCall;
661670
try {
662671
toolCall = await callGemini(query, state.conversationHistory);
672+
console.log("Gemini selected tool:", toolCall);
663673
} catch (error) {
674+
console.error("Gemini error:", error);
664675
// Fallback: use ckan_package_search with normalized query
665676
const normalizedQuery = normalizeQuery(query);
666677
toolCall = {
@@ -672,6 +683,7 @@ <h1 class="serif text-4xl md:text-5xl mb-2 gradient-text">
672683
response_format: "json"
673684
}
674685
};
686+
console.log("Using fallback tool:", toolCall);
675687
}
676688

677689
// Ensure server_url is set
@@ -684,14 +696,17 @@ <h1 class="serif text-4xl md:text-5xl mb-2 gradient-text">
684696
toolCall.arguments.response_format = "json";
685697
}
686698

699+
console.log("Final tool call:", toolCall);
687700
setToolStatus(`⚡ Using ${toolCall.tool}...`);
688701
const result = await callMcp("tools/call", {
689702
name: toolCall.tool,
690703
arguments: toolCall.arguments
691704
});
705+
console.log("MCP result:", result);
692706
setToolStatus("");
693707

694708
const data = extractStructured(result);
709+
console.log("Extracted data:", data);
695710
return {
696711
tool: toolCall.tool,
697712
data: data

0 commit comments

Comments
 (0)