Skip to main content
Glama
chrismannina

PubMed MCP Server

by chrismannina

get_trending_topics

Identify trending medical research topics and emerging areas within specific categories by analyzing recent PubMed publications over a defined time period.

Instructions

Get trending medical topics and research areas

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
categoryNoMedical category (e.g., 'cardiology', 'oncology', 'neurology')
daysNoNumber of days to analyze for trends

Implementation Reference

  • The main handler function that implements get_trending_topics by querying recent PubMed articles with trending keywords, grouping by article keywords, and returning top trending topics.
    async def _handle_get_trending_topics(self, arguments: Dict[str, Any]) -> MCPResponse:
        """Handle trending topics analysis."""
        try:
            category = arguments.get("category", "")
            days = arguments.get("days", 7)
    
            # Calculate date range for trending analysis
            end_date = datetime.now()
            start_date = end_date - timedelta(days=days)
    
            date_from = start_date.strftime("%Y/%m/%d")
            date_to = end_date.strftime("%Y/%m/%d")
    
            # Build query for trending topics
            if category:
                query = f'{category} AND ("trending" OR "emerging" OR "new" OR "novel")'
            else:
                query = (
                    '("trending" OR "emerging" OR "breakthrough" OR "novel") '
                    "AND (medicine OR medical)"
                )
    
            search_result = await self.pubmed_client.search_articles(
                query=query,
                max_results=30,
                sort_order=SortOrder.PUBLICATION_DATE,
                date_from=date_from,
                date_to=date_to,
                cache=self.cache,
            )
    
            content = []
            content.append(
                {
                    "type": "text",
                    "text": (
                        f"**Trending Topics in {category or 'Medicine'} "
                        f"(Last {days} days)**\n\n"
                        f"Found: {search_result.returned_results} recent articles\n"
                    ),
                }
            )
    
            # Group by topics/keywords
            topics = {}
            for article_data in search_result.articles:
                # Handle Article objects - access keywords attribute directly
                keywords = (
                    getattr(article_data, "keywords", [])
                    if hasattr(article_data, "keywords")
                    else []
                )
                for keyword in keywords[:3]:  # Top 3 keywords
                    if keyword not in topics:
                        topics[keyword] = []
                    topics[keyword].append(article_data)
    
            # Show top topics
            sorted_topics = sorted(topics.items(), key=lambda x: len(x[1]), reverse=True)[:5]
    
            for topic, articles in sorted_topics:
                articles_list = "\n".join(
                    [f"• {article.title} (PMID: {article.pmid})" for article in articles[:3]]
                )
    
                content.append(
                    {
                        "type": "text",
                        "text": f"\n**{topic}** ({len(articles)} articles)\n{articles_list}",
                    }
                )
    
            return MCPResponse(content=content)
    
        except Exception as e:
            logger.error(f"Error in get_trending_topics: {e}")
            return MCPResponse(
                content=[{"type": "text", "text": f"Error: {str(e)}"}], is_error=True
            )
  • Defines the tool schema, description, and input parameters (category and days) for get_trending_topics.
    {
        "name": "get_trending_topics",
        "description": "Get trending medical topics and research areas",
        "inputSchema": {
            "type": "object",
            "properties": {
                "category": {
                    "type": "string",
                    "description": (
                        "Medical category (e.g., 'cardiology', 'oncology', " "'neurology')"
                    ),
                },
                "days": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 30,
                    "default": 7,
                    "description": "Number of days to analyze for trends",
                },
            },
        },
    },
  • Registers the tool name to its handler method in the handler_map dictionary used by handle_tool_call.
    "get_trending_topics": self._handle_get_trending_topics,
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool 'gets' trending topics, implying a read-only operation, but doesn't mention any behavioral traits such as rate limits, authentication needs, data freshness, or what the output format might be. This leaves significant gaps for an agent to understand how to interact with it effectively.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that directly states the tool's purpose without any unnecessary words. It's front-loaded and wastes no space, making it easy for an agent to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of fetching trending data, lack of annotations, and no output schema, the description is incomplete. It doesn't explain what 'trending' means (e.g., based on publication volume, citations, or social media), the scope of data sources, or the structure of returned results. This leaves the agent with insufficient context to use the tool effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, clearly documenting both parameters ('category' and 'days') with details like allowed values and defaults. The description adds no additional meaning beyond what the schema provides, such as explaining how 'category' affects results or what 'trending' entails. With high schema coverage, the baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with a specific verb ('Get') and resource ('trending medical topics and research areas'), making it easy to understand what it does. However, it doesn't distinguish itself from potential siblings like 'analyze_research_trends' or 'search_mesh_terms', which might have overlapping functionality in medical trend analysis.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'analyze_research_trends' and 'search_mesh_terms' that might handle similar medical trend data, there's no indication of context, prerequisites, or exclusions to help an agent choose appropriately.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/chrismannina/pubmed-mcp'

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