ctftime_results
Retrieve CTF competition event results by year. Defaults to the current year if no year provided.
Instructions
Get event results for a year (or current year if omitted).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| year | No | Year (e.g., 2025). |
Implementation Reference
- src/index.ts:186-209 (registration)Registration of the 'ctftime_results' tool with description and input schema.
server.registerTool( "ctftime_results", { description: "Get event results for a year (or current year if omitted).", inputSchema: { year: z .number() .int() .min(2011) .max(2100) .optional() .describe("Year (e.g., 2025)."), }, }, async ({ year }) => { const url = year ? `${CTFtime_API_BASE}/results/${year}/` : `${CTFtime_API_BASE}/results/`; const data = await getJson<any>(url); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }], }; } ); - src/index.ts:188-198 (schema)Input schema for 'ctftime_results': optional year (integer, 2011-2100).
{ description: "Get event results for a year (or current year if omitted).", inputSchema: { year: z .number() .int() .min(2011) .max(2100) .optional() .describe("Year (e.g., 2025)."), }, - src/index.ts:200-209 (handler)Handler function that calls CTFtime API /results/ endpoint with optional year, returns JSON result.
async ({ year }) => { const url = year ? `${CTFtime_API_BASE}/results/${year}/` : `${CTFtime_API_BASE}/results/`; const data = await getJson<any>(url); return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }], }; } ); - src/index.ts:9-26 (helper)Generic helper getJson<T> used by the handler to fetch and parse JSON from CTFtime API.
async function getJson<T>(url: string): Promise<T> { const res = await fetch(url, { headers: { Accept: "application/json", // CTFtime doesn't require a UA header for this API, but it helps with debugging and etiquette. "User-Agent": "mcp-ctftime/0.1.0 (+https://ctftime.org/api/)", }, }); if (!res.ok) { const text = await res.text().catch(() => ""); throw new Error( `CTFtime API error ${res.status} for ${url}${ text ? `: ${text.slice(0, 300)}` : "" }` ); } return (await res.json()) as T; }