integration-test-mcp
Version:
MCP服务器用于集成测试
71 lines (70 loc) • 2.68 kB
JavaScript
/**
* 集成测试 MCP 服务器
* 基于原有 index.js 实现
*/
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
import dotenv from 'dotenv';
dotenv.config();
// 导入工具函数
import { runIntegrationTest } from "./utils/index.js";
// 创建MCP服务器
async function startServer() {
const server = new McpServer({
name: "集成测试MCP服务器",
version: "1.0.0",
});
// 添加集成测试工具
server.tool("run_integration_test", "运行集成测试工具,用于执行代码的集成测试流程。要求指定Git分支名称,。测试过程包括特性验证、提测、流水线执行和最终集成。测试失败时会立即停止并返回错误信息。", {
branchName: z.string().optional().describe("指定要测试的Git分支名称"),
}, async ({ branchName }) => {
try {
// 没有branchName直接抛出异常
if (!branchName) {
throw new Error("未指定提测分支");
}
const result = await runIntegrationTest(branchName);
if (result.success) {
return {
content: [
{
type: "text",
text: `集成测试成功完成!\n\n分支: ${result.branch}\n\n特性: ${JSON.stringify(result.feature, null, 2)}\n\n提测结果: ${JSON.stringify(result.submit, null, 2)}\n\n流水线: ${JSON.stringify(result.pipeline, null, 2)}\n\n集成结果: ${JSON.stringify(result.integrate, null, 2)}`,
},
],
};
}
else {
return {
content: [
{
type: "text",
text: `集成测试失败: ${result.error}`,
},
],
};
}
}
catch (error) {
return {
content: [
{
type: "text",
text: `执行集成测试时发生错误: ${error.message}`,
},
],
};
}
});
// 启动服务器
const transport = new StdioServerTransport();
await server.connect(transport);
console.log("集成测试MCP服务器已启动");
}
// 启动服务器
startServer().catch((error) => {
console.error("启动MCP服务器失败:", error);
process.exit(1);
});