@@ -54,8 +54,11 @@ describe('StaticMapImageTool', () => {
5454 } ) ;
5555
5656 expect ( result . isError ) . toBe ( false ) ;
57- expect ( result . content ) . toHaveLength ( 1 ) ;
58- expect ( result . content [ 0 ] ) . toMatchObject ( {
57+ expect ( result . content ) . toHaveLength ( 2 ) ; // text + image
58+ // First content should be text description
59+ expect ( result . content [ 0 ] . type ) . toBe ( 'text' ) ;
60+ // Second content should be image
61+ expect ( result . content [ 1 ] ) . toMatchObject ( {
5962 type : 'image' ,
6063 data : mockImageBuffer . toString ( 'base64' ) ,
6164 mimeType : 'image/jpeg' // satellite is a raster style
@@ -70,6 +73,98 @@ describe('StaticMapImageTool', () => {
7073 }
7174 } ) ;
7275
76+ it ( 'returns text content with map details as first item' , async ( ) => {
77+ // Disable MCP-UI for this test to focus on text + image
78+ const originalEnv = process . env . ENABLE_MCP_UI ;
79+ process . env . ENABLE_MCP_UI = 'false' ;
80+
81+ try {
82+ const mockImageBuffer = Buffer . from ( 'fake-image-data' ) ;
83+ const mockArrayBuffer = mockImageBuffer . buffer . slice (
84+ mockImageBuffer . byteOffset ,
85+ mockImageBuffer . byteOffset + mockImageBuffer . byteLength
86+ ) ;
87+
88+ const { httpRequest } = setupHttpRequest ( {
89+ arrayBuffer : vi . fn ( ) . mockResolvedValue ( mockArrayBuffer )
90+ } ) ;
91+
92+ const result = await new StaticMapImageTool ( { httpRequest } ) . run ( {
93+ center : { longitude : - 74.006 , latitude : 40.7128 } ,
94+ zoom : 12 ,
95+ size : { width : 600 , height : 400 } ,
96+ style : 'mapbox/streets-v12'
97+ } ) ;
98+
99+ expect ( result . isError ) . toBe ( false ) ;
100+ expect ( result . content [ 0 ] . type ) . toBe ( 'text' ) ;
101+
102+ const textContent = result . content [ 0 ] as { type : 'text' ; text : string } ;
103+ expect ( textContent . text ) . toContain ( 'Static map image generated' ) ;
104+ expect ( textContent . text ) . toContain ( '40.7128' ) ; // latitude
105+ expect ( textContent . text ) . toContain ( '-74.006' ) ; // longitude
106+ expect ( textContent . text ) . toContain ( '12' ) ; // zoom
107+ expect ( textContent . text ) . toContain ( '600x400' ) ; // size
108+ expect ( textContent . text ) . toContain ( 'mapbox/streets-v12' ) ; // style
109+ } finally {
110+ if ( originalEnv !== undefined ) {
111+ process . env . ENABLE_MCP_UI = originalEnv ;
112+ } else {
113+ delete process . env . ENABLE_MCP_UI ;
114+ }
115+ }
116+ } ) ;
117+
118+ it ( 'text content includes overlay count when overlays present' , async ( ) => {
119+ const originalEnv = process . env . ENABLE_MCP_UI ;
120+ process . env . ENABLE_MCP_UI = 'false' ;
121+
122+ try {
123+ const mockImageBuffer = Buffer . from ( 'fake-image-data' ) ;
124+ const mockArrayBuffer = mockImageBuffer . buffer . slice (
125+ mockImageBuffer . byteOffset ,
126+ mockImageBuffer . byteOffset + mockImageBuffer . byteLength
127+ ) ;
128+
129+ const { httpRequest } = setupHttpRequest ( {
130+ arrayBuffer : vi . fn ( ) . mockResolvedValue ( mockArrayBuffer )
131+ } ) ;
132+
133+ const result = await new StaticMapImageTool ( { httpRequest } ) . run ( {
134+ center : { longitude : - 74.006 , latitude : 40.7128 } ,
135+ zoom : 12 ,
136+ size : { width : 600 , height : 400 } ,
137+ style : 'mapbox/streets-v12' ,
138+ overlays : [
139+ {
140+ type : 'marker' ,
141+ longitude : - 74.006 ,
142+ latitude : 40.7128 ,
143+ size : 'large' ,
144+ color : 'ff0000'
145+ } ,
146+ {
147+ type : 'marker' ,
148+ longitude : - 74.01 ,
149+ latitude : 40.71 ,
150+ size : 'small' ,
151+ color : '00ff00'
152+ }
153+ ]
154+ } ) ;
155+
156+ expect ( result . isError ) . toBe ( false ) ;
157+ const textContent = result . content [ 0 ] as { type : 'text' ; text : string } ;
158+ expect ( textContent . text ) . toContain ( 'Overlays: 2' ) ;
159+ } finally {
160+ if ( originalEnv !== undefined ) {
161+ process . env . ENABLE_MCP_UI = originalEnv ;
162+ } else {
163+ delete process . env . ENABLE_MCP_UI ;
164+ }
165+ }
166+ } ) ;
167+
73168 it ( 'constructs correct Mapbox Static API URL' , async ( ) => {
74169 const { httpRequest, mockHttpRequest } = setupHttpRequest ( ) ;
75170
@@ -573,11 +668,12 @@ describe('StaticMapImageTool', () => {
573668 } ) ;
574669
575670 expect ( result . isError ) . toBe ( false ) ;
576- expect ( result . content ) . toHaveLength ( 2 ) ; // image + UIResource
577- expect ( result . content [ 0 ] . type ) . toBe ( 'image' ) ;
578- expect ( result . content [ 1 ] . type ) . toBe ( 'resource' ) ;
579- if ( result . content [ 1 ] . type === 'resource' ) {
580- expect ( result . content [ 1 ] . resource . uri ) . toMatch (
671+ expect ( result . content ) . toHaveLength ( 3 ) ; // text + image + UIResource
672+ expect ( result . content [ 0 ] . type ) . toBe ( 'text' ) ;
673+ expect ( result . content [ 1 ] . type ) . toBe ( 'image' ) ;
674+ expect ( result . content [ 2 ] . type ) . toBe ( 'resource' ) ;
675+ if ( result . content [ 2 ] . type === 'resource' ) {
676+ expect ( result . content [ 2 ] . resource . uri ) . toMatch (
581677 / ^ u i : \/ \/ m a p b o x \/ s t a t i c - m a p \/ /
582678 ) ;
583679 }
@@ -608,8 +704,9 @@ describe('StaticMapImageTool', () => {
608704 } ) ;
609705
610706 expect ( result . isError ) . toBe ( false ) ;
611- expect ( result . content ) . toHaveLength ( 1 ) ; // image only, no UIResource
612- expect ( result . content [ 0 ] . type ) . toBe ( 'image' ) ;
707+ expect ( result . content ) . toHaveLength ( 2 ) ; // text + image, no UIResource
708+ expect ( result . content [ 0 ] . type ) . toBe ( 'text' ) ;
709+ expect ( result . content [ 1 ] . type ) . toBe ( 'image' ) ;
613710 } finally {
614711 // Restore environment variable
615712 if ( originalEnv !== undefined ) {
@@ -640,13 +737,14 @@ describe('StaticMapImageTool', () => {
640737 } ) ;
641738
642739 expect ( result . isError ) . toBe ( false ) ;
643- if ( result . content [ 1 ] ?. type === 'resource' ) {
644- expect ( result . content [ 1 ] . resource . uri ) . toContain (
740+ // UIResource is now at index 2 (after text and image)
741+ if ( result . content [ 2 ] ?. type === 'resource' ) {
742+ expect ( result . content [ 2 ] . resource . uri ) . toContain (
645743 '-122.4194,37.7749,13'
646744 ) ;
647745 // Check that UIMetadata has preferred dimensions
648- if ( 'uiMetadata' in result . content [ 1 ] . resource ) {
649- const metadata = result . content [ 1 ] . resource . uiMetadata as Record <
746+ if ( 'uiMetadata' in result . content [ 2 ] . resource ) {
747+ const metadata = result . content [ 2 ] . resource . uiMetadata as Record <
650748 string ,
651749 unknown
652750 > ;
0 commit comments