Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/schemas/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,14 @@ export const bboxSchema = z.object({
maxLongitude: z.number().min(-180).max(180),
maxLatitude: z.number().min(-90).max(90)
});

/**
* Zod schema for Mapbox routing profiles.
* Uses the fully-qualified format (e.g., 'mapbox/driving-traffic').
*/
export const profileSchema = z.enum([
'mapbox/driving-traffic',
'mapbox/driving',
'mapbox/walking',
'mapbox/cycling'
]);
15 changes: 7 additions & 8 deletions src/tools/directions-tool/DirectionsTool.input.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

import { z } from 'zod';
import { coordinateSchema } from '../../schemas/shared.js';
import { coordinateSchema, profileSchema } from '../../schemas/shared.js';

/**
* Validates ISO 8601 date-time formats used by Mapbox Directions API
Expand Down Expand Up @@ -127,16 +127,15 @@ export const DirectionsInputSchema = z.object({
'Must include at least 2 coordinate pairs (starting and ending points). ' +
'Up to 25 coordinates total are supported.'
),
routing_profile: z
.enum(['driving-traffic', 'driving', 'walking', 'cycling'])
routing_profile: profileSchema
.optional()
.default('driving-traffic')
.default('mapbox/driving-traffic')
.describe(
'Routing profile for different modes of transport. Options: \n' +
'- driving-traffic (default): automotive with current traffic conditions\n' +
'- driving: automotive based on typical traffic\n' +
'- walking: pedestrian/hiking\n' +
'- cycling: bicycle'
'- mapbox/driving-traffic (default): automotive with current traffic conditions\n' +
'- mapbox/driving: automotive based on typical traffic\n' +
'- mapbox/walking: pedestrian/hiking\n' +
'- mapbox/cycling: bicycle'
),
geometries: z
.enum(['none', 'geojson'])
Expand Down
14 changes: 7 additions & 7 deletions src/tools/directions-tool/DirectionsTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export class DirectionsTool extends MapboxApiBasedTool<
];

const isDrivingProfile =
input.routing_profile === 'driving-traffic' ||
input.routing_profile === 'driving';
input.routing_profile === 'mapbox/driving-traffic' ||
input.routing_profile === 'mapbox/driving';
const items = input.exclude.split(',').map((item) => item.trim());

for (const item of items) {
Expand Down Expand Up @@ -112,8 +112,8 @@ export class DirectionsTool extends MapboxApiBasedTool<
}

const isDrivingProfile =
input.routing_profile === 'driving-traffic' ||
input.routing_profile === 'driving';
input.routing_profile === 'mapbox/driving-traffic' ||
input.routing_profile === 'mapbox/driving';

// Validate depart_at is only used with driving profiles
if (input.depart_at && !isDrivingProfile) {
Expand All @@ -129,7 +129,7 @@ export class DirectionsTool extends MapboxApiBasedTool<
}

// Validate arrive_by is only used with driving profile (not driving-traffic)
if (input.arrive_by && input.routing_profile !== 'driving') {
if (input.arrive_by && input.routing_profile !== 'mapbox/driving') {
return {
content: [
{
Expand Down Expand Up @@ -187,7 +187,7 @@ export class DirectionsTool extends MapboxApiBasedTool<
queryParams.append('alternatives', input.alternatives.toString());

// Add annotations parameter
if (input.routing_profile === 'driving-traffic') {
if (input.routing_profile === 'mapbox/driving-traffic') {
// congestion is available only when driving
queryParams.append('annotations', 'distance,congestion,speed');
} else {
Expand Down Expand Up @@ -236,7 +236,7 @@ export class DirectionsTool extends MapboxApiBasedTool<
queryString += `&exclude=${excludeEncoded}`;
}

const url = `${MapboxApiBasedTool.mapboxApiEndpoint}directions/v5/mapbox/${input.routing_profile}/${encodedCoords}?${queryString}`;
const url = `${MapboxApiBasedTool.mapboxApiEndpoint}directions/v5/${input.routing_profile}/${encodedCoords}?${queryString}`;

const response = await this.httpRequest(url);

Expand Down
18 changes: 8 additions & 10 deletions src/tools/directions-tool/cleanResponseData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,10 @@ interface RawDirectionsResponse {
}

// Cleaned response types (after cleaning)
interface CleanedRoute
extends Omit<
RawRoute,
'legs' | 'weight_name' | 'weight' | 'duration_typical' | 'weight_typical'
> {
interface CleanedRoute extends Omit<
RawRoute,
'legs' | 'weight_name' | 'weight' | 'duration_typical' | 'weight_typical'
> {
leg_summaries?: string[];
intersecting_admins?: string[];
notifications_summary?: string[];
Expand Down Expand Up @@ -116,11 +115,10 @@ interface CleanedWaypoint extends Omit<RawWaypoint, 'location' | 'distance'> {
snap_distance?: number;
}

interface CleanedDirectionsResponse
extends Omit<
RawDirectionsResponse,
'uuid' | 'code' | 'waypoints' | 'routes'
> {
interface CleanedDirectionsResponse extends Omit<
RawDirectionsResponse,
'uuid' | 'code' | 'waypoints' | 'routes'
> {
waypoints?: CleanedWaypoint[];
routes?: CleanedRoute[];
}
Expand Down
18 changes: 8 additions & 10 deletions src/tools/matrix-tool/MatrixTool.input.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

import { z } from 'zod';
import { coordinateSchema } from '../../schemas/shared.js';
import { coordinateSchema, profileSchema } from '../../schemas/shared.js';

export const MatrixInputSchema = z.object({
coordinates: z
Expand All @@ -17,15 +17,13 @@ export const MatrixInputSchema = z.object({
'Must include at least 2 coordinate pairs. ' +
'Up to 25 coordinates total are supported for most profiles (10 for driving-traffic).'
),
profile: z
.enum(['driving-traffic', 'driving', 'walking', 'cycling'])
.describe(
'Routing profile for different modes of transport. Options: \n' +
'- driving-traffic: automotive with current traffic conditions (limited to 10 coordinates)\n' +
'- driving: automotive based on typical traffic\n' +
'- walking: pedestrian/hiking\n' +
'- cycling: bicycle'
),
profile: profileSchema.describe(
'Routing profile for different modes of transport. Options: \n' +
'- mapbox/driving-traffic (default): automotive with current traffic conditions (limited to 10 coordinates)\n' +
'- mapbox/driving: automotive based on typical traffic\n' +
'- mapbox/walking: pedestrian/hiking\n' +
'- mapbox/cycling: bicycle'
),
annotations: z
.enum(['duration', 'distance', 'duration,distance', 'distance,duration'])
.optional()
Expand Down
7 changes: 5 additions & 2 deletions src/tools/matrix-tool/MatrixTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ export class MatrixTool extends MapboxApiBasedTool<
accessToken: string
): Promise<CallToolResult> {
// Validate input based on profile type
if (input.profile === 'driving-traffic' && input.coordinates.length > 10) {
if (
input.profile === 'mapbox/driving-traffic' &&
input.coordinates.length > 10
) {
return {
content: [
{
Expand Down Expand Up @@ -273,7 +276,7 @@ export class MatrixTool extends MapboxApiBasedTool<
}

// Construct the URL for the Matrix API request
const url = `${MapboxApiBasedTool.mapboxApiEndpoint}directions-matrix/v1/mapbox/${input.profile}/${joined}?${queryParams.toString()}`;
const url = `${MapboxApiBasedTool.mapboxApiEndpoint}directions-matrix/v1/${input.profile}/${joined}?${queryParams.toString()}`;

// Make the request
const response = await this.httpRequest(url);
Expand Down
5 changes: 2 additions & 3 deletions src/tools/resource-reader-tool/ResourceReaderTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,8 @@ export class ResourceReaderTool extends BaseTool<
* Lists all available resource URIs for error messages
*/
private async listAvailableResources(): Promise<string> {
const { getAllResources } = await import(
'../../resources/resourceRegistry.js'
);
const { getAllResources } =
await import('../../resources/resourceRegistry.js');
const resources = getAllResources();
return resources.map((r: { uri: string }) => r.uri).join(', ');
}
Expand Down
5 changes: 2 additions & 3 deletions src/utils/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,8 @@ export async function initializeTracing(): Promise<void> {

// Console exporter for development (avoid in stdio transport)
if (process.env.OTEL_EXPORTER_CONSOLE_ENABLED === 'true') {
const { ConsoleSpanExporter } = await import(
'@opentelemetry/sdk-trace-base'
);
const { ConsoleSpanExporter } =
await import('@opentelemetry/sdk-trace-base');
exporters.push(new ConsoleSpanExporter());
}

Expand Down
Loading