File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 11import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js" ;
22import { z } from "zod" ;
33import { createKernelClient , type KernelClient } from "@/lib/mcp/kernel-client" ;
4+ import { textResponse , toolErrorResponse } from "@/lib/mcp/responses" ;
45
56type 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-
4639function 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 ) ;
You can’t perform that action at this time.
0 commit comments