()
| 79 | } |
| 80 | |
| 81 | async function generateCli() { |
| 82 | const cliDefaults = ServerConfig.applyDefaults( |
| 83 | {viaCli: true}, |
| 84 | {suppressUsageStatisticsNotice: true}, |
| 85 | ); |
| 86 | const tools = createTools(cliDefaults); |
| 87 | |
| 88 | // Sort tools by name |
| 89 | const sortedTools = tools |
| 90 | .sort((a, b) => a.name.localeCompare(b.name)) |
| 91 | .filter(tool => { |
| 92 | // Skipping slim tools and tools behind internal flags. |
| 93 | if (isSlimTool(tool) || requiresHiddenFlag(tool)) { |
| 94 | return false; |
| 95 | } |
| 96 | // Skipping fill_form because it is not relevant in shell scripts |
| 97 | // and CLI does not handle array/JSON args well. |
| 98 | if (tool.name === 'fill_form') { |
| 99 | return false; |
| 100 | } |
| 101 | // Skipping wait_for because CLI does not handle array/JSON args well |
| 102 | // and shell scripts have many mechanisms for waiting. |
| 103 | if (tool.name === 'wait_for') { |
| 104 | return false; |
| 105 | } |
| 106 | // Skipping get_tab_id as it is for internal integrations |
| 107 | if (tool.name === 'get_tab_id') { |
| 108 | return false; |
| 109 | } |
| 110 | // Skipping in_page tools as they are not launched yet |
| 111 | if (tool.annotations.category === ToolCategory.IN_PAGE) { |
| 112 | return false; |
| 113 | } |
| 114 | return true; |
| 115 | }); |
| 116 | |
| 117 | const commands: Record< |
| 118 | string, |
| 119 | {description: string; category: string; args: Record<string, CliOption>} |
| 120 | > = {}; |
| 121 | |
| 122 | for (const tool of sortedTools) { |
| 123 | const inputSchema = zod.toJSONSchema(zod.object(tool.schema), { |
| 124 | io: 'input', |
| 125 | }) as JsonSchema; |
| 126 | const options = schemaToCLIOptions(tool.name, inputSchema); |
| 127 | const args: Record<string, CliOption> = {}; |
| 128 | for (const opt of options) { |
| 129 | args[opt.name] = opt; |
| 130 | } |
| 131 | |
| 132 | const categoryEnum = tool.annotations.category; |
| 133 | if (!categoryEnum) { |
| 134 | throw new Error(`Tool ${tool.name} has no category.`); |
| 135 | } |
| 136 | const category = labels[categoryEnum as unknown as keyof typeof labels]; |
| 137 | if (!tool.description) { |
| 138 | throw new Error(`Tool ${tool.name} is missing description`); |
no test coverage detected