Skip to content

Conversation

@Suhaib3100
Copy link

@Suhaib3100 Suhaib3100 commented Jan 26, 2026

Summary

Fixes #38961

This PR adds two new MCP tools for mocking network responses dynamically:

New Tools

browser_network_mock

Mock 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 string
  • response.headers - Optional additional headers

browser_network_unmock

Remove all network mocks for a URL pattern.

Parameters:

  • urlPattern - URL pattern to unmock (must match the pattern used in browser_network_mock)

Use Cases

  1. AI agents can test error scenarios - Mock 500 errors, 404s, timeouts, etc.
  2. Test different API responses - Mock different data without requiring a backend
  3. Faster automation - No need to wait for real API calls
  4. Isolated testing - Control exactly what data the application receives

Example Usage

// Set up a mock
await client.callTool({
  name: 'browser_network_mock',
  arguments: {
    urlPattern: '**/api/users',
    response: {
      status: 200,
      contentType: 'application/json',
      body: JSON.stringify([{ id: 1, name: 'John' }]),
    },
  },
});

// Remove the mock
await client.callTool({
  name: 'browser_network_unmock',
  arguments: {
    urlPattern: '**/api/users',
  },
});

Tests

Added comprehensive tests in tests/mcp/network.spec.ts:

  • browser_network_mock - mock JSON API response
  • browser_network_unmock - remove mock

All tests pass on chromium and chrome.

Add two new MCP tools for mocking network responses:

- browser_network_mock: Mock a network response for a URL pattern with
  customizable status, content-type, body, and headers
- browser_network_unmock: Remove network mocks for a URL pattern

These tools enable AI agents to test applications with different API
responses, mock error scenarios, and isolate testing from real backends.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Add browser_network_mock and browser_network_unmock MCP tools

1 participant