UNPKG

@grebyn/toolflow-mcp-server

Version:

MCP server for managing other MCP servers - discover, install, organize into bundles, and automate with workflows. Uses StreamableHTTP transport with dual OAuth/API key authentication.

114 lines (106 loc) • 4.93 kB
/** * Get Bundle Config Tool * Retrieve bundle configuration adapted for specific client */ import { ApiClient } from '../../utils/api-client.js'; export const getBundleConfigTool = { name: 'get_bundle_config', description: 'Get bundle configuration ready for installation. The returned configuration can be used directly with write_client_config to install all servers in the bundle.', inputSchema: { type: 'object', properties: { bundle_id: { type: 'string', description: 'Bundle ID to retrieve configuration for. Get this from list_bundles results.' } }, required: ['bundle_id'] }, async execute(args, context) { try { // Validate user context if (!context.userId) { throw new Error('User authentication required'); } // Validate bundle_id format (basic UUID check) const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; if (!uuidRegex.test(args.bundle_id)) { throw new Error('Invalid bundle ID format. Please provide a valid UUID from list_bundles.'); } // Get bundle configuration from API const bundleData = await ApiClient.getBundleConfig(args.bundle_id, context); if (!bundleData) { throw new Error('Failed to retrieve bundle or access denied'); } if (!bundleData || bundleData.length === 0) { throw new Error('Bundle not found or access denied. Verify the bundle ID is correct and you have access to it. Use `list_bundles` to find available bundles.'); } const bundle = bundleData[0]; // Extract server configurations const bundleConfig = bundle.config; if (!bundleConfig.servers || Object.keys(bundleConfig.servers).length === 0) { throw new Error('Bundle contains no server configurations'); } // Use the server configurations directly from the bundle const adaptedServers = { ...bundleConfig.servers }; // Build response const serverCount = Object.keys(adaptedServers).length; const serverNames = Object.keys(adaptedServers); const installCommands = bundle.install_commands || []; // Check for environment variables that need to be set const serversWithEnv = Object.entries(adaptedServers) .filter(([_, config]) => config.env && Object.keys(config.env).length > 0) .map(([name, config]) => ({ name, envVars: Object.keys(config.env) })); const envWarning = serversWithEnv.length > 0 ? ` āš ļø **Environment Variables Required:** ${serversWithEnv.map(server => `- **${server.name}**: ${server.envVars.join(', ')}`).join('\n')} Make sure to set these environment variables before installing the bundle.` : ''; const installSection = installCommands.length > 0 ? ` šŸ“‹ **Installation Commands Required:** Before configuring the servers, run these commands: ${installCommands.map((cmd) => `\`\`\`bash\n${cmd}\n\`\`\``).join('\n')}` : ''; return { content: [ { type: 'text', text: `šŸ“¦ **Bundle Configuration Retrieved** **Bundle**: ${bundle.name} **Description**: ${bundle.description} **Servers**: ${serverCount} MCP server${serverCount === 1 ? '' : 's'} **Server List**: ${serverNames.join(', ')}${installSection}${envWarning} **Configuration:** \`\`\`json ${JSON.stringify(adaptedServers, null, 2)} \`\`\` **Next Steps:** ${installCommands.length > 0 ? '1. **Run installation commands** (shown above)\n' : ''}${installCommands.length > 0 ? '2' : '1'}. **Set environment variables** if any are required (see above) ${installCommands.length > 0 ? '3' : '2'}. **Install the bundle** using: \`write_client_config\` with this configuration ${installCommands.length > 0 ? '4' : '3'}. **Restart your client** if required (Claude Desktop, etc.) **Example Installation:** \`\`\` write_client_config({ config: { servers: ${JSON.stringify(adaptedServers, null, 2)} } }) \`\`\` **Note:** The CLIENT environment variable determines which client will receive this configuration.` } ] }; } catch (error) { console.error('Get bundle config error:', error); return { content: [ { type: 'text', text: `āŒ Failed to get bundle configuration: ${error.message}` } ] }; } } }; //# sourceMappingURL=get-bundle-config.js.map