in src/index.ts [196:241]
async function handleToolCall(name: string, args: any): Promise<CallToolResult> {
log(`Handling tool call: name=${name}, args=${JSON.stringify(args)}`);
if (!cachedEndpoint) {
// If no cached endpoint, we can't proceed
throw new Error("No working IDE endpoint available.");
}
try {
log(`ENDPOINT: ${cachedEndpoint} | Tool name: ${name} | args: ${JSON.stringify(args)}`);
const response = await fetch(`${cachedEndpoint}/mcp/${name}`, {
method: 'POST',
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(args),
});
if (!response.ok) {
log(`Response failed with status ${response.status} for tool ${name}`);
throw new Error(`Response failed: ${response.status}`);
}
// Parse the IDE's JSON response
const {status, error}: IDEResponse = await response.json();
log("Parsed response:", {status, error});
const isError = !!error;
const text = status ?? error;
log("Final response text:", text);
log("Is error:", isError);
return {
content: [{type: "text", text: text}],
isError,
};
} catch (error: any) {
log("Error in handleToolCall:", error);
return {
content: [{
type: "text",
text: error instanceof Error ? error.message : "Unknown error",
}],
isError: true,
};
}
}