@takashito/linode-mcp-server
Version:
MCP server for Linode API
105 lines • 4.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const commander_1 = require("commander");
const dotenv_1 = require("dotenv");
const server_1 = require("./server");
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: 3000 for sse, 8080 for http)', undefined)
.option('--host <host>', '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;
// 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;
}
// Validate transport type
const validTransports = ['stdio', 'sse', 'http'];
if (!validTransports.includes(options.transport.toLowerCase())) {
console.error(`Error: Invalid transport type: ${options.transport}`);
console.error(`Available transport types: ${validTransports.join(', ')}`);
process.exit(1);
}
// Set default ports based on transport type
let defaultPort;
if (options.transport.toLowerCase() === 'sse') {
defaultPort = 3000;
}
else if (options.transport.toLowerCase() === 'http') {
defaultPort = 8080;
}
else {
defaultPort = 8000; // stdio (not used, but for consistency)
// Ensure the token is provided
if (!token) {
console.error('Error: Linode API token is required for stdio transport');
console.error('Please provide a token with --token option or set LINODE_API_TOKEN environment variable');
process.exit(1);
}
}
// Prepare server options
const serverOptions = {
token,
enabledCategories,
transport: options.transport.toLowerCase(),
port: options.port ? parseInt(options.port, 10) : defaultPort,
host: options.host,
endpoint: options.endpoint
};
// 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