@@ -492,17 +492,22 @@ const registerPreviewSnapshot = Effect.fn("McpHttpServer.registerPreviewSnapshot
492492 Effect . gen ( function * ( ) {
493493 const snapshot = encodedResult as SnapshotMetadata & {
494494 readonly url : string ;
495- readonly screenshot : {
495+ readonly screenshot ? : {
496496 readonly mimeType : "image/png" ;
497497 readonly data : string ;
498498 readonly width : number ;
499499 readonly height : number ;
500500 } ;
501501 } ;
502502 const { screenshot, ...page } = snapshot ;
503- const png = new Uint8Array ( Buffer . from ( screenshot . data , "base64" ) ) ;
503+ const png =
504+ screenshot === undefined
505+ ? undefined
506+ : new Uint8Array ( Buffer . from ( screenshot . data , "base64" ) ) ;
504507 const screenshotPath =
505- payload ?. save === true ? yield * saveScreenshot ( snapshot . url , png ) : undefined ;
508+ payload ?. save === true && png !== undefined
509+ ? yield * saveScreenshot ( snapshot . url , png )
510+ : undefined ;
506511 if ( screenshotPath !== undefined && payload ?. includeImage === false ) {
507512 // The agent only wants a file to show the user. The url keeps the site icon on the tool row.
508513 const saved = {
@@ -517,11 +522,15 @@ const registerPreviewSnapshot = Effect.fn("McpHttpServer.registerPreviewSnapshot
517522 }
518523 const metadata = {
519524 ...page ,
520- screenshot : {
521- mimeType : screenshot . mimeType ,
522- width : screenshot . width ,
523- height : screenshot . height ,
524- } ,
525+ ...( screenshot === undefined
526+ ? { }
527+ : {
528+ screenshot : {
529+ mimeType : screenshot . mimeType ,
530+ width : screenshot . width ,
531+ height : screenshot . height ,
532+ } ,
533+ } ) ,
525534 ...( screenshotPath === undefined ? { } : { screenshotPath } ) ,
526535 } ;
527536 const bounded = boundSnapshotMetadata ( metadata ) ;
@@ -548,7 +557,9 @@ const registerPreviewSnapshot = Effect.fn("McpHttpServer.registerPreviewSnapshot
548557 text : `Snapshot text was bounded. Omitted: ${ bounded . omitted . join ( "; " ) } .` ,
549558 } ,
550559 ] ) ,
551- ...( payload ?. includeImage === false
560+ ...( payload ?. includeImage === false ||
561+ screenshot === undefined ||
562+ png === undefined
552563 ? [ ]
553564 : [ { type : "image" as const , data : png , mimeType : screenshot . mimeType } ] ) ,
554565 ] ,
0 commit comments