Skip to content

Commit f84f873

Browse files
fix(puppeteer): return isError instead of internal error on navigation failure
puppeteer_navigate throws an unhandled Protocol error when given an invalid URL (e.g., empty string, malformed URL). The CDP error propagates as a JSON-RPC -32603 internal error, which prevents agents from detecting and recovering from the failure. Wrap page.goto() in a try/catch and return isError: true with the error message, matching the pattern used by puppeteer_screenshot and other tools in this server. Reproduction: mcp-assert audit --server "npx @modelcontextprotocol/server-puppeteer" # puppeteer_navigate: CRASH (internal error) Found with mcp-assert (https://github.com/blackwell-systems/mcp-assert)
1 parent e247123 commit f84f873

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

src/puppeteer/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,17 @@ async function handleToolCall(name: string, args: any): Promise<CallToolResult>
217217

218218
switch (name) {
219219
case "puppeteer_navigate":
220-
await page.goto(args.url);
220+
try {
221+
await page.goto(args.url);
222+
} catch (error) {
223+
return {
224+
content: [{
225+
type: "text",
226+
text: `Navigation failed: ${error instanceof Error ? error.message : String(error)}`,
227+
}],
228+
isError: true,
229+
};
230+
}
221231
return {
222232
content: [{
223233
type: "text",

0 commit comments

Comments
 (0)