get_channels
Retrieve all available TV channels from XMLTV feeds to access programming data and schedule information.
Instructions
Get list of all available TV channels
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:101-108 (handler)The main handler function for the 'get_channels' tool. Fetches cached XMLTV data and maps channels to an array of {id, name, icon} objects.async function getChannels() { const data = await getXmltvData(); return data.tv.channel.map(ch => ({ id: ch.id, name: ch["display-name"], icon: typeof ch.icon === 'object' ? ch.icon.src : undefined, })); }
- src/index.ts:264-271 (schema)The tool schema definition including name, description, and empty input schema (no parameters required).{ name: "get_channels", description: "Get list of all available TV channels", inputSchema: { type: "object", properties: {}, }, },
- src/index.ts:339-349 (registration)Registration in the CallToolRequestSchema handler: switch case that invokes getChannels() and formats response as JSON text.case "get_channels": { const channels = await getChannels(); return { content: [ { type: "text", text: JSON.stringify(channels, null, 2), }, ], }; }
- src/index.ts:332-334 (registration)Handler for ListToolsRequestSchema that returns the tools list including 'get_channels'.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools }; });
- src/index.ts:66-96 (helper)Helper function to fetch, parse, and cache XMLTV data from the configured URL, used by getChannels.async function getXmltvData(): Promise<XmltvData> { const now = Date.now(); if (cache && (now - cache.timestamp) < CACHE_TTL) { return cache.data; } const response = await fetch(XMLTV_URL); if (!response.ok) { throw new Error(`Failed to fetch XMLTV: ${response.statusText}`); } const xmlText = await response.text(); const parser = new XMLParser({ ignoreAttributes: false, attributeNamePrefix: "", }); const parsed = parser.parse(xmlText) as XmltvData; // Ensure arrays are always arrays (parser might return single object) if (parsed.tv.channel && !Array.isArray(parsed.tv.channel)) { parsed.tv.channel = [parsed.tv.channel]; } if (parsed.tv.programme && !Array.isArray(parsed.tv.programme)) { parsed.tv.programme = [parsed.tv.programme]; } cache = { data: parsed, timestamp: now }; return parsed; }