Connects AI agents to NCBI's PubMed and E-utilities, enabling search, retrieval, and analysis of biomedical literature. Provides tools for searching articles, fetching detailed content, finding related articles, generating citations, creating research plans, and visualizing data through charts.
Generates SVG chart visualizations from PubMed data, supporting bar, line, and scatter chart types for data representation.
Built with TypeScript for type safety and robust input validation, ensuring secure and reliable interactions with PubMed's biomedical data.
Utilizes Vega-Lite specifications to render SVG charts from PubMed data, enabling visualization of biomedical research trends and statistics.
Processes PubMed article data in XML format, providing JSON representation of the PubMedArticle XML structure through the fetch_pubmed_content tool.
Uses Zod for schema validation of inputs and outputs when interacting with PubMed, ensuring type safety and proper data formatting.
PubMed MCP Server Pubmed
Unlock the power of biomedical literature for your AI agents with the PubMed MCP Server!
This server acts as a bridge, connecting your AI to NCBI's PubMed and E-utilities through the Model Context Protocol (MCP). It empowers language models to seamlessly search, retrieve, and analyze biomedical articles and data. Built with TypeScript and adhering to the MCP 2025-03-26 specification, it's designed for robustness and includes production-grade utilities.
🚀 Core Capabilities: PubMed Tools 🛠️
This server equips your AI with specialized tools to interact with PubMed:
Tool Name | Description | Key Features |
---|---|---|
search_pubmed_articles | Searches PubMed for articles based on your query. (See Example) | - Filter by max results, sort order, date range, publication types.- Uses NCBI ESearch for PMIDs.- Optionally fetches brief summaries (title, authors, source, dates) via ESummary. |
fetch_pubmed_content | Retrieves detailed information for PubMed articles. Can use a list of PMIDs or ESearch history (queryKey/webEnv) with pagination. (See Example) | - Flexible detailLevel : abstract_plus (parsed details, optional MeSH/grant), full_xml (JSON representation of the PubMedArticle XML structure), medline_text (MEDLINE format), citation_data (minimal for citations).- Supports direct PMID list or queryKey /webEnv from ESearch history.- Supports retstart /retmax for pagination with history.- Uses NCBI EFetch. |
get_pubmed_article_connections | Finds related articles (cited by, similar, references) or formats citations for a PMID. (See Ex.1, Ex.2) | - Uses NCBI ELink for relationships.- Uses NCBI EFetch for citation data (RIS, BibTeX, APA, MLA).- Filter by max related results. |
pubmed_research_agent | Generates a standardized JSON research plan outline from component details. (See Example) | - Accepts granular inputs for all research phases.- Optionally embeds instructive prompts for agent execution.- Structures rough ideas into a formal, machine-readable plan for further processing. |
generate_pubmed_chart | Generates a chart image (SVG) from given input data. (See Bar, Line, Scatter) | - Supports 'bar', 'line', and 'scatter' chart types.- Takes data values and field specifications for axes and encoding.- Constructs a Vega-Lite specification internally and renders it as an SVG. |
✨ Key Features Beyond Tools
Feature Category | Description |
---|---|
🔌 MCP Compliant | Fully functional server supporting stdio and http (SSE) transports. |
🚀 Production-Ready Utils | Includes robust logging, error handling, ID generation, rate limiting, request context tracking, and input sanitization. |
🔒 Secure & Type-Safe | Built with TypeScript & Zod for strong type checking and input validation. Manages NCBI API keys, implements rate limiting, and features JWT-based auth middleware for HTTP. |
⚙️ Advanced Error Handling | Consistent error categorization, detailed logging, and centralized handling, including specific error types for NCBI interactions. |
📚 Well-Documented | Comprehensive JSDoc comments, API references, and project specifications. |
🤖 Agent-Friendly | Includes a .clinerules developer cheatsheet tailored for LLM coding agents using this server. |
🛠️ Developer Utilities | Scripts for cleaning builds, setting executable permissions, generating directory trees, and fetching OpenAPI specifications. |
🚀 Quick Start
Get the PubMed MCP server running in minutes:
- Clone the repository:
- Install dependencies:
- Configure Environment Variables (
.env
file): Create a.env
file in the project root. Key variables:For all options, see the Configuration section below or the Developer Cheatsheet (.clinerules).New example files for each tool are available in theexamples/
directory (e.g.,examples/search_pubmed_articles_example.md
,examples/generate_pubmed_chart_example_bar.svg
). - Build the project:
- Format the code (Optional but Recommended):
- Run the Server:
- Via Stdio (Default): Many MCP host applications will run this automatically using
stdio
. To run manually for testing: - Via HTTP (SSE): (Ensure
MCP_TRANSPORT_TYPE=http
andMCP_AUTH_SECRET_KEY
are set in your.env
)This starts an HTTP server (default:http://127.0.0.1:3010
) using Server-Sent Events.
- Via Stdio (Default): Many MCP host applications will run this automatically using
⚙️ Configuration
Server Configuration (Environment Variables)
Configure the PubMed MCP server's behavior using environment variables (typically in a .env
file).
Variable | Description | Default |
---|---|---|
MCP_TRANSPORT_TYPE | Server transport: stdio or http . | stdio |
MCP_HTTP_PORT | Port for the HTTP server (if MCP_TRANSPORT_TYPE=http ). | 3010 |
MCP_HTTP_HOST | Host address for the HTTP server (if MCP_TRANSPORT_TYPE=http ). | 127.0.0.1 |
MCP_ALLOWED_ORIGINS | Comma-separated allowed origins for CORS (if MCP_TRANSPORT_TYPE=http ). | (none) |
MCP_LOG_LEVEL | Server logging level (debug , info , warning , error , etc.). | debug |
LOGS_DIR | Directory for log files. | logs/ (in project root) |
NODE_ENV | Runtime environment (development , production ). | development |
MCP_AUTH_SECRET_KEY | Required for HTTP transport. Secret key (min 32 chars) for signing/verifying auth tokens (JWT). | (none - MUST be set in production) |
NCBI_API_KEY | Optional, but highly recommended. Your NCBI API Key for higher rate limits (10/sec vs 3/sec). | (none) |
NCBI_ADMIN_EMAIL | Optional, but recommended if using an API key. Your email for NCBI contact. | (none) |
NCBI_TOOL_IDENTIFIER | Optional. Tool identifier sent to NCBI. | @cyanheads/pubmed-mcp-server/<version> |
NCBI_REQUEST_DELAY_MS | Milliseconds to wait between NCBI requests. Dynamically set (e.g., 100ms with API key, 334ms without). | (see src/config/index.ts ) |
NCBI_MAX_RETRIES | Maximum number of retries for failed NCBI requests. | 3 |
Note on HTTP Port Retries: If the MCP_HTTP_PORT
is busy, the server automatically tries the next port (up to 15 times).
Security Note for HTTP Transport: When using MCP_TRANSPORT_TYPE=http
, authentication is mandatory as per the MCP specification. This server includes JWT-based authentication middleware. You MUST set a strong, unique MCP_AUTH_SECRET_KEY
in your production environment.
For a comprehensive list of all available environment variables, their descriptions, and default values, please review the configuration loader at src/config/index.ts
.
🏗️ Project Structure Overview
The src/
directory contains the core logic:
config/
: Environment variable loading and package information.mcp-server/
: The heart of the PubMed MCP server.server.ts
: Initializes the server instance and registers all tools and resources.resources/
: Implementations for MCP resources (e.g., server status, PubMed statistics).tools/
: Implementations for MCP tools (likesearchPubMedArticles
,fetchPubMedContent
,getPubMedArticleConnections
).transports/
: Handlesstdio
andhttp
(SSE) communication, including authentication for HTTP.
services/
: Integrations with external services.NCBI/ncbiService.ts
: Manages all interactions with NCBI E-utilities, including API calls, rate limiting, and response parsing.llm-providers/
: (Optional) For integrating LLM capabilities directly within the server.
types-global/
: Shared TypeScript definitions, especially for errors and MCP types.utils/
: A comprehensive suite of reusable utilities for logging, error handling, security, parsing, metrics, and more.
For a detailed file tree, run: npm run tree
or see Directory Tree.
🧩 Extending with More PubMed Capabilities
Adding new tools or resources is straightforward:
- Directory Setup: Create a new directory under
src/mcp-server/tools/yourNewTool/
orsrc/mcp-server/resources/yourNewResource/
. - Implement Core Logic (
logic.ts
):- Define Zod schemas for input validation.
- Write the function that interacts with
src/services/NCBI/ncbiService.ts
(e.g.,ncbiService.eLink(...)
). - Parse the NCBI response and format it according to MCP specifications (
CallToolResult
orReadResourceResult
).
- Register the Capability (
registration.ts
):- For tools:
server.tool(name, description, zodSchemaShape, handlerFunction)
- For resources:
server.resource(registrationName, template, metadata, handlerFunction)
- Always wrap your logic in
ErrorHandler.tryCatch
for robust error management.
- For tools:
- Export and Integrate: Export the registration function from your new directory's
index.ts
and call it withinsrc/mcp-server/server.ts
.
🌍 Learn More
- Model Context Protocol Official Site
- MCP Specification (2025-03-26)
- TypeScript SDK for MCP
- NCBI E-utilities Documentation
📜 License
This project is licensed under the Apache License 2.0. See the LICENSE file for details.
This server cannot be installed
A bridge connecting AI agents to NCBI's PubMed database through the Model Context Protocol, enabling seamless searching, retrieval, and analysis of biomedical literature and data.
Related MCP Servers
- -securityFlicense-qualityAn MCP server implementation that enables searching and retrieving research articles from PubMed with specific focus on open access content filtering and full-text link retrieval.Last updated -43JavaScript
- -securityFlicense-quality🔍 Enable AI assistants to search and access medRxiv papers through a simple MCP interface. The medRxiv MCP Server provides a bridge between AI assistants and medRxiv's preprint repository through the Model Context Protocol (MCP). It allows AI models to search for health sciences preprints and acceLast updated -1Python
- -securityAlicense-qualityAn MCP server enabling AI assistants to search and analyze pharmaceutical data through Cortellis. Features comprehensive drug search, ontology exploration, and real-time clinical trial data access.Last updated -PythonMIT License
- -securityAlicense-qualityA specialized Model Context Protocol server that enhances AI-assisted medical learning by connecting Claude Desktop to PubMed, NCBI Bookshelf, and user documents for searching, retrieving, and analyzing medical education content.Last updated -PythonMIT License