Skip to content

Commit 6f03271

Browse files
committed
chore: get tabid tool
1 parent 9a51af2 commit 6f03271

5 files changed

Lines changed: 54 additions & 0 deletions

File tree

src/cli.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ export const cliOptions = {
163163
'Whether to include all kinds of pages such as webviews or background pages as pages.',
164164
hidden: true,
165165
},
166+
experimentalInteropTools: {
167+
type: 'boolean',
168+
describe: 'Whether to enable interoperability tools',
169+
hidden: true,
170+
},
166171
chromeArg: {
167172
type: 'array',
168173
describe:

src/main.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,12 @@ function registerTool(tool: ToolDefinition): void {
131131
) {
132132
return;
133133
}
134+
if (
135+
tool.annotations.conditions?.includes('experimentalInterop') &&
136+
!args.experimentalInteropTools
137+
) {
138+
return;
139+
}
134140
server.registerTool(
135141
tool.name,
136142
{

src/tools/pages.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,26 @@ export const handleDialog = defineTool({
269269
response.setIncludePages(true);
270270
},
271271
});
272+
273+
export const getTabId = defineTool({
274+
name: 'get_tab_id',
275+
description: `Get the tab ID of the page`,
276+
annotations: {
277+
category: ToolCategory.NAVIGATION,
278+
readOnlyHint: true,
279+
conditions: ['experimentalInterop'],
280+
},
281+
schema: {
282+
pageId: zod
283+
.number()
284+
.describe(
285+
`The ID of the page to get the tab ID for. Call ${listPages.name} to get available pages.`,
286+
),
287+
},
288+
handler: async (request, response, context) => {
289+
const page = context.getPageById(request.params.pageId);
290+
// @ts-expect-error _tabId is internal.
291+
const tabId = page._tabId;
292+
response.appendResponseLine(tabId);
293+
},
294+
});

tests/index.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ describe('e2e', () => {
101101
if (maybeTool.annotations?.conditions?.includes('computerVision')) {
102102
continue;
103103
}
104+
if (
105+
maybeTool.annotations?.conditions?.includes(
106+
'experimentalInteropTools',
107+
)
108+
) {
109+
continue;
110+
}
104111
definedNames.push(maybeTool.name);
105112
}
106113
}

tests/tools/pages.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
navigatePage,
1818
resizePage,
1919
handleDialog,
20+
getTabId,
2021
} from '../../src/tools/pages.js';
2122
import {withMcpContext} from '../utils.js';
2223

@@ -322,4 +323,16 @@ describe('pages', () => {
322323
});
323324
});
324325
});
326+
327+
describe('get_tab_id', () => {
328+
it('returns the tab id', async () => {
329+
await withMcpContext(async (response, context) => {
330+
const page = context.getSelectedPage();
331+
// @ts-expect-error _tabId is internal.
332+
page._tabId = 'test-tab-id';
333+
await getTabId.handler({params: {pageId: 1}}, response, context);
334+
assert.ok(response.responseLines.includes('test-tab-id'));
335+
});
336+
});
337+
});
325338
});

0 commit comments

Comments
 (0)