Skip to content

Commit 6296cef

Browse files
committed
test: update tests for --allow-unrestricted-paths behavior change
- Update the legacy 'validatePath allows all paths if roots are undefined' test to explicitly pass allowUnrestrictedPaths: true, matching the new behavior where the old permissive default requires an opt-in flag. - Add a new test verifying that paths outside tmpdir are denied by default when the client never negotiates roots (and the flag is not set). - Expose allowUnrestrictedPaths in withMcpContext() test helper. - Run npm run gen to update README and telemetry metrics for the new flag.
1 parent 76f9207 commit 6296cef

4 files changed

Lines changed: 31 additions & 3 deletions

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,11 @@ The Chrome DevTools MCP server supports the following configuration option:
744744
- **Type:** boolean
745745
- **Default:** `false`
746746

747+
- **`--allowUnrestrictedPaths`/ `--allow-unrestricted-paths`**
748+
If set, disables the default path restriction that applies when the MCP client does not negotiate the roots capability. By default, file-writing tools are restricted to the OS temp directory when no roots are configured. Use this only when connecting a trusted local client that does not implement MCP roots and requires access to paths outside the temp directory.
749+
- **Type:** boolean
750+
- **Default:** `false`
751+
747752
<!-- END AUTO GENERATED OPTIONS -->
748753

749754
Pass them via the `args` property in the JSON configuration. For example:

src/telemetry/flag_usage_metrics.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,5 +347,13 @@
347347
{
348348
"name": "screenshot_max_height_present",
349349
"flagType": "boolean"
350+
},
351+
{
352+
"name": "allow_unrestricted_paths_present",
353+
"flagType": "boolean"
354+
},
355+
{
356+
"name": "allow_unrestricted_paths",
357+
"flagType": "boolean"
350358
}
351359
]

tests/McpContext.test.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,23 @@ describe('McpContext', () => {
278278
});
279279
});
280280

281-
it('validatePath allows all paths if roots are undefined (legacy)', async () => {
281+
it('validatePath allows all paths if roots are undefined and allowUnrestrictedPaths is set', async () => {
282+
await withMcpContext(
283+
async (_response, context) => {
284+
context.setRoots(undefined);
285+
await context.validatePath(path.resolve(os.homedir(), 'anywhere.txt'));
286+
},
287+
{allowUnrestrictedPaths: true},
288+
);
289+
});
290+
291+
it('validatePath denies paths outside tmpdir if roots are undefined and allowUnrestrictedPaths is not set', async () => {
282292
await withMcpContext(async (_response, context) => {
283-
context.setRoots(undefined);
284-
await context.validatePath(path.resolve(os.homedir(), 'anywhere.txt'));
293+
// setRoots() never called — simulates a client that skips roots capability.
294+
const outsidePath = path.resolve(os.homedir(), 'anywhere.txt');
295+
await assert.rejects(context.validatePath(outsidePath), /Access denied/);
296+
// Temp dir must still be reachable.
297+
await context.validatePath(path.join(os.tmpdir(), 'test.txt'));
285298
});
286299
});
287300

tests/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export async function withMcpContext(
121121
args?: string[];
122122
blockedUrlPattern?: string[];
123123
allowedUrlPattern?: string[];
124+
allowUnrestrictedPaths?: boolean;
124125
} = {},
125126
args: Partial<ParsedArguments> = {},
126127
) {
@@ -138,6 +139,7 @@ export async function withMcpContext(
138139
performanceCrux: options.performanceCrux ?? true,
139140
allowList: options.allowedUrlPattern,
140141
blocklist: options.blockedUrlPattern,
142+
allowUnrestrictedPaths: options.allowUnrestrictedPaths ?? false,
141143
},
142144
Locator,
143145
);

0 commit comments

Comments
 (0)