import { NestFactory } from '@nestjs/core';
import { AppModule } from '@/app.module';
async function bootstrap() {
// Support for both STDIO and HTTP transports
const useHttpTransport = process.env.MCP_TRANSPORT === 'http';
if (useHttpTransport) {
// Use createNestApplication for HTTP transport
const app = await NestFactory.create(AppModule, {
logger: false,
});
const port = parseInt(process.env.MCP_PORT || '3001', 10);
await app.listen(port);
console.error('🚀 Timesheet MCP Server started successfully');
console.error('📋 Server name: timesheet-mcp-server');
console.error(`🔧 Transport: http://localhost:${port}`);
console.error('✨ Ready to receive MCP tool requests');
} else {
// Use createApplicationContext for STDIO (default)
// This creates a lightweight DI container without HTTP overhead
const app = await NestFactory.createApplicationContext(AppModule, {
logger: false, // Completely disable NestJS logger to prevent stdout pollution
});
// MCP server starts automatically with @rekog/mcp-nest
// The StdioService.onApplicationBootstrap() lifecycle hook initializes the MCP server
// Note: Do NOT log to console.error either as it can interfere with MCP protocol
// Don't close the app - let it run to handle requests
// The stdio transport keeps the process alive
}
}
// Use void to properly handle the async bootstrap function in STDIO mode
void bootstrap();