UNPKG

@baguskto/saham

Version:

MCP Server untuk data saham Indonesia (IDX) - Implementasi Node.js/TypeScript

194 lines 7.93 kB
#!/usr/bin/env node "use strict"; /** * CLI entry point for IDX MCP Server */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); const commander_1 = require("commander"); const server_1 = require("./server"); const config_1 = require("./config"); const logger_1 = require("./utils/logger"); const cache_1 = require("./cache"); const data_sources_1 = require("./data-sources"); const program = new commander_1.Command(); program .name('baguskto-saham') .description('MCP Server untuk data saham Indonesia (IDX)') .version('1.0.0'); program .command('start') .description('Start the MCP server') .option('--debug', 'Enable debug mode') .action(async (options) => { try { if (options.debug) { process.env['IDX_MCP_DEBUG'] = 'true'; process.env['IDX_MCP_LOG_LEVEL'] = 'debug'; } logger_1.logger.info('Starting Baguskto Saham MCP Server...'); logger_1.logger.info(`Configuration: ${JSON.stringify(config_1.config.get(), null, 2)}`); const server = await (0, server_1.createServer)(); await server.run(); } catch (error) { logger_1.logger.error('Failed to start server:', error); process.exit(1); } }); program .command('test') .description('Test the data sources and connectivity') .action(async () => { try { logger_1.logger.info('Testing Baguskto Saham MCP Server components...'); // Test configuration logger_1.logger.info('✓ Configuration loaded'); // Test data sources const { getDataSourceManager } = await Promise.resolve().then(() => __importStar(require('./data-sources'))); const dataManager = getDataSourceManager(); logger_1.logger.info('Testing market overview...'); const marketData = await dataManager.getMarketOverview(); if (marketData) { logger_1.logger.info(`✓ Market overview: IHSG ${marketData.ihsgValue} (${marketData.ihsgChangePercent.toFixed(2)}%)`); } else { logger_1.logger.warn('✗ Market overview failed'); } logger_1.logger.info('Testing stock info (BBCA)...'); const stockData = await dataManager.getStockInfo('BBCA'); if (stockData) { logger_1.logger.info(`✓ Stock info: ${stockData.name} - ${stockData.currentPrice} (${stockData.priceChangePercent.toFixed(2)}%)`); } else { logger_1.logger.warn('✗ Stock info failed'); } // Test cache logger_1.logger.info('Testing cache...'); await cache_1.cacheManager.set('test_key', { test: 'data' }, 10); const cached = await cache_1.cacheManager.get('test_key'); if (cached) { logger_1.logger.info('✓ Cache working'); await cache_1.cacheManager.del('test_key'); } else { logger_1.logger.warn('✗ Cache failed'); } // Show stats const stats = (0, data_sources_1.getDataSourceStats)(); logger_1.logger.info('Data source statistics:'); for (const [name, stat] of Object.entries(stats)) { logger_1.logger.info(` ${name}: ${stat.isHealthy ? '✓' : '✗'} healthy, ${stat.successCount} success, ${stat.errorCount} errors`); } const cacheStats = await cache_1.cacheManager.stats(); logger_1.logger.info(`Cache statistics: ${cacheStats.keys} keys, ${cacheStats.hitRate}% hit rate`); logger_1.logger.info('Test completed'); } catch (error) { logger_1.logger.error('Test failed:', error); process.exit(1); } }); program .command('clear-cache') .description('Clear the cache') .action(async () => { try { logger_1.logger.info('Clearing cache...'); await cache_1.cacheManager.clear(); logger_1.logger.info('✓ Cache cleared'); } catch (error) { logger_1.logger.error('Failed to clear cache:', error); process.exit(1); } }); program .command('stats') .description('Show server statistics') .action(async () => { try { logger_1.logger.info('Baguskto Saham MCP Server Statistics'); logger_1.logger.info('========================'); const serverConfig = config_1.config.getServer(); logger_1.logger.info(`Server: ${serverConfig.name} v${serverConfig.version}`); const stats = (0, data_sources_1.getDataSourceStats)(); logger_1.logger.info('\nData Sources:'); for (const [name, stat] of Object.entries(stats)) { logger_1.logger.info(` ${name}:`); logger_1.logger.info(` Status: ${stat.isHealthy ? 'Healthy' : 'Unhealthy'}`); logger_1.logger.info(` Priority: ${stat.priority}`); logger_1.logger.info(` Requests: ${stat.successCount} success, ${stat.errorCount} errors`); logger_1.logger.info(` Avg Response Time: ${stat.averageResponseTime.toFixed(2)}ms`); if (stat.lastRequest) { logger_1.logger.info(` Last Request: ${stat.lastRequest.toISOString()}`); } } const cacheStats = await cache_1.cacheManager.stats(); logger_1.logger.info('\nCache:'); logger_1.logger.info(` Type: ${config_1.config.getCache().type}`); logger_1.logger.info(` Keys: ${cacheStats.keys}`); logger_1.logger.info(` Hit Rate: ${cacheStats.hitRate}%`); logger_1.logger.info(` Hits: ${cacheStats.hits}`); logger_1.logger.info(` Misses: ${cacheStats.misses}`); } catch (error) { logger_1.logger.error('Failed to get statistics:', error); process.exit(1); } }); // Check if we should run in MCP mode (default when no specific command is given) const isStartCommand = process.argv.includes('start'); const hasCommands = process.argv.some(arg => ['test', 'clear-cache', 'stats', 'help', '--help', '-h'].includes(arg)); if (!hasCommands && !isStartCommand) { // No command specified, start the server in MCP mode // Disable stdout logging for MCP mode to avoid interfering with stdio transport process.env['IDX_MCP_LOG_LEVEL'] = 'error'; (async () => { try { const server = await (0, server_1.createServer)(); await server.run(); } catch (error) { // Only log to stderr in MCP mode console.error('Failed to start server:', error); process.exit(1); } })(); } else { program.parse(); } //# sourceMappingURL=cli.js.map