Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore(mcp): do not set custom prefix for tools in vscode (#37651)

Yury Semikhatskycafa2c5f7289
diff --git "a/examples/todomvc/.github/chatmodes/ \360\237\216\255 planner.chatmode.md" "b/examples/todomvc/.github/chatmodes/ \360\237\216\255 planner.chatmode.md"
index c3dc932df9..4f1446b86d 100644
--- "a/examples/todomvc/.github/chatmodes/ \360\237\216\255 planner.chatmode.md"
+++ "b/examples/todomvc/.github/chatmodes/ \360\237\216\255 planner.chatmode.md"
@@ -1,6 +1,6 @@
---
description: Use this agent when you need to create comprehensive test plan for a web application or website.
-tools: ['createFile', 'createDirectory', 'fileSearch', 'textSearch', 'listDirectory', 'readFile', 'test_browser_click', 'test_browser_close', 'test_browser_console_messages', 'test_browser_drag', 'test_browser_evaluate', 'test_browser_file_upload', 'test_browser_handle_dialog', 'test_browser_hover', 'test_browser_navigate', 'test_browser_navigate_back', 'test_browser_network_requests', 'test_browser_press_key', 'test_browser_select_option', 'test_browser_snapshot', 'test_browser_take_screenshot', 'test_browser_type', 'test_browser_wait_for', 'test_setup_page']
+tools: ['edit/createFile', 'edit/createDirectory', 'search/fileSearch', 'search/textSearch', 'search/listDirectory', 'search/readFile', 'playwright-test/browser_click', 'playwright-test/browser_close', 'playwright-test/browser_console_messages', 'playwright-test/browser_drag', 'playwright-test/browser_evaluate', 'playwright-test/browser_file_upload', 'playwright-test/browser_handle_dialog', 'playwright-test/browser_hover', 'playwright-test/browser_navigate', 'playwright-test/browser_navigate_back', 'playwright-test/browser_network_requests', 'playwright-test/browser_press_key', 'playwright-test/browser_select_option', 'playwright-test/browser_snapshot', 'playwright-test/browser_take_screenshot', 'playwright-test/browser_type', 'playwright-test/browser_wait_for', 'playwright-test/test_setup_page']
---
You are an expert web test planner with extensive experience in quality assurance, user experience testing, and test
diff --git "a/examples/todomvc/.github/chatmodes/\360\237\216\255 generator.chatmode.md" "b/examples/todomvc/.github/chatmodes/\360\237\216\255 generator.chatmode.md"
index 7ec0fb8a00..7bf8f247aa 100644
--- "a/examples/todomvc/.github/chatmodes/\360\237\216\255 generator.chatmode.md"
+++ "b/examples/todomvc/.github/chatmodes/\360\237\216\255 generator.chatmode.md"
@@ -1,6 +1,6 @@
---
description: Use this agent when you need to create automated browser tests using Playwright.
-tools: ['createFile', 'createDirectory', 'fileSearch', 'textSearch', 'listDirectory', 'readFile', 'test_browser_click', 'test_browser_drag', 'test_browser_evaluate', 'test_browser_file_upload', 'test_browser_handle_dialog', 'test_browser_hover', 'test_browser_navigate', 'test_browser_press_key', 'test_browser_select_option', 'test_browser_snapshot', 'test_browser_type', 'test_browser_verify_element_visible', 'test_browser_verify_list_visible', 'test_browser_verify_text_visible', 'test_browser_verify_value', 'test_browser_wait_for', 'test_setup_page']
+tools: ['edit/createFile', 'edit/createDirectory', 'search/fileSearch', 'search/textSearch', 'search/listDirectory', 'search/readFile', 'playwright-test/browser_click', 'playwright-test/browser_drag', 'playwright-test/browser_evaluate', 'playwright-test/browser_file_upload', 'playwright-test/browser_handle_dialog', 'playwright-test/browser_hover', 'playwright-test/browser_navigate', 'playwright-test/browser_press_key', 'playwright-test/browser_select_option', 'playwright-test/browser_snapshot', 'playwright-test/browser_type', 'playwright-test/browser_verify_element_visible', 'playwright-test/browser_verify_list_visible', 'playwright-test/browser_verify_text_visible', 'playwright-test/browser_verify_value', 'playwright-test/browser_wait_for', 'playwright-test/test_setup_page']
---
You are a Playwright Test Generator, an expert in browser automation and end-to-end testing.
diff --git "a/examples/todomvc/.github/chatmodes/\360\237\216\255 healer.chatmode.md" "b/examples/todomvc/.github/chatmodes/\360\237\216\255 healer.chatmode.md"
index ea1dd53015..6604d74030 100644
--- "a/examples/todomvc/.github/chatmodes/\360\237\216\255 healer.chatmode.md"
+++ "b/examples/todomvc/.github/chatmodes/\360\237\216\255 healer.chatmode.md"
@@ -1,6 +1,6 @@
---
description: Use this agent when you need to debug and fix failing Playwright tests.
-tools: ['createFile', 'createDirectory', 'editFiles', 'fileSearch', 'textSearch', 'listDirectory', 'readFile', 'test_browser_console_messages', 'test_browser_evaluate', 'test_browser_generate_locator', 'test_browser_network_requests', 'test_browser_snapshot', 'test_debug', 'test_list', 'test_run']
+tools: ['edit/createFile', 'edit/createDirectory', 'edit/editFiles', 'search/fileSearch', 'search/textSearch', 'search/listDirectory', 'search/readFile', 'playwright-test/browser_console_messages', 'playwright-test/browser_evaluate', 'playwright-test/browser_generate_locator', 'playwright-test/browser_network_requests', 'playwright-test/browser_snapshot', 'playwright-test/test_debug', 'playwright-test/test_list', 'playwright-test/test_run']
---
You are the Playwright Test Healer, an expert test automation engineer specializing in debugging and
diff --git a/examples/todomvc/.vscode/mcp.json b/examples/todomvc/.vscode/mcp.json
index 8cb0a2009c..f0c78a8aab 100644
--- a/examples/todomvc/.vscode/mcp.json
+++ b/examples/todomvc/.vscode/mcp.json
@@ -6,11 +6,7 @@
"args": [
"playwright",
"run-test-mcp-server"
- ],
- "cwd": "${workspaceFolder}",
- "env": {
- "PLAYWRIGHT_MCP_TOOL_PREFIX": "test_"
- }
+ ]
}
},
"inputs": []
diff --git a/packages/playwright/src/agents/generateAgents.ts b/packages/playwright/src/agents/generateAgents.ts
index 2ce295f8ca..b99cb5bd0f 100644
--- a/packages/playwright/src/agents/generateAgents.ts
+++ b/packages/playwright/src/agents/generateAgents.ts
@@ -210,19 +210,19 @@ export async function initClaudeCodeRepo() {
}
const vscodeToolMap = new Map<string, string[]>([
- ['ls', ['listDirectory', 'fileSearch']],
- ['grep', ['textSearch']],
- ['read', ['readFile']],
- ['edit', ['editFiles']],
- ['write', ['createFile', 'createDirectory']],
+ ['ls', ['search/listDirectory', 'search/fileSearch']],
+ ['grep', ['search/textSearch']],
+ ['read', ['search/readFile']],
+ ['edit', ['edit/editFiles']],
+ ['write', ['edit/createFile', 'edit/createDirectory']],
]);
-const vscodeToolsOrder = ['createFile', 'createDirectory', 'editFiles', 'fileSearch', 'textSearch', 'listDirectory', 'readFile'];
-const vscodeToolPrefix = 'test_'; // FIXME: Remove this once VSCode rolls fix for https://github.com/microsoft/vscode/issues/267811.
+const vscodeToolsOrder = ['edit/createFile', 'edit/createDirectory', 'edit/editFiles', 'search/fileSearch', 'search/textSearch', 'search/listDirectory', 'search/readFile'];
+const vscodeMcpName = 'playwright-test';
function saveAsVSCodeChatmode(agent: Agent): string {
function asVscodeTool(tool: string): string | string[] {
const [first, second] = tool.split('/');
if (second)
- return second.startsWith('browser_') ? vscodeToolPrefix + second : second;
+ return `${vscodeMcpName}/${second}`;
return vscodeToolMap.get(first) || first;
}
const tools = agent.header.tools.map(asVscodeTool).flat().sort((a, b) => {
@@ -276,9 +276,7 @@ export async function initVSCodeRepo() {
mcpJson.servers['playwright-test'] = {
type: 'stdio',
command: commonMcpServers.playwrightTest.command,
- args: commonMcpServers.playwrightTest.args,
- cwd: '${workspaceFolder}',
- env: { 'PLAYWRIGHT_MCP_TOOL_PREFIX': vscodeToolPrefix },
+ args: commonMcpServers.playwrightTest.args
};
await writeFile(mcpJsonPath, JSON.stringify(mcpJson, null, 2));
}
diff --git a/packages/playwright/src/mcp/browser/tools.ts b/packages/playwright/src/mcp/browser/tools.ts
index e5927c2888..3ebbe7591e 100644
--- a/packages/playwright/src/mcp/browser/tools.ts
+++ b/packages/playwright/src/mcp/browser/tools.ts
@@ -57,13 +57,6 @@ export const browserTools: Tool<any>[] = [
...verify,
];
-// FIXME: this is ugly, fix VSCode!
-const customPrefix = process.env.PLAYWRIGHT_MCP_TOOL_PREFIX;
-if (customPrefix) {
- for (const tool of browserTools)
- tool.schema.name = customPrefix + tool.schema.name;
-}
-
export function filteredTools(config: FullConfig) {
return browserTools.filter(tool => tool.capability.startsWith('core') || config.capabilities?.includes(tool.capability));
}
diff --git a/tests/mcp/prefix.spec.ts b/tests/mcp/prefix.spec.ts
deleted file mode 100644
index 6a096eef0d..0000000000
--- a/tests/mcp/prefix.spec.ts
+++ /dev/null
@@ -1,122 +0,0 @@
-/**
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import { test, expect, prepareDebugTest } from './fixtures';
-
-test('tool prefix', async ({ startClient, server }) => {
- const { client } = await startClient({ env: { 'PLAYWRIGHT_MCP_TOOL_PREFIX': 'test_' } });
- expect(await client.callTool({
- name: 'test_browser_navigate',
- arguments: { url: server.HELLO_WORLD },
- })).toHaveResponse({
- code: `await page.goto('${server.HELLO_WORLD}');`,
- pageState: `- Page URL: ${server.HELLO_WORLD}
-- Page Title: Title
-- Page Snapshot:
-\`\`\`yaml
-- generic [active] [ref=e1]: Hello, world!
-\`\`\``,
- });
-});
-
-test('alert dialog', async ({ server, startClient }) => {
- const { client } = await startClient({ env: { 'PLAYWRIGHT_MCP_TOOL_PREFIX': 'test_' } });
- server.setContent('/', `<button onclick="alert('Alert')">Button</button>`, 'text/html');
- expect(await client.callTool({
- name: 'test_browser_navigate',
- arguments: { url: server.PREFIX },
- })).toHaveResponse({
- pageState: expect.stringContaining(`- button "Button" [ref=e2]`),
- });
-
- expect(await client.callTool({
- name: 'test_browser_click',
- arguments: {
- element: 'Button',
- ref: 'e2',
- },
- })).toHaveResponse({
- code: `await page.getByRole('button', { name: 'Button' }).click();`,
- modalState: `- ["alert" dialog with message "Alert"]: can be handled by the "test_browser_handle_dialog" tool`,
- });
-});
-
-test('browser_file_upload', async ({ server, startClient }) => {
- const { client } = await startClient({ env: { 'PLAYWRIGHT_MCP_TOOL_PREFIX': 'test_' } });
- server.setContent('/', `
- <input type="file" />
- <button>Button</button>
- `, 'text/html');
-
- expect(await client.callTool({
- name: 'test_browser_navigate',
- arguments: { url: server.PREFIX },
- })).toHaveResponse({
- pageState: expect.stringContaining(`- generic [active] [ref=e1]:
- - button "Choose File" [ref=e2]
- - button "Button" [ref=e3]`),
- });
-
- expect(await client.callTool({
- name: 'test_browser_file_upload',
- arguments: { paths: [] },
- })).toHaveResponse({
- isError: true,
- result: expect.stringContaining(`The tool "test_browser_file_upload" can only be used when there is related modal state present.`),
- modalState: expect.stringContaining(`- There is no modal state present`),
- });
-});
-
-test.describe(() => {
- test.use({ mcpServerType: 'test-mcp' });
-
- test('test_debug (browser_snapshot/network/console)', async ({ startClient, server }) => {
- const { client, id } = await prepareDebugTest(startClient, `
- import { test, expect } from '@playwright/test';
- test('fail', async ({ page }) => {
- await page.goto(${JSON.stringify(server.HELLO_WORLD)});
- await page.evaluate(() => {
- console.log('hello from console');
- setTimeout(() => { throw new Error('error from page'); }, 0);
- });
- await expect(page.getByRole('button', { name: 'Missing' })).toBeVisible({ timeout: 1000 });
- });
- `, {
- env: { 'PLAYWRIGHT_MCP_TOOL_PREFIX': 'test_' },
- });
- await client.callTool({
- name: 'test_debug',
- arguments: {
- test: { id, title: 'fail' },
- },
- });
- await expect.poll(() => client.callTool({
- name: 'test_browser_network_requests',
- })).toHaveResponse({
- result: expect.stringContaining(`[GET] ${server.HELLO_WORLD} => [200] OK`),
- });
- expect(await client.callTool({
- name: 'test_browser_console_messages',
- })).toHaveResponse({
- result: expect.stringMatching(/\[LOG\] hello from console.*\nError: error from page/),
- });
- expect(await client.callTool({
- name: 'test_browser_snapshot',
- })).toHaveResponse({
- pageState: expect.stringContaining(`generic [active] [ref=e1]: Hello, world!`),
- });
- });
-});