From 9a81322c1d5fd04ffd50f98869635925ad563828 Mon Sep 17 00:00:00 2001 From: Brett Lyman Date: Fri, 9 May 2025 16:33:15 -0400 Subject: [PATCH] fix: ensure browser_snapshot correctly handles undefined arguments This commit resolves an issue where mcp7_browser_snapshot would fail with an "invalid_type" error if called with no arguments. The root cause was 'undefined' being passed to Zod's parse method for a schema expecting an object. The fix ensures an empty object {} is provided if parameters are undefined. Additionally, the npm build script in package.json has been updated from 'tsc' to 'npx tsc' to improve build reliability, particularly in environments where TypeScript might not be globally installed or in the PATH. --- package.json | 2 +- src/context.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 9f85cb5c..25d3f462 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ }, "license": "Apache-2.0", "scripts": { - "build": "tsc", + "build": "npx tsc", "lint": "npm run update-readme && eslint . && tsc --noEmit", "update-readme": "node utils/update-readme.js", "watch": "tsc --watch", diff --git a/src/context.ts b/src/context.ts index 76f461ca..09770842 100644 --- a/src/context.ts +++ b/src/context.ts @@ -125,7 +125,8 @@ export class Context { async run(tool: Tool, params: Record | undefined) { // Tab management is done outside of the action() call. - const toolResult = await tool.handle(this, tool.schema.inputSchema.parse(params)); + const parsedParams = tool.schema.inputSchema.parse(params === undefined ? {} : params); + const toolResult = await tool.handle(this, parsedParams); const { code, action, waitForNetwork, captureSnapshot, resultOverride } = toolResult; const racingAction = action ? () => this._raceAgainstModalDialogs(action) : undefined;