Skip to main content
Glama

health_topics

Access evidence-based health information on specific topics using the Healthcare MCP Server. Search for reliable content in English or Spanish to support informed decision-making.

Instructions

Get evidence-based health information on various topics

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
languageNoLanguage for content (en or es)en
topicYesHealth topic to search for information

Implementation Reference

  • The main handler function implementing the health_topics tool logic: validates input, checks cache, queries Health.gov API, processes and cleans topic data, caches results, and formats success/error responses.
    async getHealthTopics(topic, language = 'en') {
      // Input validation
      if (!topic) {
        return this.formatErrorResponse('Topic is required');
      }
      
      // Validate language
      if (!['en', 'es'].includes(language.toLowerCase())) {
        language = 'en';
      }
      
      // Create cache key
      const cacheKey = this.getCacheKey('health_topics', topic, language);
      
      // Check cache first
      const cachedResult = this.cache.get(cacheKey);
      if (cachedResult) {
        console.error(`Cache hit for Health Topics search: ${topic}`);
        return cachedResult;
      }
      
      try {
        console.error(`Searching Health Topics for: ${topic}, language: ${language}`);
        
        // Build API URL with parameters for topicsearch
        const params = {
          keyword: topic,
          lang: language
        };
        
        const url = this.buildUrl(`${this.baseUrl}/topicsearch.json`, params);
        
        // Make the request
        const data = await this.makeRequest(url);
        
        // Process the response
        let topics = [];
        let totalResults = 0;
        
        if (data && data.Result && data.Result.Resources) {
          const rawTopics = data.Result.Resources.Resource || [];
          totalResults = rawTopics.length;
          
          // Process each topic
          for (const rawTopic of rawTopics) {
            const processedTopic = {
              title: rawTopic.Title || '',
              url: rawTopic.AccessibleVersion || rawTopic.LastUpdate || '',
              last_updated: rawTopic.LastUpdate || '',
              section: rawTopic.Sections?.Section?.[0]?.Title || '',
              description: rawTopic.Sections?.Section?.[0]?.Description || '',
              content: []
            };
            
            // Extract content from sections
            if (rawTopic.Sections && rawTopic.Sections.Section) {
              for (const section of rawTopic.Sections.Section) {
                if (section.Content) {
                  // Clean and limit content
                  let content = section.Content;
                  if (typeof content === 'string') {
                    // Remove HTML and limit size
                    content = content.replace(/<[^>]*>/g, ' ').replace(/\s+/g, ' ').trim();
                    if (content.length > 500) {
                      content = content.substring(0, 497) + '...';
                    }
                    if (content) {
                      processedTopic.content.push(content);
                    }
                  }
                }
              }
            }
            
            topics.push(processedTopic);
          }
        }
        
        // Create result object
        const result = this.formatSuccessResponse({
          search_term: topic,
          language: language,
          total_results: totalResults,
          health_topics: topics
        });
        
        // Cache for 24 hours (86400 seconds)
        this.cache.set(cacheKey, result, 86400);
        
        return result;
        
      } catch (error) {
        console.error(`Error searching Health Topics: ${error.message}`);
        return this.formatErrorResponse(`Error searching health topics: ${error.message}`);
      }
    }
  • Input schema definition for the health_topics tool, specifying required 'topic' parameter and optional 'language' (en/es).
    inputSchema: {
      type: "object",
      properties: {
        topic: {
          type: "string",
          description: "Health topic to search for information",
        },
        language: {
          type: "string",
          description: "Language for content (en or es)",
          enum: ["en", "es"],
          default: "en",
        },
      },
      required: ["topic"],
    },
  • Tool registration in the main CallToolRequestSchema handler switch statement, dispatching calls to the HealthTopicsTool.getHealthTopics method.
    case "health_topics":
      result = await healthTopicsTool.getHealthTopics(args.topic, args.language);
  • server/index.js:31-31 (registration)
    Instantiation of the HealthTopicsTool instance used by the server.
    const healthTopicsTool = new HealthTopicsTool(cacheService);
  • Inline input validation schema enforcing required topic and valid language (en/es).
    // Input validation
    if (!topic) {
      return this.formatErrorResponse('Topic is required');
    }
    
    // Validate language
    if (!['en', 'es'].includes(language.toLowerCase())) {
      language = 'en';
    }
Install Server

Other Tools

Related Tools

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/Cicatriiz/healthcare-mcp-public'

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