trendingTopicsSearch
Discover trending topics and popular content on Twitter by specifying location, timeframe, and the number of topics to retrieve for analysis.
Instructions
Get trending topics and popular content for analysis
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| count | No | Number of trending topics to return (default: 10, max: 50) | |
| location | No | Location for trending topics (default: "worldwide") | |
| timeframe | No | Timeframe for trending analysis (default: "hourly") |
Implementation Reference
- Main handler function that implements the core logic of the trendingTopicsSearch tool. It uses the SocialData client to search for recent popular tweets (filter:popular -filter:replies) within the specified timeframe as a proxy for trending topics.export const handleTrendingTopicsSearch: SocialDataHandler<TrendingTopicsArgs> = async ( _client: any, { location = 'worldwide', timeframe = 'hourly', count = 10 }: TrendingTopicsArgs ) => { try { const socialClient = getSocialDataClient(); if (!socialClient) { return createMissingApiKeyResponse('Trending Topics Search'); } // For trending topics, we'll search for popular recent content const query = `filter:popular -filter:replies`; const now = new Date(); const timeOffset = timeframe === 'hourly' ? 1 : timeframe === 'daily' ? 24 : 168; // hours const startTime = new Date(now.getTime() - timeOffset * 60 * 60 * 1000).toISOString(); const result = await socialClient.searchTweets({ query, maxResults: count, startTime, endTime: now.toISOString() }); if (!result.data || result.data.length === 0) { return createSocialDataResponse(`No trending topics found for ${location} (${timeframe})`); } return createSocialDataResponse( formatTweetList(result.data, `Trending Topics - ${location} (${timeframe})`) ); } catch (error) { throw new Error(formatSocialDataError(error as Error, 'trending topics search')); } };
- src/socialdata-tools.ts:76-99 (schema)Defines the input schema, parameters, and description for the trendingTopicsSearch tool used in MCP tool listing.trendingTopicsSearch: { description: 'Get trending topics and popular content for analysis', inputSchema: { type: 'object', properties: { location: { type: 'string', description: 'Location for trending topics (default: "worldwide")' }, timeframe: { type: 'string', enum: ['hourly', 'daily', 'weekly'], description: 'Timeframe for trending analysis (default: "hourly")' }, count: { type: 'number', description: 'Number of trending topics to return (default: 10, max: 50)', minimum: 1, maximum: 50 } }, required: [] } },
- src/types/socialdata.ts:33-37 (schema)TypeScript interface defining the input arguments for the trendingTopicsSearch handler.export interface TrendingTopicsArgs { location?: string; timeframe?: 'hourly' | 'daily' | 'weekly'; count?: number; }
- src/tools.ts:736-738 (registration)Registers the trendingTopicsSearch tool by spreading SOCIALDATA_TOOLS into the main TOOLS export, which is used by the MCP server for listing available tools.// SocialData.tools enhanced research and analytics ...SOCIALDATA_TOOLS };
- src/index.ts:436-439 (registration)Registers the tool handler in the main MCP request dispatcher switch statement, routing tool calls to handleTrendingTopicsSearch.case 'trendingTopicsSearch': { const args = request.params.arguments as any; response = await handleTrendingTopicsSearch(client, args); break;