trending
Fetch trending topics from GitHub or HackerNews. Specify the platform and maximum results to retrieve.
Instructions
Get trending topics from popular platforms
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| search_service | Yes | Specify the platform to get trending topics from | github |
| max_results | No | Maximum number of trending items to return |
Implementation Reference
- src/tools/trending.ts:10-42 (handler)Handler function that validates trending arguments, makes API request to the /trending endpoint, and returns results (or error)
export async function handleTrending(args: unknown, apiKey?: string) { if (!isValidTrendingArgs(args)) { throw new McpError( ErrorCode.InvalidParams, "Invalid trending arguments" ); } try { const response = await makeRequest<TrendingResponse>( API_CONFIG.ENDPOINTS.TRENDING, args, apiKey ); return { content: [{ type: "text", mimeType: "application/json", text: JSON.stringify(response.results, null, 2) }] }; } catch (error) { return { content: [{ type: "text", mimeType: "text/plain", text: `Trending API error: ${formatError(error)}` }], isError: true }; } } - src/types.ts:291-294 (schema)TrendingArgs interface with search_service and optional max_results
export interface TrendingArgs { search_service: TrendingService; max_results?: number; } - src/types.ts:296-317 (schema)Validation function for trending arguments
export function isValidTrendingArgs(args: unknown): args is TrendingArgs { if (typeof args !== 'object' || args === null) { return false; } const { search_service, max_results } = args as TrendingArgs; if (search_service === undefined) { return false; } const validServices = Object.values(TrendingService); if (!validServices.includes(search_service)) { return false; } if (max_results !== undefined && (typeof max_results !== 'number' || max_results < 1 || max_results > 50)) { return false; } return true; } - src/tools/index.ts:157-178 (registration)Tool definition registration with name 'trending', description, and input schema
// Trending tool definition export const TRENDING_TOOL: Tool = { name: "trending", description: "Get trending topics from popular platforms", inputSchema: { type: "object", properties: { search_service: { type: "string", description: "Specify the platform to get trending topics from", enum: ["github", "hackernews"], default: "github" }, max_results: { type: "number", description: "Maximum number of trending items to return", default: 10 } }, required: ["search_service"] } }; - src/tools/handlers.ts:8-48 (helper)Handler dispatch that routes trending tool calls to handleTrending function
import { handleTrending } from './trending.js'; import { SEARCH_TOOL, CRAWL_TOOL, SITEMAP_TOOL, NEWS_TOOL, REASONING_TOOL, TRENDING_TOOL } from './index.js'; /** * Dispatch request based on tool name * @param toolName Name of the tool * @param args Tool parameters * @param apiKey Optional per-session API key * @returns Tool processing result */ export async function handleToolCall(toolName: string, args: unknown, apiKey?: string) { log(`Handling tool call: ${toolName}`); switch (toolName) { case SEARCH_TOOL.name: return await handleSearch(args, apiKey); case CRAWL_TOOL.name: return await handleCrawl(args, apiKey); case SITEMAP_TOOL.name: return await handleSitemap(args, apiKey); case NEWS_TOOL.name: return await handleNews(args, apiKey); case REASONING_TOOL.name: return await handleReasoning(args, apiKey); case TRENDING_TOOL.name: return await handleTrending(args, apiKey); default: log(`Unknown tool: ${toolName}`); throw new McpError( ErrorCode.InvalidParams, `Unknown tool: ${toolName}` ); } }