feat(mcp): add browser_network_mock and browser_network_unmock tools #38960
+166
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #38961
This PR adds two new MCP tools for mocking network responses dynamically:
New Tools
browser_network_mockMock a network response for a URL pattern. When a request matches the pattern, it will be fulfilled with the provided response instead of going to the network.
Parameters:
urlPattern- URL pattern to match (glob pattern, e.g.,**/api/users,https://example.com/api/**)response.status- HTTP status code for the mocked response (default: 200)response.contentType- Content-Type header (default:application/json)response.body- Response body as a stringresponse.headers- Optional additional headersbrowser_network_unmockRemove all network mocks for a URL pattern.
Parameters:
urlPattern- URL pattern to unmock (must match the pattern used inbrowser_network_mock)Use Cases
Example Usage
Tests
Added comprehensive tests in
tests/mcp/network.spec.ts:browser_network_mock - mock JSON API responsebrowser_network_unmock - remove mockAll tests pass on chromium and chrome.