Skip to content

Commit 27b5816

Browse files
committed
tool for listing in-page tools
1 parent f7ae9e8 commit 27b5816

3 files changed

Lines changed: 42 additions & 34 deletions

File tree

src/bin/chrome-devtools-mcp-cli-options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ export const cliOptions = {
219219
categoryInPageTools: {
220220
type: 'boolean',
221221
hidden: true,
222+
default: false,
222223
describe:
223224
'Set to true to enable tools exposed by the inspected page itself',
224225
},

tests/cli.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ describe('cli args parsing', () => {
2323
performanceCrux: true,
2424
'usage-statistics': true,
2525
usageStatistics: true,
26+
'category-in-page-tools': false,
27+
categoryInPageTools: false,
2628
};
2729

2830
it('parses with default args', async () => {

tests/index.test.ts

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -72,47 +72,52 @@ describe('e2e', () => {
7272
});
7373

7474
it('has all tools', async () => {
75-
await withClient(async client => {
76-
const {tools} = await client.listTools();
77-
const exposedNames = tools.map(t => t.name).sort();
78-
const files = fs.readdirSync('build/src/tools');
79-
const definedNames = [];
80-
for (const file of files) {
81-
if (
82-
file === 'ToolDefinition.js' ||
83-
file === 'tools.js' ||
84-
file === 'slim'
85-
) {
86-
continue;
87-
}
88-
const fileTools = await import(`../src/tools/${file}`);
89-
for (const maybeTool of Object.values<unknown>(fileTools)) {
90-
if (typeof maybeTool === 'function') {
91-
const tool = (maybeTool as (val: boolean) => ToolDefinition)(false);
92-
if (tool && typeof tool === 'object' && 'name' in tool) {
75+
await withClient(
76+
async client => {
77+
const {tools} = await client.listTools();
78+
const exposedNames = tools.map(t => t.name).sort();
79+
const files = fs.readdirSync('build/src/tools');
80+
const definedNames = [];
81+
for (const file of files) {
82+
if (
83+
file === 'ToolDefinition.js' ||
84+
file === 'tools.js' ||
85+
file === 'slim'
86+
) {
87+
continue;
88+
}
89+
const fileTools = await import(`../src/tools/${file}`);
90+
for (const maybeTool of Object.values<unknown>(fileTools)) {
91+
if (typeof maybeTool === 'function') {
92+
const tool = (maybeTool as (val: boolean) => ToolDefinition)(
93+
false,
94+
);
95+
if (tool && typeof tool === 'object' && 'name' in tool) {
96+
if (tool.annotations?.conditions) {
97+
continue;
98+
}
99+
definedNames.push(tool.name);
100+
}
101+
continue;
102+
}
103+
if (
104+
typeof maybeTool === 'object' &&
105+
maybeTool !== null &&
106+
'name' in maybeTool
107+
) {
108+
const tool = maybeTool as ToolDefinition;
93109
if (tool.annotations?.conditions) {
94110
continue;
95111
}
96112
definedNames.push(tool.name);
97113
}
98-
continue;
99-
}
100-
if (
101-
typeof maybeTool === 'object' &&
102-
maybeTool !== null &&
103-
'name' in maybeTool
104-
) {
105-
const tool = maybeTool as ToolDefinition;
106-
if (tool.annotations?.conditions) {
107-
continue;
108-
}
109-
definedNames.push(tool.name);
110114
}
111115
}
112-
}
113-
definedNames.sort();
114-
assert.deepStrictEqual(exposedNames, definedNames);
115-
});
116+
definedNames.sort();
117+
assert.deepStrictEqual(exposedNames, definedNames);
118+
},
119+
['--category-in-page-tools'],
120+
);
116121
});
117122

118123
it('has experimental in-Page tools', async () => {

0 commit comments

Comments
 (0)