Network Mocking

Tools for mocking API responses without modifying your backend. Matched XHR/fetch requests return the mock response directly.

set_network_mock

Add a network mock rule. Matching requests will return the mocked response without hitting the network.

Parameters

ParameterTypeRequiredDescription
urlPatternstringYesURL pattern to match (substring or regex)
isRegexbooleanNoSet true if urlPattern is a regex
methodstringNoHTTP method filter. Omit to match all methods
statusnumberNoMock response status code. Default: 200
statusTextstringNoMock response status text
headersobjectNoMock response headers. e.g., { "Content-Type": "application/json" }
bodystringNoMock response body
delaynumberNoDelay in ms before returning the mock response
platform"ios" | "android"NoTarget platform
deviceIdstringNoTarget device

Example

// Mock a successful API response
{
  "tool": "set_network_mock",
  "arguments": {
    "urlPattern": "/api/users",
    "method": "GET",
    "status": 200,
    "headers": { "Content-Type": "application/json" },
    "body": "{\"users\":[{\"id\":1,\"name\":\"Alice\"}]}"
  }
}

// Simulate a server error
{
  "tool": "set_network_mock",
  "arguments": {
    "urlPattern": "/api/checkout",
    "method": "POST",
    "status": 500,
    "body": "{\"error\":\"Internal server error\"}"
  }
}

// Simulate slow network (2 second delay)
{
  "tool": "set_network_mock",
  "arguments": {
    "urlPattern": "/api/products",
    "delay": 2000,
    "body": "{\"products\":[]}"
  }
}

// Regex pattern matching
{
  "tool": "set_network_mock",
  "arguments": {
    "urlPattern": "/api/users/\\d+",
    "isRegex": true,
    "body": "{\"id\":1,\"name\":\"Mock User\"}"
  }
}

// Response
{ "id": 1, "urlPattern": "/api/users", "status": 200, "enabled": true }

Tips

  • Mocks intercept both fetch() and XMLHttpRequest calls.
  • Substring matching is the default. Use isRegex: true for complex patterns.
  • Mocks persist until explicitly removed or cleared.
  • The body must be a string. For JSON responses, stringify the object.

list_network_mocks

List all active network mock rules.

Parameters

ParameterTypeRequiredDescription
platform"ios" | "android"NoTarget platform
deviceIdstringNoTarget device

Example

// Request
{ "tool": "list_network_mocks" }

// Response
[
  { "id": 1, "urlPattern": "/api/users", "isRegex": false, "method": "GET", "status": 200, "enabled": true, "hitCount": 3 },
  { "id": 2, "urlPattern": "/api/checkout", "isRegex": false, "method": "POST", "status": 500, "enabled": true, "hitCount": 0 }
]

Tips

  • hitCount shows how many requests matched each mock — useful for verifying your mock was triggered.

remove_network_mock

Remove a specific network mock rule by its ID.

Parameters

ParameterTypeRequiredDescription
idnumberYesMock rule ID to remove (from list_network_mocks or set_network_mock response)
platform"ios" | "android"NoTarget platform
deviceIdstringNoTarget device

Example

{ "tool": "remove_network_mock", "arguments": { "id": 1 } }

To remove all mock rules at once, use the unified clear tool with target: "network_mocks":

{ "tool": "clear", "arguments": { "target": "network_mocks" } }

Call after a test scenario to ensure mocks don't leak into subsequent tests.