Skip to content

Commit 3d7abbc

Browse files
[tools] Update tools to use structuredContent with schema
1 parent 7f423a3 commit 3d7abbc

File tree

3 files changed

+4
-50
lines changed

3 files changed

+4
-50
lines changed

src/tools/create-token-tool/CreateTokenTool.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,8 @@ export class CreateTokenTool extends MapboxApiBasedTool<
8484
body: JSON.stringify(body)
8585
});
8686

87-
if (!response.ok) {
88-
const errorBody = await response.text();
89-
this.log(
90-
'error',
91-
`CreateTokenTool: API Error - Status: ${response.status}, Body: ${errorBody}`
92-
);
93-
return {
94-
content: [
95-
{
96-
type: 'text',
97-
text: `Failed to create token: ${response.status} ${response.statusText}`
98-
}
99-
],
100-
isError: true
101-
};
87+
if (response.status !== 204) {
88+
return this.handleApiError(response, 'create token');
10289
}
10390

10491
const data = await response.json();

src/tools/list-tokens-tool/ListTokensTool.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,20 +118,7 @@ export class ListTokensTool extends MapboxApiBasedTool<
118118
});
119119

120120
if (!response.ok) {
121-
const errorBody = await response.text();
122-
this.log(
123-
'error',
124-
`ListTokensTool: API Error - Status: ${response.status}, Body: ${errorBody}`
125-
);
126-
return {
127-
isError: true,
128-
content: [
129-
{
130-
type: 'text',
131-
text: `Failed to list tokens: ${response.status} ${response.statusText}`
132-
}
133-
]
134-
};
121+
return this.handleApiError(response, 'list tokens');
135122
}
136123

137124
const data = await response.json();

src/tools/tilequery-tool/TilequeryTool.ts

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -74,27 +74,7 @@ export class TilequeryTool extends MapboxApiBasedTool<
7474
const response = await this.httpRequest(url.toString());
7575

7676
if (!response.ok) {
77-
const errorText = await response.text();
78-
throw new Error(
79-
`Tilequery request failed: ${response.status} ${response.statusText}. ${errorText}`
80-
);
81-
}
82-
83-
if (!response.ok) {
84-
const errorBody = await response.text();
85-
this.log(
86-
'error',
87-
`SearchAndGeocodeTool: API Error - Status: ${response.status}, Body: ${errorBody}`
88-
);
89-
return {
90-
content: [
91-
{
92-
type: 'text',
93-
text: `Failed to search: ${response.status} ${response.statusText}`
94-
}
95-
],
96-
isError: true
97-
};
77+
return this.handleApiError(response, 'query tile');
9878
}
9979

10080
const rawData = await response.json();

0 commit comments

Comments
 (0)