diff --git a/scripts/generate-docs.ts b/scripts/generate-docs.ts index 4be8fcbd7..cf3f107db 100644 --- a/scripts/generate-docs.ts +++ b/scripts/generate-docs.ts @@ -141,8 +141,14 @@ function generateToolsTOC( const categoryName = labels[category]; toc += `- **${categoryName}** (${categoryTools.length} tools)\n`; - // Sort tools within category for TOC - categoryTools.sort((a: Tool, b: Tool) => a.name.localeCompare(b.name)); + // Sort tools within category for TOC: no-arg tools first, then with args + categoryTools.sort((a: Tool, b: Tool) => { + const aHasRequired = a.inputSchema?.required?.length ?? 0 > 0; + const bHasRequired = b.inputSchema?.required?.length ?? 0 > 0; + if (!aHasRequired && bHasRequired) return -1; + if (aHasRequired && !bHasRequired) return 1; + return a.name.localeCompare(b.name); + }); for (const tool of categoryTools) { const anchorLink = tool.name.toLowerCase(); toc += ` - [\`${tool.name}\`](docs/tool-reference.md#${anchorLink})\n`; @@ -361,8 +367,14 @@ async function generateReference( markdown += `> NOTE: ${categoryName} are not active by default. Use the '${flagName}' flag\n\n`; } - // Sort tools within category - categoryTools.sort((a: Tool, b: Tool) => a.name.localeCompare(b.name)); + // Sort tools within category: no-arg tools first, then tools with required args, then optional-arg tools + categoryTools.sort((a: Tool, b: Tool) => { + const aHasRequired = a.inputSchema?.required?.length ?? 0 > 0; + const bHasRequired = b.inputSchema?.required?.length ?? 0 > 0; + if (!aHasRequired && bHasRequired) return -1; + if (aHasRequired && !bHasRequired) return 1; + return a.name.localeCompare(b.name); + }); for (const tool of categoryTools) { markdown += `### \`${tool.name}\`\n\n`; diff --git a/src/McpResponse.ts b/src/McpResponse.ts index 246536b77..81994c671 100644 --- a/src/McpResponse.ts +++ b/src/McpResponse.ts @@ -203,12 +203,19 @@ export class McpResponse implements Response { #args: ParsedArguments; #page?: McpPage; #redactNetworkHeaders = true; + #pageLimit?: number; + #pageQuery?: string; #error?: Error; constructor(args: ParsedArguments) { this.#args = args; } + setPageListOptions(limit?: number, query?: string): void { + this.#pageLimit = limit; + this.#pageQuery = query; + } + setPage(page: McpPage): void { this.#page = page; } @@ -803,9 +810,24 @@ Call ${handleDialog.name} to handle it before continuing.`); ); if (regularPages.length) { - const parts = [`## Pages`]; + // Apply query filter if specified + let filteredPages = regularPages; + if (this.#pageQuery) { + const queryLower = this.#pageQuery.toLowerCase(); + filteredPages = regularPages.filter(page => + page.url().toLowerCase().includes(queryLower), + ); + } + + // Apply limit if specified + const displayPages = this.#pageLimit + ? filteredPages.slice(0, this.#pageLimit) + : filteredPages; + const hasMore = filteredPages.length > displayPages.length; + + const parts = [`## Pages${hasMore ? ` (showing ${displayPages.length} of ${filteredPages.length})` : ''}`]; const structuredPages = []; - for (const page of regularPages) { + for (const page of displayPages) { const isolatedContextName = context.getIsolatedContextName(page); const contextLabel = isolatedContextName ? ` isolatedContext=${isolatedContextName}` diff --git a/src/bin/check-latest-version.ts b/src/bin/check-latest-version.ts index eb45674df..f8f0c652d 100644 --- a/src/bin/check-latest-version.ts +++ b/src/bin/check-latest-version.ts @@ -12,8 +12,9 @@ const cachePath = process.argv[2]; if (cachePath) { try { + const registry = process.env.npm_config_registry?.replace(/\/$/, '') || 'https://registry.npmjs.org'; const response = await fetch( - 'https://registry.npmjs.org/chrome-devtools-mcp/latest', + `${registry}/chrome-devtools-mcp/latest`, ); const data = response.ok ? await response.json() : null; diff --git a/src/tools/input.ts b/src/tools/input.ts index 588f5308b..0e98cf8d1 100644 --- a/src/tools/input.ts +++ b/src/tools/input.ts @@ -44,7 +44,7 @@ function handleActionError(error: unknown, uid: string) { export const click = definePageTool({ name: 'click', - description: `Clicks on the provided element`, + description: `Clicks on an element (buttons, links, etc.). For