Skip to content

Commit 18d20ac

Browse files
committed
Preserve browser MCP error context
1 parent a7a7746 commit 18d20ac

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

src/lib/mcp/responses.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export function textResponse(text: string) {
2+
return { content: [{ type: "text" as const, text }] };
3+
}
4+
5+
function errorMessage(error: unknown) {
6+
return error instanceof Error ? error.message : String(error);
7+
}
8+
9+
export function toolErrorResponse(
10+
toolName: string,
11+
action: string,
12+
error: unknown,
13+
) {
14+
return textResponse(
15+
`Error in ${toolName} (${action}): ${errorMessage(error)}`,
16+
);
17+
}

src/lib/mcp/tools/browsers.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
22
import { z } from "zod";
33
import { createKernelClient, type KernelClient } from "@/lib/mcp/kernel-client";
4+
import { textResponse, toolErrorResponse } from "@/lib/mcp/responses";
45

56
type BrowserCreateParams = NonNullable<
67
Parameters<KernelClient["browsers"]["create"]>[0]
@@ -35,14 +36,6 @@ const telemetryCategories = [
3536
["telemetry_interaction", "interaction"],
3637
] as const;
3738

38-
function textResponse(text: string) {
39-
return { content: [{ type: "text" as const, text }] };
40-
}
41-
42-
function errorMessage(error: unknown) {
43-
return error instanceof Error ? error.message : String(error);
44-
}
45-
4639
function buildProfile(params: ProfileParams): BrowserCreateParams["profile"] {
4740
if (
4841
params.save_profile_changes !== undefined &&
@@ -529,7 +522,7 @@ export function registerBrowserCapabilities(server: McpServer) {
529522
}
530523
}
531524
} catch (error) {
532-
return textResponse(`Error: ${errorMessage(error)}`);
525+
return toolErrorResponse("manage_browsers", params.action, error);
533526
}
534527
},
535528
);

0 commit comments

Comments
 (0)