Skip to main content
Glama
chrismannina

PubMed MCP Server

by chrismannina

compare_articles

Analyze and contrast multiple PubMed articles by comparing key research elements like authors, methods, and conclusions to identify similarities and differences.

Instructions

Compare multiple articles side by side

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pmidsYesList of PMIDs to compare (2-5 articles)
comparison_fieldsNoFields to compare

Implementation Reference

  • Main execution logic for the compare_articles tool: validates 2-5 PMIDs, fetches article details via PubMedClient, formats comparison of basic info, MeSH terms, and abstracts.
    async def _handle_compare_articles(self, arguments: Dict[str, Any]) -> MCPResponse:
        """Handle article comparison."""
        try:
            pmids = arguments.get("pmids", [])
            if len(pmids) < 2 or len(pmids) > 5:
                return MCPResponse(
                    content=[{"type": "text", "text": "Please provide 2-5 PMIDs for comparison"}],
                    is_error=True,
                )
    
            comparison_fields = arguments.get(
                "comparison_fields", ["authors", "methods", "conclusions"]
            )
    
            # Get article details
            articles = await self.pubmed_client.get_article_details(
                pmids=pmids, include_abstracts=True, cache=self.cache
            )
    
            if len(articles) < 2:
                return MCPResponse(
                    content=[
                        {"type": "text", "text": "Not enough valid articles found for comparison"}
                    ],
                    is_error=True,
                )
    
            content = []
            content.append(
                {"type": "text", "text": f"**Comparison of {len(articles)} Articles**\n"}
            )
    
            # Basic comparison
            comparison_text = "**Articles:**\n"
            for i, article in enumerate(articles, 1):
                authors_str = format_authors(
                    [f"{a.first_name or a.initials} {a.last_name}" for a in article.authors[:3]]
                )
                comparison_text += f"{i}. {article.title}\n"
                comparison_text += f"   Authors: {authors_str}\n"
                comparison_text += (
                    f"   Journal: {article.journal.title} ({format_date(article.pub_date)})\n"
                )
                comparison_text += f"   PMID: {article.pmid}\n\n"
    
            content.append({"type": "text", "text": comparison_text})
    
            # Compare specific fields
            if "mesh_terms" in comparison_fields:
                mesh_comparison = "**MeSH Terms Comparison:**\n"
                for i, article in enumerate(articles, 1):
                    mesh_terms = [term.descriptor_name for term in article.mesh_terms[:5]]
                    mesh_comparison += f"{i}. {', '.join(mesh_terms)}\n"
    
                content.append({"type": "text", "text": mesh_comparison})
    
            if "abstracts" in comparison_fields:
                content.append({"type": "text", "text": "**Abstracts:**\n"})
    
                for i, article in enumerate(articles, 1):
                    abstract_text = truncate_text(article.abstract or "No abstract available", 200)
                    content.append({"type": "text", "text": f"{i}. {abstract_text}\n"})
    
            return MCPResponse(content=content)
    
        except Exception as e:
            logger.error(f"Error in compare_articles: {e}")
            return MCPResponse(
                content=[{"type": "text", "text": f"Error: {str(e)}"}], is_error=True
            )
  • JSON schema defining the input parameters for compare_articles: requires array of 2-5 PMIDs, optional comparison_fields enum.
    {
        "name": "compare_articles",
        "description": "Compare multiple articles side by side",
        "inputSchema": {
            "type": "object",
            "properties": {
                "pmids": {
                    "type": "array",
                    "items": {"type": "string"},
                    "minItems": 2,
                    "maxItems": 5,
                    "description": "List of PMIDs to compare (2-5 articles)",
                },
                "comparison_fields": {
                    "type": "array",
                    "items": {
                        "type": "string",
                        "enum": [
                            "authors",
                            "methods",
                            "results",
                            "conclusions",
                            "mesh_terms",
                            "citations",
                        ],
                    },
                    "default": ["authors", "methods", "conclusions"],
                    "description": "Fields to compare",
                },
            },
            "required": ["pmids"],
        },
    },
  • Registration of the _handle_compare_articles handler in the tool routing dictionary used by handle_tool_call method.
    handler_map = {
        "search_pubmed": self._handle_search_pubmed,
        "get_article_details": self._handle_get_article_details,
        "search_by_author": self._handle_search_by_author,
        "find_related_articles": self._handle_find_related_articles,
        "export_citations": self._handle_export_citations,
        "search_mesh_terms": self._handle_search_mesh_terms,
        "search_by_journal": self._handle_search_by_journal,
        "get_trending_topics": self._handle_get_trending_topics,
        "analyze_research_trends": self._handle_analyze_research_trends,
        "compare_articles": self._handle_compare_articles,
        "get_journal_metrics": self._handle_get_journal_metrics,
        "advanced_search": self._handle_advanced_search,
    }
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It implies a read-only comparison operation but doesn't disclose output format, pagination, rate limits, authentication needs, or what 'side by side' means structurally (e.g., table, summary). This leaves significant gaps for agent understanding.

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 with zero wasted words. It's appropriately sized for the tool's complexity and front-loaded with the core action, making it easy 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 no annotations and no output schema, the description is incomplete for a tool with 2 parameters and comparison functionality. It lacks details on return values, error handling, or practical use cases, leaving the agent under-informed about how to effectively invoke and interpret results.

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?

Schema description coverage is 100%, with clear parameter documentation in the schema itself. The description adds no additional meaning about parameters beyond implying multi-article comparison, so it meets the baseline of 3 where the schema does the heavy lifting without compensating value.

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 'Compare multiple articles side by side' clearly states the verb (compare) and resource (articles), specifying the multi-article scope. However, it doesn't distinguish this from potential sibling tools like 'find_related_articles' or 'analyze_research_trends' that might also involve article comparison, missing explicit differentiation.

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. It doesn't mention prerequisites (e.g., needing PMIDs), exclusions, or how it differs from siblings like 'get_article_details' for single articles or 'analyze_research_trends' for broader analysis.

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