PubMed MCP Server
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.
README
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.<br/>- Uses NCBI ESearch for PMIDs.<br/>- 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).<br/>- Supports direct PMID list or queryKey/webEnv from ESearch history.<br/>- Supports retstart/retmax for pagination with history.<br/>- 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.<br/>- Uses NCBI EFetch for citation data (RIS, BibTeX, APA, MLA).<br/>- 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.<br/>- Optionally embeds instructive prompts for agent execution.<br/>- 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.<br/>- Takes data values and field specifications for axes and encoding.<br/>- 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:
git clone https://github.com/cyanheads/pubmed-mcp-server.git cd pubmed-mcp-server -
Install dependencies:
npm install -
Configure Environment Variables (
.envfile): Create a.envfile in the project root. Key variables:# REQUIRED FOR HTTP TRANSPORT MCP_AUTH_SECRET_KEY=generate_a_strong_random_32_plus_char_secret_key # RECOMMENDED FOR NCBI E-UTILITIES (for higher rate limits) # NCBI_API_KEY=your_ncbi_api_key_here # NCBI_ADMIN_EMAIL=your_email@example.com # Recommended if using an API key # NCBI_TOOL_IDENTIFIER=@cyanheads/pubmed-mcp-server/1.0.13 # Optional: Tool identifier for NCBI (defaults to current version)For all options, see the Configuration section below or the Developer Cheatsheet (.clinerules).
New example files for each tool are available in the
examples/directory (e.g.,examples/search_pubmed_articles_example.md,examples/generate_pubmed_chart_example_bar.svg). -
Build the project:
npm run build # Or use 'npm run rebuild' for a clean install (deletes node_modules, logs, dist) -
Format the code (Optional but Recommended):
npm run format -
Run the Server:
- Via Stdio (Default): Many MCP host applications will run this automatically using
stdio. To run manually for testing:npm start # or 'npm run start:stdio' - Via HTTP (SSE): (Ensure
MCP_TRANSPORT_TYPE=httpandMCP_AUTH_SECRET_KEYare set in your.env)
This starts an HTTP server (default:npm run start:httphttp://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/: Handlesstdioandhttp(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 (
CallToolResultorReadResourceResult).
- 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.tryCatchfor robust error management.
- For tools:
- Export and Integrate: Export the registration function from your new directory's
index.tsand 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.
<div align="center"> Empowering AI with PubMed | Built on the <a href="https://modelcontextprotocol.io/">Model Context Protocol</a> </div>
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。