UNPKG

guardz-generator-mcp

Version:

MCP (Model Context Protocol) Server for TypeScript Type Guard Generation - Generate runtime validation functions from TypeScript types

108 lines โ€ข 3.32 kB
#!/usr/bin/env node /** * Test script for Guardz Generator MCP Server * * This script tests the basic functionality of the MCP server by: * 1. Starting the server * 2. Sending a tools/list request * 3. Sending a generate_type_guards request * 4. Verifying the responses */ import { spawn } from 'child_process'; import { writeFileSync, unlinkSync } from 'fs'; import { join } from 'path'; const TEST_INTERFACE = ` interface TestUser { id: string; name: string; email: string; age?: number; } `; const TEST_FILE_PATH = join(process.cwd(), 'test-user.ts'); // Create test file writeFileSync(TEST_FILE_PATH, TEST_INTERFACE); console.log('๐Ÿงช Testing Guardz Generator MCP Server...\n'); // Start the MCP server const serverProcess = spawn('node', ['dist/mcp-guardz-generator.js'], { stdio: ['pipe', 'pipe', 'pipe'], }); let serverStarted = false; let serverOutput = ''; serverProcess.stdout.on('data', data => { serverOutput += data.toString(); }); serverProcess.stderr.on('data', data => { const output = data.toString(); if (output.includes('Guardz Generator MCP Server started')) { serverStarted = true; console.log('โœ… MCP server started successfully'); } }); // Test sequence setTimeout(() => { if (!serverStarted) { console.log('โŒ MCP server failed to start'); serverProcess.kill(); process.exit(1); } console.log('\n2. Testing tools/list request...'); const listRequest = { jsonrpc: '2.0', id: 1, method: 'tools/list', }; serverProcess.stdin.write(JSON.stringify(listRequest) + '\n'); setTimeout(() => { if (serverOutput.includes('generate_type_guards')) { console.log('โœ… Tools list request successful'); } else { console.log('โŒ Tools list request failed'); } console.log('\n3. Testing generate_type_guards request...'); const generateRequest = { jsonrpc: '2.0', id: 2, method: 'tools/call', params: { name: 'generate_type_guards', arguments: { files: [TEST_FILE_PATH], postProcess: false, verbose: true, }, }, }; serverProcess.stdin.write(JSON.stringify(generateRequest) + '\n'); setTimeout(async () => { if (serverOutput.includes('Successfully generated') || serverOutput.includes('Error')) { console.log('โœ… Generate type guards request processed'); } else { console.log('โŒ Generate type guards request failed'); } serverProcess.kill(); try { unlinkSync(TEST_FILE_PATH); } catch { // Ignore cleanup errors } console.log('\n๐ŸŽ‰ MCP server test completed!'); console.log('\nServer output:'); console.log(serverOutput); }, 2000); }, 1000); }, 2000); // Handle process termination process.on('SIGINT', () => { serverProcess.kill(); process.exit(0); }); process.on('SIGTERM', () => { serverProcess.kill(); process.exit(0); }); //# sourceMappingURL=test-mcp.js.map