#!/usr/bin/env node
/**
* MCP Server Entry Point
*
* DESIGN PATTERNS:
* - CLI pattern with Commander for argument parsing
* - Command pattern for organizing CLI commands
* - Transport abstraction for multiple communication methods
*
* CODING STANDARDS:
* - Use async/await for asynchronous operations
* - Handle errors gracefully with try-catch
* - Log important events for debugging
* - Register all commands in main entry point
*
* AVOID:
* - Hardcoding command logic in index.ts (use separate command files)
* - Missing error handling for command execution
*/
import { Command } from 'commander';
import {
initCommand,
mcpServeCommand,
listToolsCommand,
describeToolsCommand,
useToolCommand,
listResourcesCommand,
readResourceCommand,
prefetchCommand,
} from './commands';
import packageJson from '../package.json' assert { type: 'json' };
/**
* Main entry point
*/
async function main() {
try {
const program = new Command();
program
.name('one-mcp')
.description('One MCP server package')
.version(packageJson.version);
// Add all commands
program.addCommand(initCommand);
program.addCommand(mcpServeCommand);
program.addCommand(listToolsCommand);
program.addCommand(describeToolsCommand);
program.addCommand(useToolCommand);
program.addCommand(listResourcesCommand);
program.addCommand(readResourceCommand);
program.addCommand(prefetchCommand);
// Parse arguments
await program.parseAsync(process.argv);
} catch (error) {
console.error(`CLI execution failed: ${error instanceof Error ? error.message : error}`);
process.exit(1);
}
}
main().catch((error) => {
console.error(`Fatal error: ${error instanceof Error ? error.message : error}`);
process.exit(1);
});