Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions scripts/generate-docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
Expand Down Expand Up @@ -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`;
Expand Down
26 changes: 24 additions & 2 deletions src/McpResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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}`
Expand Down
3 changes: 2 additions & 1 deletion src/bin/check-latest-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/tools/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <select> dropdowns or comboboxes, use the 'fill' tool instead to select options directly.`,
annotations: {
category: ToolCategory.INPUT,
readOnlyHint: false,
Expand Down
16 changes: 14 additions & 2 deletions src/tools/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,23 @@ export const listPages = defineTool(args => {
category: ToolCategory.NAVIGATION,
readOnlyHint: true,
},
schema: {},
handler: async (_request, response) => {
schema: {
limit: zod
.number()
.optional()
.describe('Maximum number of pages to return.'),
query: zod
.string()
.optional()
.describe('Filter pages by URL containing this query string.'),
},
handler: async (request, response) => {
response.setIncludePages(true);
response.setListInPageTools();
response.setListWebMcpTools();
if (request.params.limit || request.params.query) {
response.setPageListOptions(request.params.limit, request.params.query);
}
},
};
});
Expand Down