Skip to main content
Glama

explore-segments

Find popular running and cycling segments within a specific geographical area to discover new routes and challenges.

Instructions

Searches for popular segments within a given geographical area.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
boundsYesThe geographical area to search, specified as a comma-separated string: south_west_lat,south_west_lng,north_east_lat,north_east_lng
activityTypeNoFilter segments by activity type (optional: 'running' or 'riding').
minCatNoFilter by minimum climb category (optional, 0-5). Requires riding activityType.
maxCatNoFilter by maximum climb category (optional, 0-5). Requires riding activityType.

Implementation Reference

  • The 'exploreSegments' constant defines the tool name, description, schema, and the 'execute' function which contains the tool's core logic for interacting with the Strava API.
    export const exploreSegments = {
        name: "explore-segments",
        description: "Searches for popular segments within a given geographical area.",
        inputSchema: ExploreSegmentsInputSchema,
        execute: async ({ bounds, activityType, minCat, maxCat }: ExploreSegmentsInput) => {
            const token = process.env.STRAVA_ACCESS_TOKEN;
    
            if (!token || token === 'YOUR_STRAVA_ACCESS_TOKEN_HERE') {
                console.error("Missing or placeholder STRAVA_ACCESS_TOKEN in .env");
                return {
                    content: [{ type: "text" as const, text: "❌ Configuration Error: STRAVA_ACCESS_TOKEN is missing or not set in the .env file." }],
                    isError: true,
                };
            }
            if ((minCat !== undefined || maxCat !== undefined) && activityType !== 'riding') {
                return {
                    content: [{ type: "text" as const, text: "❌ Input Error: Climb category filters (minCat, maxCat) require activityType to be 'riding'." }],
                    isError: true,
                };
            }
    
            try {
                console.error(`Exploring segments within bounds: ${bounds}...`);
                const athlete = await getAuthenticatedAthlete(token);
                const response: StravaExplorerResponse = await fetchExploreSegments(token, bounds, activityType, minCat, maxCat);
                console.error(`Found ${response.segments?.length ?? 0} segments.`);
    
                if (!response.segments || response.segments.length === 0) {
                    return { content: [{ type: "text" as const, text: " MNo segments found in the specified area with the given filters." }] };
                }
    
                const distanceFactor = athlete.measurement_preference === 'feet' ? 0.000621371 : 0.001;
                const distanceUnit = athlete.measurement_preference === 'feet' ? 'mi' : 'km';
                const elevationFactor = athlete.measurement_preference === 'feet' ? 3.28084 : 1;
                const elevationUnit = athlete.measurement_preference === 'feet' ? 'ft' : 'm';
    
                const segmentItems = response.segments.map(segment => {
                    const distance = (segment.distance * distanceFactor).toFixed(2);
                    const elevDifference = (segment.elev_difference * elevationFactor).toFixed(0);
                    const text = `
    πŸ—ΊοΈ **${segment.name}** (ID: ${segment.id})
       - Climb: Cat ${segment.climb_category_desc} (${segment.climb_category})
       - Distance: ${distance} ${distanceUnit}
       - Avg Grade: ${segment.avg_grade}%
       - Elev Difference: ${elevDifference} ${elevationUnit}
       - Starred: ${segment.starred ? 'Yes' : 'No'}
                    `.trim();
                    const item: { type: "text", text: string } = { type: "text" as const, text };
                    return item;
                });
    
                const responseText = `**Found Segments:**\n\n${segmentItems.map(item => item.text).join("\n---\n")}`;
    
                return { content: [{ type: "text" as const, text: responseText }] };
            } catch (error) {
                const errorMessage = error instanceof Error ? error.message : "An unknown error occurred";
                console.error("Error in explore-segments tool:", errorMessage);
                return {
                    content: [{ type: "text" as const, text: `❌ API Error: ${errorMessage}` }],
                    isError: true,
                };
            }
        }
    };
  • The 'ExploreSegmentsInputSchema' defines the Zod schema for the tool's input parameters, including validation for geographic bounds and activity type filters.
    const ExploreSegmentsInputSchema = z.object({
        bounds: z.string()
            .regex(/^-?\d+(\.\d+)?,-?\d+(\.\d+)?,-?\d+(\.\d+)?,-?\d+(\.\d+)?$/, "Bounds must be in the format: south_west_lat,south_west_lng,north_east_lat,north_east_lng")
            .describe("The geographical area to search, specified as a comma-separated string: south_west_lat,south_west_lng,north_east_lat,north_east_lng"),
        activityType: z.enum(["running", "riding"])
            .optional()
            .describe("Filter segments by activity type (optional: 'running' or 'riding')."),
        minCat: z.number().int().min(0).max(5).optional()
            .describe("Filter by minimum climb category (optional, 0-5). Requires riding activityType."),
        maxCat: z.number().int().min(0).max(5).optional()
            .describe("Filter by maximum climb category (optional, 0-5). Requires riding activityType."),
    });

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.2.1

TDQS

C2.9/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions searching for 'popular segments' but doesn't specify what makes a segment 'popular' (e.g., based on usage, ratings, or other metrics), nor does it describe the return format, pagination, or any rate limits or authentication requirements. This leaves significant gaps in understanding the tool's behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence that efficiently conveys the core functionality without unnecessary words. It is front-loaded with the main action and resource, making it easy to understand at a glance.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a search tool with 4 parameters, no annotations, and no output schema, the description is incomplete. It lacks details on behavioral traits (e.g., how popularity is determined, result format), usage context, and differentiation from siblings. This makes it inadequate for an AI agent to fully understand when and how to invoke the tool effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, meaning all parameters are well-documented in the schema itself. The description adds no additional parameter semantics beyond implying a geographical search, which is already covered by the 'bounds' parameter description. Thus, it meets the baseline score of 3 without adding extra value.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with a specific verb ('searches') and resource ('popular segments'), and specifies the geographical scope. However, it doesn't differentiate from sibling tools like 'list-starred-segments' or 'get-segment', which might also retrieve segments but with different criteria or scope.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'list-starred-segments' or 'get-segment', nor does it mention prerequisites such as requiring a connected Strava account. It only states what the tool does without contextual usage advice.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.