()
| 106 | } |
| 107 | |
| 108 | async function generateCli() { |
| 109 | const tools = await fetchTools(); |
| 110 | |
| 111 | const staticTools = createTools(parseArguments()); |
| 112 | const toolNameToCategoryEnum = new Map<string, string>(); |
| 113 | const toolNameToConditions = new Map<string, string[]>(); |
| 114 | |
| 115 | for (const tool of staticTools) { |
| 116 | toolNameToCategoryEnum.set(tool.name, tool.annotations.category); |
| 117 | toolNameToConditions.set(tool.name, tool.annotations.conditions || []); |
| 118 | } |
| 119 | |
| 120 | // Sort tools by name |
| 121 | const sortedTools = tools |
| 122 | .sort((a, b) => a.name.localeCompare(b.name)) |
| 123 | .filter(tool => { |
| 124 | // Skipping fill_form because it is not relevant in shell scripts |
| 125 | // and CLI does not handle array/JSON args well. |
| 126 | if (tool.name === 'fill_form') { |
| 127 | return false; |
| 128 | } |
| 129 | // Skipping wait_for because CLI does not handle array/JSON args well |
| 130 | // and shell scripts have many mechanisms for waiting. |
| 131 | if (tool.name === 'wait_for') { |
| 132 | return false; |
| 133 | } |
| 134 | // Skipping get_tab_id as it is for internal integrations |
| 135 | if (tool.name === 'get_tab_id') { |
| 136 | return false; |
| 137 | } |
| 138 | // Skipping in_page tools as they are not launched yet |
| 139 | if (toolNameToCategoryEnum.get(tool.name) === ToolCategory.IN_PAGE) { |
| 140 | return false; |
| 141 | } |
| 142 | return true; |
| 143 | }); |
| 144 | |
| 145 | const commands: Record< |
| 146 | string, |
| 147 | {description: string; category: string; args: Record<string, CliOption>} |
| 148 | > = {}; |
| 149 | |
| 150 | for (const tool of sortedTools) { |
| 151 | const options = schemaToCLIOptions(tool.inputSchema); |
| 152 | const args: Record<string, CliOption> = {}; |
| 153 | for (const opt of options) { |
| 154 | args[opt.name] = opt; |
| 155 | } |
| 156 | |
| 157 | const categoryEnum = toolNameToCategoryEnum.get(tool.name); |
| 158 | if (!categoryEnum) { |
| 159 | throw new Error(`Tool ${tool.name} has no category.`); |
| 160 | } |
| 161 | const category = labels[categoryEnum as unknown as keyof typeof labels]; |
| 162 | if (!tool.description) { |
| 163 | throw new Error(`Tool ${tool.name} is missing description`); |
| 164 | } |
| 165 |
no test coverage detected