Skip to content

Commit 617f562

Browse files
Revert "[tools] Add compact parameter to reduce response verbosity and token …" (#83)
This reverts commit f3f439b.
1 parent 4f92df6 commit 617f562

File tree

9 files changed

+9
-484
lines changed

9 files changed

+9
-484
lines changed

src/tools/category-search-tool/CategorySearchTool.input.schema.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,5 @@ export const CategorySearchInputSchema = z.object({
4444
.default('formatted_text')
4545
.describe(
4646
'Output format: "json_string" returns raw GeoJSON data as a JSON string that can be parsed; "formatted_text" returns human-readable text with place names, addresses, and coordinates. Both return as text content but json_string contains parseable JSON data while formatted_text is for display.'
47-
),
48-
compact: z
49-
.boolean()
50-
.optional()
51-
.default(true)
52-
.describe(
53-
'When true (default), returns simplified GeoJSON with only essential fields (name, address, coordinates, categories, brand). When false, returns full verbose Mapbox API response with all metadata. Only applies to structured content output.'
5447
)
5548
});

src/tools/category-search-tool/CategorySearchTool.ts

Lines changed: 3 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -93,62 +93,6 @@ export class CategorySearchTool extends MapboxApiBasedTool<
9393
return results.join('\n\n');
9494
}
9595

96-
/**
97-
* Simplify GeoJSON response to only essential fields
98-
* Removes verbose nested context, attribution, and metadata while keeping valid GeoJSON structure
99-
*/
100-
private compactGeoJsonResponse(
101-
geoJsonResponse: MapboxFeatureCollection
102-
): Record<string, unknown> {
103-
return {
104-
type: 'FeatureCollection',
105-
features: geoJsonResponse.features.map((feature) => {
106-
const props = feature.properties || {};
107-
const context = (props.context || {}) as Record<string, any>;
108-
const geom = feature.geometry;
109-
110-
// Extract coordinates safely
111-
let coordinates: [number, number] | undefined;
112-
if (geom && geom.type === 'Point' && 'coordinates' in geom) {
113-
coordinates = geom.coordinates as [number, number];
114-
}
115-
116-
return {
117-
type: 'Feature',
118-
geometry: geom
119-
? {
120-
type: geom.type,
121-
coordinates:
122-
'coordinates' in geom ? geom.coordinates : undefined
123-
}
124-
: null,
125-
properties: {
126-
name: props.name,
127-
full_address: props.full_address,
128-
place_formatted: props.place_formatted,
129-
feature_type: props.feature_type,
130-
coordinates: coordinates
131-
? {
132-
longitude: coordinates[0],
133-
latitude: coordinates[1]
134-
}
135-
: undefined,
136-
poi_category: props.poi_category,
137-
brand: props.brand,
138-
maki: props.maki,
139-
address: context.address?.name,
140-
street: context.street?.name,
141-
postcode: context.postcode?.name,
142-
place: context.place?.name,
143-
district: context.district?.name,
144-
region: context.region?.name,
145-
country: context.country?.name
146-
}
147-
};
148-
})
149-
};
150-
}
151-
15296
protected async execute(
15397
input: z.infer<typeof CategorySearchInputSchema>,
15498
accessToken: string
@@ -231,23 +175,16 @@ export class CategorySearchTool extends MapboxApiBasedTool<
231175
data = rawData as MapboxFeatureCollection;
232176
}
233177

234-
// Determine which structured content to return
235-
const structuredContent = input.compact
236-
? this.compactGeoJsonResponse(data)
237-
: (data as unknown as Record<string, unknown>);
238-
239178
if (input.format === 'json_string') {
240179
return {
241-
content: [
242-
{ type: 'text', text: JSON.stringify(structuredContent, null, 2) }
243-
],
244-
structuredContent,
180+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
181+
structuredContent: data as unknown as Record<string, unknown>,
245182
isError: false
246183
};
247184
} else {
248185
return {
249186
content: [{ type: 'text', text: this.formatGeoJsonToText(data) }],
250-
structuredContent,
187+
structuredContent: data as unknown as Record<string, unknown>,
251188
isError: false
252189
};
253190
}

src/tools/reverse-geocode-tool/ReverseGeocodeTool.input.schema.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,5 @@ export const ReverseGeocodeInputSchema = z.object({
5656
.default('formatted_text')
5757
.describe(
5858
'Output format: "json_string" returns raw GeoJSON data as a JSON string that can be parsed; "formatted_text" returns human-readable text with place names, addresses, and coordinates. Both return as text content but json_string contains parseable JSON data while formatted_text is for display.'
59-
),
60-
compact: z
61-
.boolean()
62-
.optional()
63-
.default(true)
64-
.describe(
65-
'When true (default), returns simplified GeoJSON with only essential fields (name, address, coordinates, location hierarchy). When false, returns full verbose Mapbox API response with all metadata. Only applies to structured content output.'
6659
)
6760
});

src/tools/reverse-geocode-tool/ReverseGeocodeTool.ts

Lines changed: 3 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -86,58 +86,6 @@ export class ReverseGeocodeTool extends MapboxApiBasedTool<
8686
return results.join('\n\n');
8787
}
8888

89-
/**
90-
* Simplify GeoJSON response to only essential fields
91-
* Removes verbose nested context and attribution while keeping valid GeoJSON structure
92-
*/
93-
private compactGeoJsonResponse(
94-
geoJsonResponse: MapboxFeatureCollection
95-
): Record<string, unknown> {
96-
return {
97-
type: 'FeatureCollection',
98-
features: geoJsonResponse.features.map((feature) => {
99-
const props = feature.properties || {};
100-
const context = (props.context || {}) as Record<string, any>;
101-
const geom = feature.geometry;
102-
103-
// Extract coordinates safely
104-
let coordinates: [number, number] | undefined;
105-
if (geom && geom.type === 'Point' && 'coordinates' in geom) {
106-
coordinates = geom.coordinates as [number, number];
107-
}
108-
109-
return {
110-
type: 'Feature',
111-
geometry: geom
112-
? {
113-
type: geom.type,
114-
coordinates:
115-
'coordinates' in geom ? geom.coordinates : undefined
116-
}
117-
: null,
118-
properties: {
119-
name: props.name,
120-
full_address: props.full_address,
121-
place_formatted: props.place_formatted,
122-
feature_type: props.feature_type,
123-
coordinates: coordinates
124-
? {
125-
longitude: coordinates[0],
126-
latitude: coordinates[1]
127-
}
128-
: undefined,
129-
address: context.address?.name,
130-
postcode: context.postcode?.name,
131-
place: context.place?.name,
132-
district: context.district?.name,
133-
region: context.region?.name,
134-
country: context.country?.name
135-
}
136-
};
137-
})
138-
};
139-
}
140-
14189
protected async execute(
14290
input: z.infer<typeof ReverseGeocodeInputSchema>,
14391
accessToken: string
@@ -223,23 +171,16 @@ export class ReverseGeocodeTool extends MapboxApiBasedTool<
223171
};
224172
}
225173

226-
// Determine which structured content to return
227-
const structuredContent = input.compact
228-
? this.compactGeoJsonResponse(data)
229-
: (data as unknown as Record<string, unknown>);
230-
231174
if (input.format === 'json_string') {
232175
return {
233-
content: [
234-
{ type: 'text', text: JSON.stringify(structuredContent, null, 2) }
235-
],
236-
structuredContent,
176+
content: [{ type: 'text', text: JSON.stringify(data, null, 2) }],
177+
structuredContent: data as unknown as Record<string, unknown>,
237178
isError: false
238179
};
239180
} else {
240181
return {
241182
content: [{ type: 'text', text: this.formatGeoJsonToText(data) }],
242-
structuredContent,
183+
structuredContent: data as unknown as Record<string, unknown>,
243184
isError: false
244185
};
245186
}

src/tools/search-and-geocode-tool/SearchAndGeocodeTool.input.schema.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,5 @@ export const SearchAndGeocodeInputSchema = z.object({
6161
longitude: z.number().min(-180).max(180),
6262
latitude: z.number().min(-90).max(90)
6363
})
64-
.optional(),
65-
compact: z
66-
.boolean()
6764
.optional()
68-
.default(true)
69-
.describe(
70-
'When true (default), returns simplified GeoJSON with only essential fields (name, address, coordinates, categories, brand). When false, returns full verbose Mapbox API response with all metadata. Only applies to structured content output.'
71-
)
7265
});

src/tools/search-and-geocode-tool/SearchAndGeocodeTool.ts

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -96,62 +96,6 @@ export class SearchAndGeocodeTool extends MapboxApiBasedTool<
9696
return results.join('\n\n');
9797
}
9898

99-
/**
100-
* Simplify GeoJSON response to only essential fields
101-
* Removes verbose nested context, attribution, and metadata while keeping valid GeoJSON structure
102-
*/
103-
private compactGeoJsonResponse(
104-
geoJsonResponse: MapboxFeatureCollection
105-
): Record<string, unknown> {
106-
return {
107-
type: 'FeatureCollection',
108-
features: geoJsonResponse.features.map((feature) => {
109-
const props = feature.properties || {};
110-
const context = (props.context || {}) as Record<string, any>;
111-
const geom = feature.geometry;
112-
113-
// Extract coordinates safely
114-
let coordinates: [number, number] | undefined;
115-
if (geom && geom.type === 'Point' && 'coordinates' in geom) {
116-
coordinates = geom.coordinates as [number, number];
117-
}
118-
119-
return {
120-
type: 'Feature',
121-
geometry: geom
122-
? {
123-
type: geom.type,
124-
coordinates:
125-
'coordinates' in geom ? geom.coordinates : undefined
126-
}
127-
: null,
128-
properties: {
129-
name: props.name,
130-
full_address: props.full_address,
131-
place_formatted: props.place_formatted,
132-
feature_type: props.feature_type,
133-
coordinates: coordinates
134-
? {
135-
longitude: coordinates[0],
136-
latitude: coordinates[1]
137-
}
138-
: undefined,
139-
poi_category: props.poi_category,
140-
brand: props.brand,
141-
maki: props.maki,
142-
address: context.address?.name,
143-
street: context.street?.name,
144-
postcode: context.postcode?.name,
145-
place: context.place?.name,
146-
district: context.district?.name,
147-
region: context.region?.name,
148-
country: context.country?.name
149-
}
150-
};
151-
})
152-
};
153-
}
154-
15599
protected async execute(
156100
input: z.infer<typeof SearchAndGeocodeInputSchema>,
157101
accessToken: string
@@ -267,19 +211,14 @@ export class SearchAndGeocodeTool extends MapboxApiBasedTool<
267211
`SearchAndGeocodeTool: Successfully completed search, found ${data.features?.length || 0} results`
268212
);
269213

270-
// Determine which structured content to return
271-
const structuredContent = input.compact
272-
? this.compactGeoJsonResponse(data as MapboxFeatureCollection)
273-
: (data as unknown as Record<string, unknown>);
274-
275214
return {
276215
content: [
277216
{
278217
type: 'text',
279218
text: this.formatGeoJsonToText(data as MapboxFeatureCollection)
280219
}
281220
],
282-
structuredContent,
221+
structuredContent: data,
283222
isError: false
284223
};
285224
}

0 commit comments

Comments
 (0)