Skip to main content
Glama

research_topic

Research topics using Brave Search and Perplexity to gather information, facts, trends, news, and hashtags for social media content creation.

Instructions

Research a topic using Brave Search and Perplexity

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
topicYesTopic to research
includeHashtagsNoWhether to include relevant hashtags
includeFactsNoWhether to include facts about the topic
includeTrendsNoWhether to include trending information
includeNewsNoWhether to include news articles

Implementation Reference

  • Primary MCP handler function that processes the research_topic tool call, extracts options from arguments, delegates to researchAggregator.researchTopic, and formats the response.
    private async handleResearchTopic(args: any) { logger.info('Researching topic', { topic: args.topic }); try { const topic = args.topic; const options = { includeHashtags: args.includeHashtags || false, includeFacts: args.includeFacts || false, includeTrends: args.includeTrends || false, includeNews: args.includeNews || false, }; const researchData = await researchAggregator.researchTopic(topic, options); return { content: [ { type: 'text', text: JSON.stringify({ topic, options, researchData, status: 'success', }, null, 2), }, ], }; } catch (error) { logger.error('Error researching topic', { topic: args.topic, error: error instanceof Error ? error.message : String(error) }); throw error; }
  • Core implementation of topic research, aggregating results from Brave Search and Perplexity, extracting hashtags, facts, news, and trends based on options.
    async researchTopic( topic: string, options: { includeHashtags?: boolean; includeFacts?: boolean; includeTrends?: boolean; includeNews?: boolean; } = {} ): Promise<ResearchData> { logger.info('Researching topic', { topic, options }); const researchData: ResearchData = { sources: [], }; try { // Get search results from Brave Search const searchResults = await braveClient.search(topic, 10); // Add Brave Search as a source researchData.sources.push(searchResults.source); // Extract hashtags if requested if (options.includeHashtags) { researchData.hashtags = await braveClient.extractHashtags(topic, 5); } // Extract facts if requested if (options.includeFacts) { try { // Get in-depth research from Perplexity const perplexityResults = await perplexityClient.research(topic, { depth: 'detailed' }); // Add Perplexity as a source researchData.sources.push(perplexityResults.source); // Use Perplexity facts if available, otherwise extract from search results if (perplexityResults.facts && perplexityResults.facts.length > 0) { researchData.facts = perplexityResults.facts; logger.info('Using Perplexity facts', { count: perplexityResults.facts.length }); } else { researchData.facts = this.extractFacts(searchResults); logger.info('Using extracted facts from search results', { count: researchData.facts.length }); } } catch (error) { logger.warn('Error getting Perplexity research, falling back to extracted facts', { error: error instanceof Error ? error.message : String(error) }); // Fall back to extracting facts from search results researchData.facts = this.extractFacts(searchResults); } } // Extract news if requested if (options.includeNews) { researchData.news = this.extractNews(searchResults); } // Get trends if requested // Note: In a complete implementation, this would use the Twitter and Mastodon clients if (options.includeTrends) { researchData.trends = this.generatePlaceholderTrends(topic); } logger.info('Research completed successfully', { topic, hashtagCount: researchData.hashtags?.length || 0, factCount: researchData.facts?.length || 0, newsCount: researchData.news?.length || 0, trendCount: researchData.trends?.length || 0, }); return researchData; } catch (error) { logger.error('Error researching topic', { topic, error: error instanceof Error ? error.message : String(error) }); throw error; }
  • Schema definition and registration of the research_topic tool in the ListTools response.
    { name: 'research_topic', description: 'Research a topic using Brave Search and Perplexity', inputSchema: { type: 'object', properties: { topic: { type: 'string', description: 'Topic to research', }, includeHashtags: { type: 'boolean', description: 'Whether to include relevant hashtags', }, includeFacts: { type: 'boolean', description: 'Whether to include facts about the topic', }, includeTrends: { type: 'boolean', description: 'Whether to include trending information', }, includeNews: { type: 'boolean', description: 'Whether to include news articles', }, }, required: ['topic'], }, },
  • Helper function to extract factual sentences from Brave Search results.
    private extractFacts(searchResults: any): string[] { // In a real implementation, this would use NLP to extract facts // For now, we'll use a simple approach const facts: string[] = []; // Extract facts from web results searchResults.web.forEach((result: any) => { const sentences = result.description.split(/[.!?]+/).filter(Boolean); sentences.forEach((sentence: string) => { // Simple heuristic: sentences with numbers or specific keywords might be facts if ( /\d+/.test(sentence) || // Contains numbers /according to|research|study|found|shows|reveals|experts|report/i.test(sentence) // Contains fact-like keywords ) { facts.push(sentence.trim()); } }); }); // Limit to 5 facts return facts.slice(0, 5); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/tayler-id/social-media-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server