basin-mcp
Version:
Basin AI MCP tool for code quality and reliability testing
44 lines (43 loc) • 1.96 kB
JavaScript
import { executeBasinTest, getTestPlan } from "basin-executor-lib";
import { BASIN_HOST, CURRENT_BASIN_PROTOCOL_VERSION } from "./const.js";
const BASIN_API_KEY = process.env.BASIN_API_KEY || "";
const DEBUG_MODE = process.env.DEBUG_MODE ? process.env.DEBUG_MODE === "true" : false;
const HOST = process.env.HOST || BASIN_HOST;
const testPlanToLogs = (testPlan) => {
const items = Array.isArray(testPlan.testing_instructions) ? testPlan.testing_instructions : testPlan.testing_instructions.items ? testPlan.testing_instructions.items : testPlan.testing_instructions.instruction ? testPlan.testing_instructions.instruction : [];
const logs = [];
for (let i = 0; i < items.length; i++) {
const item = items[i];
logs.push({
type: "text",
text: JSON.stringify(item),
});
}
return logs;
};
const checkCodeQuality = async (args) => {
const threadId = args.threadId;
const args_dump = JSON.stringify(args);
const testType = args && args.testType && args.testType === "general" ? "general" : "sanity";
const testPlan = await getTestPlan(BASIN_API_KEY, args_dump, threadId, CURRENT_BASIN_PROTOCOL_VERSION, testType, HOST);
if (!testPlan || !testPlan.testing_instructions) {
return {
content: [
{
type: "text",
text: "failed. unable to produce test plan. Testing did not happen",
},
],
};
}
const logs = testPlanToLogs(testPlan);
const result = await executeBasinTest(BASIN_API_KEY, testPlan, testPlan.thread_id, CURRENT_BASIN_PROTOCOL_VERSION, HOST, DEBUG_MODE);
if (result.logs && Array.isArray(result.logs))
logs.push(...result.logs);
logs.push({
type: "text",
text: result.success ? "All tests passed" : "Some tests failed: " + result.message,
});
return { content: logs };
};
export default checkCodeQuality;