UNPKG

mcp-framework

Version:

Framework for building Model Context Protocol (MCP) servers in Typescript

51 lines (50 loc) • 1.95 kB
import { Command } from 'commander'; import { join } from 'path'; import { existsSync, readdirSync } from 'fs'; import { pathToFileURL } from 'url'; export const validateCommand = new Command('validate') .description('Validate all tools in the current project') .action(async () => { console.log('šŸ” Validating tools...\n'); const distPath = join(process.cwd(), 'dist', 'tools'); if (!existsSync(distPath)) { console.error('āŒ No dist/tools directory found. Run "npm run build" first.'); process.exit(1); } const toolFiles = readdirSync(distPath).filter((f) => f.endsWith('.js') && !f.includes('.test.')); const errors = []; let validatedCount = 0; for (const file of toolFiles) { try { const toolPath = pathToFileURL(join(distPath, file)).href; const module = await import(toolPath); const ToolClass = module.default; if (ToolClass && typeof ToolClass === 'function') { const instance = new ToolClass(); if ('validate' in instance && typeof instance.validate === 'function') { try { instance.validate(); validatedCount++; console.log(`āœ… ${file}: Valid`); } catch (error) { errors.push(`āŒ ${file}: ${error.message}`); } } } } catch (error) { errors.push(`āŒ ${file}: Failed to load - ${error.message}`); } } console.log(''); if (errors.length > 0) { console.error('Validation failed:\n'); errors.forEach((error) => console.error(error)); console.error(`\nāŒ ${errors.length} error(s) found`); process.exit(1); } else { console.log(`āœ… All ${validatedCount} tools validated successfully!`); } });