UNPKG

@takashito/linode-mcp-server

Version:

MCP server for Linode API

115 lines 5.09 kB
#!/usr/bin/env node "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.VERSION = exports.createClient = exports.startServer = void 0; const commander_1 = require("commander"); const dotenv_1 = require("dotenv"); const server_1 = require("./server"); Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return server_1.VERSION; } }); Object.defineProperty(exports, "startServer", { enumerable: true, get: function () { return server_1.startServer; } }); const client_1 = require("./client"); Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return client_1.createClient; } }); const tools_1 = require("./tools"); // Load environment variables from .env file (0, dotenv_1.config)(); // Define CLI program const program = new commander_1.Command(); program .name('linode-mcp-server') .description('MCP server for Linode API integration with Claude Desktop') .version(server_1.VERSION); program .option('-t, --token <token>', 'Linode API token') .option('-c, --categories <categories>', `Tool categories to enable (comma-separated). Available: ${tools_1.TOOL_CATEGORIES.join(', ')}`, (val) => val.split(',').map(c => c.trim())) .option('--list-categories', 'List all available tool categories') .option('--transport <type>', 'Transport type: stdio (default), sse, http', 'stdio') .option('--port <port>', 'Server port (default: 8080 for HTTP, 3000 for SSE)', 'default') .option('--endpoint <endpoint>', 'Server endpoint path (default: /mcp for HTTP, /sse for SSE)', 'default') .option('--host <host>', 'SSE server host (default: 127.0.0.1)', '127.0.0.1') .action(async (options) => { // If --list-categories was specified, show available categories and exit if (options.listCategories) { console.log('Available tool categories:'); tools_1.TOOL_CATEGORIES.forEach(cat => console.log(`- ${cat}`)); process.exit(0); } // Check for token in command line args, then env var, then .env file const token = options.token || process.env.LINODE_API_TOKEN; // Ensure the token is provided if (!token) { console.error('Error: Linode API token is required'); console.error('Please provide a token with --token option or set LINODE_API_TOKEN environment variable'); process.exit(1); } // Validate categories if provided let enabledCategories = undefined; if (options.categories && options.categories.length > 0) { // Check each category is valid const invalidCategories = options.categories.filter((cat) => !tools_1.TOOL_CATEGORIES.includes(cat)); if (invalidCategories.length > 0) { console.error(`Error: Invalid categories: ${invalidCategories.join(', ')}`); console.error(`Available categories: ${tools_1.TOOL_CATEGORIES.join(', ')}`); process.exit(1); } enabledCategories = options.categories; } // Determine which transport to use let useSSE = false; let useHTTP = false; if (options.transport) { if (options.transport.toLowerCase() === 'sse') { useSSE = true; } else if (options.transport.toLowerCase() === 'http') { useHTTP = true; } else if (options.transport.toLowerCase() !== 'stdio') { console.error(`Error: Invalid transport type: ${options.transport}`); console.error(`Available transport types: stdio, sse, http`); process.exit(1); } } // Prepare server options const serverOptions = { token, enabledCategories, transport: options.transport.toLowerCase(), httpOptions: useHTTP ? { port: options.port === 'default' ? 8080 : parseInt(options.port, 10), endpoint: options.endpoint === 'default' ? '/mcp' : options.endpoint } : undefined, sseOptions: useSSE ? { port: options.port === 'default' ? 3000 : parseInt(options.port, 10), endpoint: options.endpoint === 'default' ? '/sse' : options.endpoint, host: options.host } : undefined }; // Start the server try { // Start the server await (0, server_1.startServer)(serverOptions); // Add event listeners for errors process.on('uncaughtException', (error) => { console.error(`Uncaught exception: ${error}`); }); process.on('unhandledRejection', (error) => { console.error(`Unhandled rejection: ${error}`); }); } catch (error) { // Report error to stderr to avoid breaking stdio protocol console.error('Error starting server:', error); process.exit(1); } }); // Auto-start server when this file is executed directly (not imported) if (require.main === module) { try { program.parse(); } catch (error) { console.error('Error during program execution:', error); process.exit(1); } } //# sourceMappingURL=index.js.map