| 257 | * ``` |
| 258 | */ |
| 259 | export class MCPClientWrapper { |
| 260 | private client: Client | null = null; |
| 261 | |
| 262 | /** |
| 263 | * Initializes the Chrome DevTools MCP server and establishes connection. |
| 264 | * |
| 265 | * @param options - Configuration options |
| 266 | * @param options.headless - Run browser in headless mode (default: true) |
| 267 | * @returns This wrapper instance for chaining |
| 268 | * @throws Error if connection fails |
| 269 | */ |
| 270 | async connect(options?: { headless?: boolean }): Promise<this> { |
| 271 | const headless = options?.headless ?? true; |
| 272 | |
| 273 | cli.info("Starting Chrome DevTools MCP server..."); |
| 274 | |
| 275 | const transport = new StdioClientTransport({ |
| 276 | command: "npx", |
| 277 | args: [ |
| 278 | "@mcp-b/chrome-devtools-mcp@latest", |
| 279 | ...(headless ? ["--headless"] : []), |
| 280 | ], |
| 281 | }); |
| 282 | |
| 283 | this.client = new Client({ |
| 284 | name: "benchmark-client", |
| 285 | version: "1.0.0", |
| 286 | }); |
| 287 | |
| 288 | await this.client.connect(transport); |
| 289 | cli.success("MCP client connected"); |
| 290 | |
| 291 | const tools = await this.client.listTools(); |
| 292 | cli.info(`Available MCP tools: ${tools.tools.length}`); |
| 293 | |
| 294 | // Set viewport to 14-inch MacBook size for realistic screenshots |
| 295 | await this.callTool("resize_page", { width: 1512, height: 982 }); |
| 296 | cli.info("Browser viewport set to 1512x982"); |
| 297 | |
| 298 | return this; |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * Executes an MCP tool call with type-safe arguments. |
| 303 | * |
| 304 | * @param name - Tool name to call |
| 305 | * @param args - Arguments to pass to the tool |
| 306 | * @returns The tool result |
| 307 | * @throws Error if client is not connected |
| 308 | */ |
| 309 | async callTool( |
| 310 | name: string, |
| 311 | args: Record<string, unknown> = {} |
| 312 | ): Promise<CompatibilityCallToolResult> { |
| 313 | if (!this.client) { |
| 314 | throw new Error("MCP client not initialized. Call connect() first."); |
| 315 | } |
| 316 | return this.client.callTool({ name, arguments: args }); |
nothing calls this directly
no outgoing calls
no test coverage detected