mcpServerApproval.tsx
1 import React from 'react' 2 import { render } from 'ink' 3 import { MCPServerMultiselectDialog } from '../components/MCPServerMultiselectDialog.js' 4 import { MCPServerApprovalDialog } from '../components/MCPServerApprovalDialog.js' 5 import { getMcprcServerStatus } from './mcpClient.js' 6 import { getMcprcConfig } from '../utils/config.js' 7 8 export async function handleMcprcServerApprovals(): Promise<void> { 9 const mcprcServers = getMcprcConfig() 10 const pendingServers = Object.keys(mcprcServers).filter( 11 serverName => getMcprcServerStatus(serverName) === 'pending', 12 ) 13 14 if (pendingServers.length === 0) { 15 return 16 } 17 18 await new Promise<void>(resolve => { 19 const clearScreenAndResolve = () => { 20 // Clear screen after dialog 21 process.stdout.write('\x1b[2J\x1b[3J\x1b[H', () => { 22 resolve() 23 }) 24 } 25 26 if (pendingServers.length === 1 && pendingServers[0] !== undefined) { 27 const result = render( 28 <MCPServerApprovalDialog 29 serverName={pendingServers[0]} 30 onDone={() => { 31 result.unmount?.() 32 clearScreenAndResolve() 33 }} 34 />, 35 { exitOnCtrlC: false }, 36 ) 37 } else { 38 const result = render( 39 <MCPServerMultiselectDialog 40 serverNames={pendingServers} 41 onDone={() => { 42 result.unmount?.() 43 clearScreenAndResolve() 44 }} 45 />, 46 { exitOnCtrlC: false }, 47 ) 48 } 49 }) 50 }