UNPKG

mcp-codesentry

Version:

CodeSentry MCP - AI-powered code review assistant with 5 specialized review tools for security, best practices, and comprehensive code analysis

92 lines (77 loc) 2.84 kB
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'; import { MCPServer } from '../../src/core/server.js'; import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'; import type { ServerConfig } from '../../src/types/index.js'; // Mock the stdio transport vi.mock('@modelcontextprotocol/sdk/server/stdio.js'); // Mock the logger vi.mock('../../src/utils/logger.js', () => ({ logger: { info: vi.fn(), error: vi.fn(), warn: vi.fn(), debug: vi.fn() } })); describe('MCPServer', () => { let server: MCPServer; let mockTransport: StdioServerTransport; const testConfig: ServerConfig = { name: 'test-server', version: '1.0.0', gemini: { apiKey: 'test-key', proModel: 'gemini-1.5-pro', flashModel: 'gemini-1.5-flash' } }; beforeEach(() => { mockTransport = new StdioServerTransport(); server = new MCPServer(testConfig); }); afterEach(() => { vi.clearAllMocks(); }); describe('initialization', () => { it('should create server instance with correct config', () => { expect(server).toBeDefined(); expect(server.getServer()).toBeDefined(); }); it('should initialize McpServer with correct name and version', () => { const serverInstance = server.getServer(); expect(serverInstance).toBeDefined(); // The actual name/version are stored internally in McpServer }); }); describe('start', () => { it('should connect to transport when started', async () => { const connectSpy = vi.spyOn(server.getServer(), 'connect'); await server.start(mockTransport); expect(connectSpy).toHaveBeenCalledWith(mockTransport); }); }); describe('tool registration', () => { it('should register review_plan tool on initialization', () => { // Tools are registered in the constructor // We can't directly test this without invoking the tools expect(server.getServer()).toBeDefined(); }); it('should register review_implementation tool on initialization', () => { // Tools are registered in the constructor // We can't directly test this without invoking the tools expect(server.getServer()).toBeDefined(); }); }); describe('tool execution', () => { it('review_plan should return mock response', async () => { // Since we can't directly test tool handlers without a full MCP setup, // we're verifying the server is properly initialized expect(server.getServer()).toBeDefined(); }); it('review_implementation should return mock response', async () => { // Since we can't directly test tool handlers without a full MCP setup, // we're verifying the server is properly initialized expect(server.getServer()).toBeDefined(); }); }); });