UNPKG

mcpay

Version:

SDK and CLI for MCPay functionality - MCP servers with payment capabilities

133 lines 5.77 kB
#!/usr/bin/env node "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const dotenv_1 = require("dotenv"); const commander_1 = require("commander"); const accounts_1 = require("viem/accounts"); const start_stdio_server_js_1 = require("../server/stdio/start-stdio-server.js"); (0, dotenv_1.config)(); const program = new commander_1.Command(); program .name('mcpay') .description('MCPay CLI - MCP servers with payment capabilities') .version('0.0.2'); program .command('server') .description('Start an MCP stdio server with payment transport') .requiredOption('-u, --urls <urls>', 'Comma-separated list of server URLs') .option('-k, --private-key <key>', 'Private key for wallet (or set PRIVATE_KEY env var)') .option('-t, --transport <type>', 'Transport type (payment, http, sse)', 'payment') .action(async (options) => { try { const privateKeyString = options.privateKey || process.env.PRIVATE_KEY; if (!privateKeyString) { console.error('Error: Private key is required. Use --private-key or set PRIVATE_KEY environment variable.'); process.exit(1); } // Validate and cast to Hex type if (!privateKeyString.startsWith('0x') || privateKeyString.length !== 66) { console.error('Error: Private key must be a valid hex string starting with 0x and 64 characters long.'); process.exit(1); } const privateKey = privateKeyString; const serverUrls = options.urls.split(',').map((url) => url.trim()); if (serverUrls.length === 0) { console.error('Error: At least one server URL is required.'); process.exit(1); } const account = (0, accounts_1.privateKeyToAccount)(privateKey); // Map transport type to ServerType enum let serverType; switch (options.transport.toLowerCase()) { case 'payment': serverType = start_stdio_server_js_1.ServerType.Payment; break; case 'sse': serverType = start_stdio_server_js_1.ServerType.SSE; break; case 'http': default: serverType = start_stdio_server_js_1.ServerType.HTTPStream; break; } console.log(`Starting MCP server with ${options.transport} transport...`); console.log(`Connecting to ${serverUrls.length} server(s): ${serverUrls.join(', ')}`); const serverConnections = (0, start_stdio_server_js_1.createServerConnections)(serverUrls, serverType); await (0, start_stdio_server_js_1.startStdioServer)({ serverConnections, account, }); console.log(`Successfully connected to ${serverUrls.length} servers`); } catch (error) { console.error('Failed to start server:', error); process.exit(1); } }); program .command('proxy') .description('Start a proxy server (alias for server command)') .requiredOption('-u, --urls <urls>', 'Comma-separated list of server URLs') .option('-k, --private-key <key>', 'Private key for wallet (or set PRIVATE_KEY env var)') .option('-t, --transport <type>', 'Transport type (payment, http, sse)', 'payment') .action(async (options) => { // Duplicate server logic (since it's an alias) try { const privateKeyString = options.privateKey || process.env.PRIVATE_KEY; if (!privateKeyString) { console.error('Error: Private key is required. Use --private-key or set PRIVATE_KEY environment variable.'); process.exit(1); } // Validate and cast to Hex type if (!privateKeyString.startsWith('0x') || privateKeyString.length !== 66) { console.error('Error: Private key must be a valid hex string starting with 0x and 64 characters long.'); process.exit(1); } const privateKey = privateKeyString; const serverUrls = options.urls.split(',').map((url) => url.trim()); if (serverUrls.length === 0) { console.error('Error: At least one server URL is required.'); process.exit(1); } const account = (0, accounts_1.privateKeyToAccount)(privateKey); // Map transport type to ServerType enum let serverType; switch (options.transport.toLowerCase()) { case 'payment': serverType = start_stdio_server_js_1.ServerType.Payment; break; case 'sse': serverType = start_stdio_server_js_1.ServerType.SSE; break; case 'http': default: serverType = start_stdio_server_js_1.ServerType.HTTPStream; break; } console.log(`Starting MCP proxy server with ${options.transport} transport...`); console.log(`Connecting to ${serverUrls.length} server(s): ${serverUrls.join(', ')}`); const serverConnections = (0, start_stdio_server_js_1.createServerConnections)(serverUrls, serverType); await (0, start_stdio_server_js_1.startStdioServer)({ serverConnections, account, }); console.log(`Successfully connected to ${serverUrls.length} servers via proxy`); } catch (error) { console.error('Failed to start proxy server:', error); process.exit(1); } }); program .command('version') .description('Show version information') .action(() => { console.log('mcpay-sdk version 0.0.2'); }); // Parse command line arguments program.parse(); // If no command was provided, show help if (!process.argv.slice(2).length) { program.outputHelp(); } //# sourceMappingURL=index.js.map