Skip to main content
Glama

star-segment

Manage starred segments on Strava: star or unstar specific segments for authenticated athletes using segment ID and starred status.

Instructions

Stars or unstars a specific segment for the authenticated athlete.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
segmentIdYesThe unique identifier of the segment to star or unstar.
starredYesSet to true to star the segment, false to unstar it.

Implementation Reference

  • Handler function that implements the 'star-segment' tool logic. Validates token, calls the helper updateStarStatus (starSegment from stravaClient), handles success/error responses in MCP format.
    execute: async ({ segmentId, starred }: StarSegmentInput) => { 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, }; } try { const action = starred ? 'starring' : 'unstarring'; console.error(`Attempting to ${action} segment ID: ${segmentId}...`); const updatedSegment = await updateStarStatus(token, segmentId, starred); const successMessage = `Successfully ${action} segment: "${updatedSegment.name}" (ID: ${updatedSegment.id}). Its starred status is now: ${updatedSegment.starred}.`; console.error(successMessage); return { content: [{ type: "text" as const, text: successMessage }] }; } catch (error) { const errorMessage = error instanceof Error ? error.message : "An unknown error occurred"; const action = starred ? 'star' : 'unstar'; console.error(`Error attempting to ${action} segment ID ${segmentId}:`, errorMessage); return { content: [{ type: "text" as const, text: `❌ API Error: Failed to ${action} segment ${segmentId}. ${errorMessage}` }], isError: true, }; } }
  • Zod input schema defining parameters for the star-segment tool: segmentId (number) and starred (boolean).
    const StarSegmentInputSchema = z.object({ segmentId: z.number().int().positive().describe("The unique identifier of the segment to star or unstar."), starred: z.boolean().describe("Set to true to star the segment, false to unstar it."), });
  • src/server.ts:98-103 (registration)
    Registration of the 'star-segment' tool on the MCP server using server.tool() with name, description, inputSchema.shape, and execute function from the imported starSegment object.
    server.tool( starSegment.name, starSegment.description, starSegment.inputSchema?.shape ?? {}, starSegment.execute );
  • Core helper function that makes the Strava API PUT request to /segments/{id}/starred to star/unstar a segment. Includes validation, error handling with token refresh, and Zod parsing of response.
    export async function starSegment(accessToken: string, segmentId: number, starred: boolean): Promise<StravaDetailedSegment> { if (!accessToken) { throw new Error("Strava access token is required."); } if (!segmentId) { throw new Error("Segment ID is required to star/unstar."); } if (starred === undefined) { throw new Error("Starred status (true/false) is required."); } try { const response = await stravaApi.put<unknown>( `segments/${segmentId}/starred`, { starred: starred }, // Data payload for the PUT request { headers: { Authorization: `Bearer ${accessToken}`, 'Content-Type': 'application/json' // Important for PUT requests with body } } ); // The response is expected to be the updated DetailedSegment const validationResult = DetailedSegmentSchema.safeParse(response.data); if (!validationResult.success) { console.error(`Strava API validation failed (starSegment: ${segmentId}):`, validationResult.error); throw new Error(`Invalid data format received from Strava API: ${validationResult.error.message}`); } return validationResult.data; } catch (error) { return await handleApiError<StravaDetailedSegment>(error, `starSegment for ID ${segmentId} with starred=${starred}`, async () => { // Use new token from environment after refresh const newToken = process.env.STRAVA_ACCESS_TOKEN!; return starSegment(newToken, segmentId, starred); }); } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/r-huijts/strava-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server