marathon_countdown
Calculate the remaining time until a specific marathon event starts using its unique identifier.
Instructions
Get a countdown to a specific marathon event
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | Marathon ID, e.g. "tokyo2026", "boston2026" |
Implementation Reference
- index.js:312-336 (handler)The handler function and registration for the 'marathon_countdown' tool. It fetches marathon data from an API and calculates the time remaining until the race date.
// Tool: marathon_countdown server.tool( 'marathon_countdown', 'Get a countdown to a specific marathon event', { id: z.string().describe('Marathon ID, e.g. "tokyo2026", "boston2026"') }, async ({ id }) => { const data = await fetchJSON(`${BASE_URL}/api/marathons/${id}.json`); const m = data.marathon; const raceDate = new Date(m.date + 'T00:00:00'); const now = new Date(); const diff = raceDate - now; if (diff <= 0) { return { content: [{ type: 'text', text: `${m.name.en} has already taken place on ${m.date}.` }] }; } const days = Math.floor(diff / (1000 * 60 * 60 * 24)); const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); let text = `${m.name.en} Countdown\n\n`; text += `${days} days, ${hours} hours until race day\n`; text += `Date: ${m.date}\nCity: ${m.city}\n`; text += `\nLive countdown: ${m.links.countdown}`; return { content: [{ type: 'text', text }] }; }