Skip to content

Fix 4 blocking issues from code review#7

Open
pyyush wants to merge 1 commit intomainfrom
fix/code-review-blocking-issues
Open

Fix 4 blocking issues from code review#7
pyyush wants to merge 1 commit intomainfrom
fix/code-review-blocking-issues

Conversation

@pyyush
Copy link
Contributor

@pyyush pyyush commented Feb 22, 2026

Summary

Fixes all 4 blocking issues identified in code review:

  • B1: Remove duplicated authorization code from server-playwright -- BAPScope, ScopeProfiles, MethodScopes, hasScope(), parseScopes(), and createAuthorizationError() were defined inline in server-playwright/server.ts instead of being imported from @browseragentprotocol/protocol where the canonical definitions live. Removed ~120 lines of duplicated code and replaced with imports.

  • B2: Add Zod input validation on MCP tool arguments -- Tool arguments were cast with as string/as number without validation. Added Zod validation schemas for the 10 most critical tools (navigate, click, type, fill, press, select, hover, element, activate_page, extract). Invalid arguments now throw descriptive errors before reaching the BAP client.

  • B3: Fix token not refreshed on reconnect -- The auth token was baked into the WebSocket URL at construction time and never updated on reconnect. Refactored WebSocketTransport to store the base URL and token separately, rebuilding the URL with the current token on each connect() call. Added updateToken() method to both WebSocketTransport and BAPClient.

  • B4: Replace require() in ESM modules -- require('crypto') and require('fs') were used inline in server-playwright/server.ts (an ESM module). Replaced with top-level import { timingSafeEqual } from "node:crypto" and import fs from "node:fs".

Changes

File What changed
packages/server-playwright/src/server.ts Removed ~120 lines of duplicated authorization code, import from protocol instead. Replaced inline require() with top-level ESM imports.
packages/mcp/src/index.ts Added Zod validation schemas and validateArgs() helper. Applied validation to 10 tool handlers.
packages/client/src/index.ts Refactored WebSocketTransport to store token separately from URL. Added updateToken() to both transport and client.

Test plan

  • pnpm build -- all 7 packages build successfully
  • pnpm typecheck -- all packages pass type checking
  • pnpm test -- all 420 tests pass (163 protocol + 78 client + 66 mcp + 43 server-playwright + 70 cli)
  • Manual: verify MCP tools reject invalid arguments (e.g., empty selector, malformed URL)
  • Manual: verify updateToken() works across reconnection

B1: Remove duplicated authorization code (BAPScope, ScopeProfiles,
MethodScopes, hasScope, parseScopes, createAuthorizationError) from
server-playwright and import from @browseragentprotocol/protocol.

B2: Add Zod input validation schemas for the 10 most critical MCP tool
arguments (navigate, click, type, fill, press, select, hover, element,
activate_page, extract) to catch invalid inputs before they reach the
BAP client.

B3: Fix token not refreshed on reconnect in BAPClient. Store the token
separately from the URL in WebSocketTransport, reconstruct the URL with
the current token on each connect/reconnect, and add updateToken()
method to both WebSocketTransport and BAPClient.

B4: Replace inline require('crypto') and require('fs') in ESM module
server-playwright/server.ts with top-level imports using node: protocol.
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.

1 participant