Skip to content

Commit 7760d33

Browse files
committed
test(mcp): add eval scenarios for vague and URL-based webpage prompts (refs #940)
1 parent 5a169bf commit 7760d33

3 files changed

Lines changed: 94 additions & 2 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* @license
3+
* Copyright 2026 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Eval scenario: user asks to fix issues with their webpage (no URL given).
7+
* When no URL is provided, the model should pick the current frontend and run
8+
* and inspect it. Verifies the MCP server is invoked and the model opens the
9+
* frontend and inspects it (snapshot, console, or network).
10+
*
11+
* Note: Tools like performance_start_trace, take_snapshot, list_console_messages,
12+
* and list_network_requests do not require a URL in the prompt—they operate on
13+
* the currently selected page. Only navigate_page/new_page need a URL to open
14+
* a page; the eval runner injects the test URL when htmlRoute is set.
15+
*/
16+
17+
import assert from 'node:assert';
18+
19+
import type {TestScenario} from '../eval_gemini.ts';
20+
21+
const INSPECTION_TOOLS = [
22+
'take_snapshot',
23+
'list_console_messages',
24+
'list_network_requests',
25+
];
26+
27+
export const scenario: TestScenario = {
28+
prompt: 'Can you fix issues with my webpage?',
29+
maxTurns: 4,
30+
htmlRoute: {
31+
path: '/fix_issues_test.html',
32+
htmlContent: `
33+
<h1>Test Page</h1>
34+
<p>Some content</p>
35+
<script>
36+
console.error('Intentional error for testing');
37+
</script>
38+
`,
39+
},
40+
expectations: calls => {
41+
const NAVIGATION_TOOLS = ['navigate_page', 'new_page'];
42+
assert.ok(calls.length >= 2, 'Expected at least navigation and one inspection');
43+
const navigationIndex = calls.findIndex(c => NAVIGATION_TOOLS.includes(c.name));
44+
assert.ok(
45+
navigationIndex !== -1,
46+
`Expected a navigation call (${NAVIGATION_TOOLS.join(' or ')}), got: ${calls.map(c => c.name).join(', ')}`,
47+
);
48+
const afterNavigation = calls.slice(navigationIndex + 1);
49+
const inspectionCalls = afterNavigation.filter(c =>
50+
INSPECTION_TOOLS.includes(c.name),
51+
);
52+
assert.ok(
53+
inspectionCalls.length >= 1,
54+
`Expected at least one inspection tool (${INSPECTION_TOOLS.join(', ')}) after navigation, got: ${calls.map(c => c.name).join(', ')}`,
55+
);
56+
},
57+
};
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @license
3+
* Copyright 2026 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*
6+
* Eval scenario using "website"/"webpage" wording to verify the model invokes
7+
* the right tools when users ask to open a site and read its content.
8+
*/
9+
10+
import assert from 'node:assert';
11+
12+
import type {TestScenario} from '../eval_gemini.ts';
13+
14+
export const scenario: TestScenario = {
15+
prompt:
16+
'Open the website at <TEST_URL> and tell me what content is on the page.',
17+
maxTurns: 3,
18+
htmlRoute: {
19+
path: '/frontend_snapshot.html',
20+
htmlContent: '<h1>Frontend Test</h1><p>This is a test webpage.</p>',
21+
},
22+
expectations: calls => {
23+
assert.strictEqual(calls.length, 2);
24+
assert.ok(
25+
calls[0].name === 'navigate_page' || calls[0].name === 'new_page',
26+
'First call should be navigation',
27+
);
28+
assert.strictEqual(
29+
calls[1].name,
30+
'take_snapshot',
31+
'Second call should be take_snapshot to read page content',
32+
);
33+
},
34+
};

src/tools/pages.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ export const closePage = defineTool({
8080

8181
export const newPage = defineTool({
8282
name: 'new_page',
83-
description: `Creates a new page`,
83+
84+
description: `Open a new tab and load a URL. If no URL given, ask to run from current directory or for the URL.`,
8485
annotations: {
8586
category: ToolCategory.NAVIGATION,
8687
readOnlyHint: false,
@@ -113,7 +114,7 @@ export const newPage = defineTool({
113114

114115
export const navigatePage = defineTool({
115116
name: 'navigate_page',
116-
description: `Navigates the currently selected page to a URL.`,
117+
description: `Go to a URL, or back, forward, or reload. If no URL given, ask to run from current directory or for the URL.`,
117118
annotations: {
118119
category: ToolCategory.NAVIGATION,
119120
readOnlyHint: false,

0 commit comments

Comments
 (0)