@@ -859,6 +859,126 @@ describe("useMcpToolTool", () => {
859859 ] )
860860 } )
861861
862+ it ( "should extract image data from embedded resource blobs" , async ( ) => {
863+ const block : ToolUse < "use_mcp_tool" > = {
864+ type : "tool_use" ,
865+ name : "use_mcp_tool" ,
866+ params : {
867+ server_name : "godot-server" ,
868+ tool_name : "game_screenshot" ,
869+ arguments : "{}" ,
870+ } ,
871+ nativeArgs : {
872+ server_name : "godot-server" ,
873+ tool_name : "game_screenshot" ,
874+ arguments : { } ,
875+ } ,
876+ partial : false ,
877+ }
878+
879+ mockAskApproval . mockResolvedValue ( true )
880+
881+ const mockToolResult = {
882+ content : [
883+ { type : "text" , text : "Screenshot captured: 1152x648" } ,
884+ {
885+ type : "resource" ,
886+ resource : {
887+ uri : "godot://screenshot/latest" ,
888+ mimeType : "image/png" ,
889+ blob : "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJ" ,
890+ } ,
891+ } ,
892+ ] ,
893+ isError : false ,
894+ }
895+
896+ mockProviderRef . deref . mockReturnValue ( {
897+ getMcpHub : ( ) => ( {
898+ callTool : vi . fn ( ) . mockResolvedValue ( mockToolResult ) ,
899+ getAllServers : vi . fn ( ) . mockReturnValue ( [
900+ {
901+ name : "godot-server" ,
902+ tools : [ { name : "game_screenshot" , description : "Capture screenshot" } ] ,
903+ } ,
904+ ] ) ,
905+ } ) ,
906+ postMessageToWebview : vi . fn ( ) ,
907+ } )
908+
909+ await useMcpToolTool . handle ( mockTask as Task , block , {
910+ askApproval : mockAskApproval ,
911+ handleError : mockHandleError ,
912+ pushToolResult : mockPushToolResult ,
913+ } )
914+
915+ expect ( mockTask . say ) . toHaveBeenCalledWith (
916+ "mcp_server_response" ,
917+ expect . stringContaining ( "Screenshot captured: 1152x648" ) ,
918+ [ "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJ" ] ,
919+ )
920+ expect ( mockPushToolResult ) . toHaveBeenCalledWith ( expect . stringContaining ( "with 1 image(s)" ) )
921+ } )
922+
923+ it ( "should not extract non-image resource blobs" , async ( ) => {
924+ const block : ToolUse < "use_mcp_tool" > = {
925+ type : "tool_use" ,
926+ name : "use_mcp_tool" ,
927+ params : {
928+ server_name : "godot-server" ,
929+ tool_name : "read_scene" ,
930+ arguments : "{}" ,
931+ } ,
932+ nativeArgs : {
933+ server_name : "godot-server" ,
934+ tool_name : "read_scene" ,
935+ arguments : { } ,
936+ } ,
937+ partial : false ,
938+ }
939+
940+ mockAskApproval . mockResolvedValue ( true )
941+
942+ const mockToolResult = {
943+ content : [
944+ {
945+ type : "resource" ,
946+ resource : {
947+ uri : "godot://scene/main" ,
948+ mimeType : "text/plain" ,
949+ blob : "c2NlbmUgZGF0YQ==" ,
950+ } ,
951+ } ,
952+ ] ,
953+ isError : false ,
954+ }
955+
956+ mockProviderRef . deref . mockReturnValue ( {
957+ getMcpHub : ( ) => ( {
958+ callTool : vi . fn ( ) . mockResolvedValue ( mockToolResult ) ,
959+ getAllServers : vi . fn ( ) . mockReturnValue ( [
960+ {
961+ name : "godot-server" ,
962+ tools : [ { name : "read_scene" , description : "Read scene" } ] ,
963+ } ,
964+ ] ) ,
965+ } ) ,
966+ postMessageToWebview : vi . fn ( ) ,
967+ } )
968+
969+ await useMcpToolTool . handle ( mockTask as Task , block , {
970+ askApproval : mockAskApproval ,
971+ handleError : mockHandleError ,
972+ pushToolResult : mockPushToolResult ,
973+ } )
974+
975+ expect ( mockTask . say ) . toHaveBeenCalledWith (
976+ "mcp_server_response" ,
977+ expect . stringContaining ( "godot://scene/main" ) ,
978+ [ ] ,
979+ )
980+ } )
981+
862982 it ( "should handle multiple images in response" , async ( ) => {
863983 const block : ToolUse = {
864984 type : "tool_use" ,
0 commit comments