115 lines
4.0 KiB
TypeScript
115 lines
4.0 KiB
TypeScript
/**
|
|
* MCP Server integration tests
|
|
*/
|
|
|
|
import { describe, test, expect, beforeEach } from "bun:test";
|
|
import { mcpServer } from "../../src/server.js";
|
|
import { getRegisteredTools, callTool } from "../helpers/tool-helper.js";
|
|
|
|
// Register all tools
|
|
import { registerCodeSnippetTools } from "../../src/tools/programming/codeSnippet.js";
|
|
import { registerProjectTemplateTools } from "../../src/tools/programming/projectTemplate.js";
|
|
import { registerDocsTools } from "../../src/tools/programming/docs.js";
|
|
import { registerCodeReviewTools } from "../../src/tools/programming/codeReview.js";
|
|
import { registerServerTools } from "../../src/tools/devops/server.js";
|
|
import { registerRouterTools } from "../../src/tools/devops/router.js";
|
|
import { registerMathTools } from "../../src/tools/family/math.js";
|
|
import { registerBabyTools } from "../../src/tools/family/baby.js";
|
|
import { registerFootballTools } from "../../src/tools/hobbies/football.js";
|
|
import { registerGameTools } from "../../src/tools/hobbies/games.js";
|
|
import { registerNoteTools } from "../../src/tools/common/notes.js";
|
|
import { registerTaskTools } from "../../src/tools/common/tasks.js";
|
|
|
|
describe("MCP Server Integration", () => {
|
|
beforeEach(() => {
|
|
// Register all tools
|
|
registerCodeSnippetTools();
|
|
registerProjectTemplateTools();
|
|
registerDocsTools();
|
|
registerCodeReviewTools();
|
|
registerServerTools();
|
|
registerRouterTools();
|
|
registerMathTools();
|
|
registerBabyTools();
|
|
registerFootballTools();
|
|
registerGameTools();
|
|
registerNoteTools();
|
|
registerTaskTools();
|
|
});
|
|
|
|
test("should register all tools", () => {
|
|
const tools = getRegisteredTools();
|
|
|
|
// Check that key tools are registered
|
|
expect(tools).toContain("code_snippet_save");
|
|
expect(tools).toContain("code_snippet_search");
|
|
expect(tools).toContain("project_template_create");
|
|
expect(tools).toContain("docs_typescript");
|
|
expect(tools).toContain("code_review");
|
|
expect(tools).toContain("note_create");
|
|
expect(tools).toContain("task_add");
|
|
expect(tools).toContain("math_problem_generate");
|
|
expect(tools).toContain("baby_milestone_add");
|
|
expect(tools).toContain("game_info");
|
|
expect(tools).toContain("server_status");
|
|
|
|
// Should have many tools registered
|
|
expect(tools.length).toBeGreaterThan(20);
|
|
});
|
|
|
|
test("should handle tool call with valid arguments", async () => {
|
|
const result = await callTool("docs_typescript", {});
|
|
|
|
expect(result.content).toBeDefined();
|
|
expect(result.content.length).toBeGreaterThan(0);
|
|
expect(result.content[0].type).toBe("text");
|
|
expect(result.content[0].text).toBeDefined();
|
|
});
|
|
|
|
test("should handle tool call with invalid tool name", async () => {
|
|
await expect(callTool("non_existent_tool", {})).rejects.toThrow(
|
|
"Tool non_existent_tool not found"
|
|
);
|
|
});
|
|
|
|
test("should handle tool errors gracefully", async () => {
|
|
// Call a tool that might fail (like server_status without proper config)
|
|
const result = await callTool("server_status", {});
|
|
|
|
// Should return an error response, not throw
|
|
expect(result.content).toBeDefined();
|
|
expect(result.content[0].text).toBeDefined();
|
|
});
|
|
|
|
test("should support multiple tool categories", () => {
|
|
const tools = getRegisteredTools();
|
|
|
|
// Programming tools
|
|
const programmingTools = tools.filter(
|
|
(t) =>
|
|
t.startsWith("code_") ||
|
|
t.startsWith("project_") ||
|
|
t.startsWith("docs_")
|
|
);
|
|
expect(programmingTools.length).toBeGreaterThan(0);
|
|
|
|
// Family tools
|
|
const familyTools = tools.filter(
|
|
(t) => t.startsWith("math_") || t.startsWith("baby_")
|
|
);
|
|
expect(familyTools.length).toBeGreaterThan(0);
|
|
|
|
// Common tools
|
|
const commonTools = tools.filter(
|
|
(t) => t.startsWith("note_") || t.startsWith("task_")
|
|
);
|
|
expect(commonTools.length).toBeGreaterThan(0);
|
|
|
|
// Hobby tools
|
|
const hobbyTools = tools.filter(
|
|
(t) => t.startsWith("game_") || t.startsWith("football_")
|
|
);
|
|
expect(hobbyTools.length).toBeGreaterThan(0);
|
|
});
|
|
});
|