Why OpenSafari should reflect this
network_intercept currently keeps intercept rules in a module-global activeRules array and applies/clears them without using the canonical src/network-interceptor.ts implementation. In long-lived MCP sessions this can leak request blocking/mocking rules across independent sessions, and the clear path restores fetch only while leaving XHR hooks outside the canonical restore contract.
This is directionally aligned with OpenSafari because network interception is a user-facing QA feature: stale or cross-session rules can make Safari/webview tests fail in ways that look like app or network bugs rather than automation state leakage.
Risk / user impact
- Severity: high reliability risk, medium user impact.
- A stale rule can block login, API calls, or asset loads in later tests.
- Incomplete restore can leave a page in a modified network state after
clear or network_offline=false.
- The issue is scoped to existing OpenSafari network tooling and does not require new dependencies.
How to implement
- Route
network_intercept and network_offline through src/network-interceptor.ts.
- Scope interceptor instances by MCP session id, with an explicit default only for legacy callers.
- Add optional
device_id support so tools can target the intended WebKit connection.
- Preserve existing action names:
block stays block; modify maps to the canonical mock response path.
- Ensure clear/disable restores fetch and XHR hooks through the canonical disable path.
- Add unit tests proving session isolation and action mapping.
Decisions needed before implementation
- Whether a future PR should expose rule ids for individual removal; first PR can keep clear-all behavior.
- Whether interceptor state should be additionally keyed by device id; first PR can use session scope plus
device_id routing.
- Whether response headers should be configurable; first PR can preserve text/plain default.
Success criteria
- Rules added in one MCP session do not affect another session's interceptor state.
clear=true disables and clears only that session's interceptor.
network_offline uses the same per-session interceptor as network_intercept.
- Existing
block/modify tool responses remain backward compatible.
- Targeted tests, lint, build, and CI pass.
Post-merge OpenSafari live validation
- Start two MCP sessions against Safari; add an intercept rule in session A and confirm session B has no rule count/state leakage.
- Add a
modify rule and confirm fetch returns mocked response.
- Call
clear=true, then confirm normal fetch/XHR behavior is restored in that session.
- Toggle
network_offline on/off and confirm the same page can fetch again after restore.
Direction/necessity review
- Aligned: yes, this protects existing Safari QA/network tooling from cross-session state leakage.
- Necessary: yes, long-running AI-agent MCP sessions routinely reuse the same process and can otherwise inherit stale rules.
- Minimal first PR: per-session canonical interceptor routing and tests only; no new network interception feature surface beyond optional
device_id.
Why OpenSafari should reflect this
network_interceptcurrently keeps intercept rules in a module-globalactiveRulesarray and applies/clears them without using the canonicalsrc/network-interceptor.tsimplementation. In long-lived MCP sessions this can leak request blocking/mocking rules across independent sessions, and the clear path restoresfetchonly while leaving XHR hooks outside the canonical restore contract.This is directionally aligned with OpenSafari because network interception is a user-facing QA feature: stale or cross-session rules can make Safari/webview tests fail in ways that look like app or network bugs rather than automation state leakage.
Risk / user impact
clearornetwork_offline=false.How to implement
network_interceptandnetwork_offlinethroughsrc/network-interceptor.ts.device_idsupport so tools can target the intended WebKit connection.blockstays block;modifymaps to the canonical mock response path.Decisions needed before implementation
device_idrouting.Success criteria
clear=truedisables and clears only that session's interceptor.network_offlineuses the same per-session interceptor asnetwork_intercept.block/modifytool responses remain backward compatible.Post-merge OpenSafari live validation
modifyrule and confirm fetch returns mocked response.clear=true, then confirm normal fetch/XHR behavior is restored in that session.network_offlineon/off and confirm the same page can fetch again after restore.Direction/necessity review
device_id.