()
| 38 | |
| 39 | // 显示命令提示 |
| 40 | function showPrompt() { |
| 41 | console.log('\n📝 Available commands:'); |
| 42 | console.log('1. List all tools'); |
| 43 | console.log('2. Search CSS techniques'); |
| 44 | console.log('3. Get random CSS tip'); |
| 45 | console.log('4. Custom command'); |
| 46 | console.log('5. Exit'); |
| 47 | |
| 48 | rl.question('\n👉 Enter command number: ', (answer) => { |
| 49 | switch(answer) { |
| 50 | case '1': |
| 51 | sendCommand({ |
| 52 | jsonrpc: "2.0", |
| 53 | id: 1, |
| 54 | method: "tools/list", |
| 55 | params: {} |
| 56 | }); |
| 57 | break; |
| 58 | case '2': |
| 59 | rl.question('Enter search query: ', (query) => { |
| 60 | sendCommand({ |
| 61 | jsonrpc: "2.0", |
| 62 | id: 2, |
| 63 | method: "tools/call", |
| 64 | params: { |
| 65 | name: "search_css_techniques", |
| 66 | arguments: { |
| 67 | query: query, |
| 68 | limit: 3 |
| 69 | } |
| 70 | } |
| 71 | }); |
| 72 | }); |
| 73 | break; |
| 74 | case '3': |
| 75 | sendCommand({ |
| 76 | jsonrpc: "2.0", |
| 77 | id: 3, |
| 78 | method: "tools/call", |
| 79 | params: { |
| 80 | name: "get_random_css_tip", |
| 81 | arguments: {} |
| 82 | } |
| 83 | }); |
| 84 | break; |
| 85 | case '4': |
| 86 | rl.question('Enter custom JSON-RPC command: ', (cmd) => { |
| 87 | try { |
| 88 | const command = JSON.parse(cmd); |
| 89 | sendCommand(command); |
| 90 | } catch (e) { |
| 91 | console.error('❌ Invalid JSON:', e.message); |
| 92 | showPrompt(); |
| 93 | } |
| 94 | }); |
| 95 | break; |
| 96 | case '5': |
| 97 | console.log('👋 Shutting down server...'); |
no test coverage detected