File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -217,6 +217,18 @@ export abstract class MapboxApiBasedTool<
217217 } ;
218218 }
219219
220+ protected handleValidationError ( error : unknown ) : CallToolResult {
221+ return {
222+ isError : true ,
223+ content : [
224+ {
225+ type : 'text' ,
226+ text : `Unexpected API response format from Mapbox API: ${ error instanceof Error ? error . message : 'Unknown validation error' } `
227+ }
228+ ]
229+ } ;
230+ }
231+
220232 /**
221233 * Tool logic to be implemented by subclasses.
222234 * Must return a complete OutputSchema with content and optional structured content.
Original file line number Diff line number Diff line change @@ -95,16 +95,8 @@ export class CreateTokenTool extends MapboxApiBasedTool<
9595 let data ;
9696 try {
9797 data = CreateTokenOutputSchema . parse ( rawData ) ;
98- } catch {
99- return {
100- isError : true ,
101- content : [
102- {
103- type : 'text' ,
104- text : 'Unexpected API response format from Mapbox API'
105- }
106- ]
107- } ;
98+ } catch ( validationError ) {
99+ return this . handleValidationError ( validationError ) ;
108100 }
109101
110102 this . log ( 'info' , `CreateTokenTool: Successfully created token` ) ;
Original file line number Diff line number Diff line change @@ -73,16 +73,8 @@ export class ListStylesTool extends MapboxApiBasedTool<
7373 let validatedData ;
7474 try {
7575 validatedData = StylesArraySchema . parse ( rawData ) ;
76- } catch {
77- return {
78- isError : true ,
79- content : [
80- {
81- type : 'text' ,
82- text : 'Unexpected API response format from Mapbox API'
83- }
84- ]
85- } ;
76+ } catch ( validationError ) {
77+ return this . handleValidationError ( validationError ) ;
8678 }
8779
8880 this . log ( 'info' , `ListStylesTool: Successfully listed styles` ) ;
Original file line number Diff line number Diff line change @@ -133,16 +133,8 @@ export class ListTokensTool extends MapboxApiBasedTool<
133133 let validatedTokens ;
134134 try {
135135 validatedTokens = TokenObjectSchema . array ( ) . parse ( tokens ) ;
136- } catch {
137- return {
138- isError : true ,
139- content : [
140- {
141- type : 'text' ,
142- text : 'Unexpected API response format from Mapbox API'
143- }
144- ]
145- } ;
136+ } catch ( validationError ) {
137+ return this . handleValidationError ( validationError ) ;
146138 }
147139
148140 allTokens . push ( ...validatedTokens ) ;
Original file line number Diff line number Diff line change @@ -57,16 +57,8 @@ export class RetrieveStyleTool extends MapboxApiBasedTool<
5757 let data : MapboxStyleOutput ;
5858 try {
5959 data = MapboxStyleOutputSchema . parse ( rawData ) ;
60- } catch {
61- return {
62- isError : true ,
63- content : [
64- {
65- type : 'text' ,
66- text : 'Unexpected API response format from Mapbox API'
67- }
68- ]
69- } ;
60+ } catch ( validationError ) {
61+ return this . handleValidationError ( validationError ) ;
7062 }
7163
7264 this . log (
Original file line number Diff line number Diff line change @@ -84,16 +84,8 @@ export class TilequeryTool extends MapboxApiBasedTool<
8484 let data : TilequeryResponse ;
8585 try {
8686 data = TilequeryResponseSchema . parse ( rawData ) ;
87- } catch {
88- return {
89- isError : true ,
90- content : [
91- {
92- type : 'text' ,
93- text : 'Unexpected API response format from Mapbox API'
94- }
95- ]
96- } ;
87+ } catch ( validationError ) {
88+ return this . handleValidationError ( validationError ) ;
9789 }
9890
9991 this . log (
Original file line number Diff line number Diff line change @@ -67,16 +67,8 @@ export class UpdateStyleTool extends MapboxApiBasedTool<
6767 let data : MapboxStyleOutput ;
6868 try {
6969 data = MapboxStyleOutputSchema . parse ( rawData ) ;
70- } catch {
71- return {
72- isError : true ,
73- content : [
74- {
75- type : 'text' ,
76- text : 'Unexpected API response format from Mapbox API'
77- }
78- ]
79- } ;
70+ } catch ( validationError ) {
71+ return this . handleValidationError ( validationError ) ;
8072 }
8173
8274 this . log ( 'info' , `UpdateStyleTool: Successfully updated style ${ data . id } ` ) ;
You can’t perform that action at this time.
0 commit comments