Skip to main content
Glama

PubMed MCP Server v3.0

License: MIT npm version MCP Compatible TypeScript

为 LLM Agent 提供结构化 PubMed 文献数据的 MCP 服务器。Agent 友好的响应模型,专注数据提供,分析交给 LLM。

LLM Agent <--MCP--> PubMed MCP Server <--API--> PubMed / PMC / Unpaywall

核心能力: 文献搜索 / 智能缓存 / OA 全文下载 / Agentic 响应模型


快速开始

前置要求: Node.js v18.0.0+

1. 安装

# npm 全局安装
npm install -g mcp-pubmed-llm-server

# 或从源码构建
git clone git@github.com:PancrePal-xiaoyibao/mcp-pubmed-server-pancrpal.git
cd mcp-pubmed-server-pancrpal
npm install && npm run build

2. 配置

cp .env.example .env

编辑 .env

PUBMED_API_KEY=你的NCBI_API密钥    # 可选,https://www.ncbi.nlm.nih.gov/account/settings/
PUBMED_EMAIL=你的邮箱               # 可选(建议填写)
ABSTRACT_MODE=quick                 # quick(1500字符) | deep(6000字符)
FULLTEXT_MODE=disabled              # disabled | enabled | auto

说明: API Key 和 Email 均非必填。无 Key 时匿名运行(3 次/秒),有 Key 时 10 次/秒。

3. 运行

# npm 包
mcp-pubmed-llm-server
# 或
npx mcp-pubmed-llm-server

# 源码开发
npm run dev

# 源码生产
npm run build && npm start

Related MCP server: mcp-pubmed-server

传输模式

模式

适用场景

启动方式

stdio

本地 MCP 客户端集成

npm start(默认)

Streamable HTTP

服务端远程部署

npm run start:http

stdio 模式(默认)

npm start
# 或
node dist/index.js --mode=stdio

Streamable HTTP 模式

npm run start:http
# 或
node dist/index.js --mode=streamableHttp

Docker 部署:

cd docker
cp .env.example .env   # 编辑填入配置
docker compose up -d --build

验证:

curl http://localhost:8745/health
# {"status":"ok","mode":"streamableHttp","sessions":0}

端点:

  • POST /mcp — MCP 协议消息

  • GET /mcp — SSE 事件流

  • DELETE /mcp — 关闭会话

  • GET /health — 健康检查


MCP 客户端配置

Claude Desktop / Claude Code / Cline

{
  "mcpServers": {
    "pubmed": {
      "command": "npx",
      "args": ["-y", "mcp-pubmed-llm-server"],
      "env": {
        "PUBMED_API_KEY": "你的API密钥(可选)",
        "PUBMED_EMAIL": "你的邮箱(可选)",
        "ABSTRACT_MODE": "deep",
        "FULLTEXT_MODE": "enabled"
      }
    }
  }
}

配置文件位置:

  • Claude Desktop: ~/Library/Application Support/Claude/claude_desktop_config.json (macOS)

  • Claude Code: ~/.claude/config.json

  • Cline: VS Code 设置中的 MCP Servers

Cherry Studio

stdio 模式: 同上配置,type 设为 stdio

streamableHttp 模式: type 设为 streamableHttpbaseUrl 设为 http://<服务器IP>:8745/mcp


工具列表(8 个)

文献搜索

工具

说明

关键参数

pubmed_search

文献搜索,支持 Boolean/MeSH

query, max_results, days_back, sort_by, format

pubmed_get_details

获取 PMID 完整信息(单个或批量)

pmids, format

pubmed_extract_info

提取论文关键信息段落

pmid, sections

pubmed_find_related

查找相关/综述文献

pmid, type, max_results

缓存管理

工具

说明

关键参数

pubmed_manage_cache

缓存统计、清理、清空

action, target

全文下载(需 FULLTEXT_MODE=enabled

工具

说明

关键参数

pubmed_detect_fulltext

检测 OA 状态和全文可用性

pmid, auto_download

pubmed_download_fulltext

下载全文 PDF(单篇或批量)

pmids, force

pubmed_system_status

系统环境和 API Key 状态检测


Agentic 响应模型

每个工具返回统一的 AgentResponse<T> 结构,为 AI Agent 优化:

{
  "status": "success",
  "data": { ... },
  "metadata": {
    "tool": "pubmed_search",
    "executionMs": 1234,
    "timestamp": "2025-01-01T00:00:00.000Z",
    "pagination": { "total": 500, "returned": 20, "hasMore": true }
  },
  "suggestions": [
    {
      "tool": "pubmed_get_details",
      "reason": "Get full metadata for specific articles of interest.",
      "parameters": { "pmids": ["12345678"] }
    }
  ]
}
  • status — 成功/错误状态

  • data — 类型化的返回数据

  • metadata — 执行上下文(耗时、分页、缓存状态)

  • suggestions — Agent 下一步操作建议(工具名 + 原因 + 参数)


API Key 池配置

支持多个 NCBI API Key 轮询/主备/随机负载均衡。

在项目根目录创建 api-keys.json(参见 api-keys.json.example):

{
  "keys": [
    { "api_key": "KEY_1", "email": "user1@example.com" },
    { "api_key": "KEY_2", "email": "user2@example.com" }
  ],
  "strategy": "round-robin"
}

策略

说明

round-robin

轮询(默认)

failover

主备切换

random

随机负载均衡

优先级: api-keys.json > 环境变量 > 匿名模式

健康管理: 连续 3 次失败自动下线,60 秒冷却后恢复


项目结构

src/
├── index.ts                  # 入口点
├── config.ts                 # 配置常量 + 环境变量
├── server.ts                 # MCP Server 编排器
├── types/                    # TypeScript 类型定义
│   ├── article.ts            # Article, SearchResult, OAInfo
│   ├── responses.ts          # AgentResponse<T>, makeResponse/makeError
│   └── index.ts
├── api/
│   ├── pubmed-client.ts      # PubMed EUtilities 客户端
│   └── key-pool.ts           # API Key 号池(轮询/主备/随机)
├── cache/
│   ├── memory-cache.ts       # 内存 LRU 缓存(5 分钟,100 条上限)
│   └── file-cache.ts         # 文件持久化缓存(30 天过期)
├── services/
│   ├── fulltext.ts           # OA 检测 + PDF 下载
│   └── system.ts             # 系统环境检测
├── tools/
│   ├── definitions.ts        # MCP 工具 Schema(8 个工具)
│   └── handlers.ts           # 工具路由 + 处理逻辑
├── transport/
│   ├── stdio.ts              # stdio 传输
│   └── streamable-http.ts    # HTTP 传输(Express)
└── utils/
    └── formatter.ts          # 文章格式化(compact/standard/detailed)

故障排除

问题

解决方案

依赖缺失

npm install && npm run build

PubMed API 调用失败

检查网络;有 Key 时确认 Key 有效

Key 池全部不可用

检查 api-keys.json 中 Key 是否有效,60 秒后自动恢复

端口被占用

lsof -i :8745 查看,或设置 PORT=其他端口

Docker 健康检查失败

检查 .env 配置,docker logs pubmed-mcp


许可证

MIT License

Available Tools

5 tools
pubmed_extract_infoA
Read-onlyIdempotent

Extract specific structured sections from a PubMed article. Use when you need only certain aspects (author details, structured abstract, keywords, DOI) rather than the full record. More token-efficient than get_details for targeted extraction.

ParametersJSON Schema
NameRequiredDescriptionDefault
pmidYesPubMed article ID.
sectionsNoWhich sections to extract.

TDQS

A4/5.0
Behavior3/5

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

Annotations already declare readOnlyHint, openWorldHint, and idempotentHint, covering safety and side-effect expectations. The description adds context about token efficiency and the targeted nature of extraction, but does not disclose return format or further behavioral details. This is adequate but not rich beyond annotations.

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?

Two sentences, front-loaded with purpose, then usage guidance. No filler or redundancy. Every sentence contributes meaning.

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

Completeness4/5

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

Given the moderate complexity (2 params, no output schema, read-only), the description provides enough context: what it extracts, when to use, and how it compares to a sibling. It does not explain return values, but the annotations cover safety and the description conveys the core use case well.

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%: both 'pmid' and 'sections' have descriptive text in the schema. The description mentions examples of sections (authors, abstract, keywords, DOI) which echo the schema enums, adding no new meaning. Baseline 3 is appropriate since the schema handles parameter semantics fully.

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

Purpose5/5

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

The description clearly states the tool's function: 'Extract specific structured sections from a PubMed article.' It uses a specific verb ('extract') and resource ('sections from a PubMed article'), and differentiates from siblings by noting it is for partial data rather than the full record, explicitly contrasting with get_details.

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

Usage Guidelines4/5

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

The description provides explicit guidance on when to use: 'Use when you need only certain aspects… rather than the full record.' It also names the alternative (get_details) and highlights token efficiency. It does not explicitly state when not to use, but the 'when' scenario is clear enough.

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

pubmed_get_detailsA
Read-onlyIdempotent

Retrieve complete metadata for specific PubMed articles by PMID. Accepts a single PMID or array of PMIDs (up to 20). Returns full article records including abstract, authors, journal, DOI, MeSH terms. Use when you have specific PMIDs from a previous search or citation and need the full record.

ParametersJSON Schema
NameRequiredDescriptionDefault
pmidsYesSingle PMID string or array of PMIDs.
formatNoOutput format.standard

TDQS

A4.3/5.0
Behavior4/5

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

Annotations already declare read-only, open-world, and idempotent behavior. The description adds the limit of up to 20 PMIDs and the specific fields returned (abstract, authors, journal, DOI, MeSH terms), which is useful context beyond the annotations. It doesn't mention error handling, but the annotation coverage lowers the burden.

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 three sentences, front-loaded with the main action, and contains no filler or redundant information. Every sentence provides value.

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

Completeness5/5

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

Given the tool's moderate complexity, with 2 parameters and annotations but no output schema, the description covers the input format, limits, expected return content, and usage context. This is sufficient for an agent to invoke it correctly.

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 coverage is 100% with both parameters described. The description only restates what the schema already says (single or array, up to 20), adding no additional parameter-specific meaning. Baseline 3 is appropriate.

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

Purpose5/5

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

The description clearly states 'Retrieve complete metadata for specific PubMed articles by PMID', which uses a specific verb and resource. It distinguishes from siblings by focusing on PMID-based retrieval rather than searching, and mentions 'complete metadata' which is distinct from other tools.

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

Usage Guidelines4/5

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

It says 'Use when you have specific PMIDs from a previous search or citation and need the full record', providing clear context. However, it doesn't explicitly name alternative tools (e.g., pubmed_search) or state when not to use it, so it falls short of full explicit guidance.

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

pubmed_manage_cacheA
Destructive

View cache statistics or perform maintenance. Use action="stats" to check hit rates and storage usage. Use action="clean" to remove expired entries, or action="clear" to wipe a specific cache layer.

ParametersJSON Schema
NameRequiredDescriptionDefault
actionNoCache operation to perform.stats
targetNoWhich cache layer to operate on.all

TDQS

A4.4/5.0
Behavior4/5

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

Annotations already indicate destructiveHint=true. The description adds valuable nuance by showing that 'stats' is safe, 'clean' removes expired entries (moderate), and 'clear' wipes a cache layer (destructive). It clarifies the specific destructive behavior for each action, which is more granular than the single annotation flag.

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 two sentences, front-loaded with the core purpose, followed by concise action-specific guidance. Every word earns its place – no filler or redundancy.

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

Completeness4/5

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

Given the tool's simplicity (2 enum params, no output schema, annotations present), the description covers the key behavioral aspects: the three actions, their intent, and the existence of cache layers via 'target'. It could mention that 'clear' is irreversible or what 'stats' returns, but the current description is sufficient for basic correct use.

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

Parameters4/5

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

Schema coverage is 100% with enum parameters already explaining each field. The description adds semantics by mapping actions to real-world outcomes (checking hit rates, removing expired entries, wiping layers), which deepens the meaning beyond the generic 'Cache operation to perform.' This extra context helps the agent choose the right action without additional lookups.

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

Purpose5/5

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

The description starts with 'View cache statistics or perform maintenance,' clearly stating the tool's purpose as cache management. It explicitly distinguishes itself from sibling tools (search, details, extract, related) by focusing on internal DB cache operations. The actions are enumerated with specific outcomes (hit rates, storage usage, expired entries, wipe layer).

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

Usage Guidelines4/5

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

The description provides clear usage context by explaining when to use each action: 'stats' for hit rates and storage, 'clean' for removing expired entries, 'clear' for wiping a layer. While it doesn't explicitly mention alternatives to this tool, the sibling tools are obviously unrelated to cache management, making the intended use case clear.

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

TDQS

A4.3/5.0
Disambiguation4/5

Each tool has a clear primary purpose: search, fetch full records, extract specific fields, find related articles, and manage cache. However, pubmed_get_details and pubmed_extract_info could be confused by an agent, as both retrieve article information, though the descriptions differentiate full records from targeted extraction.

Naming Consistency5/5

All tool names follow a consistent pattern: 'pubmed_' prefix followed by a verb or verb_noun phrase (search, get_details, extract_info, find_related, manage_cache). The naming is uniform, snake_case, and clearly indicates the operation performed.

Tool Count5/5

Five tools is a well-scoped set for a PubMed MCP server, covering core literature search and retrieval without redundancy. The count feels appropriately moderate, not overwhelming or thin.

Completeness5/5

The toolset covers the full typical workflow: search for articles, retrieve full details, extract specific sections, discover related articles, and manage cache for efficiency. No obvious critical gaps exist for a literature search domain.

Maintenance

ActivityInactive
ResponsivenessSyncing

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • A
    license
    A
    quality
    D
    maintenance
    An MCP server that provides direct access to PubMed and PubMed Central via the NCBI E-utilities API. It enables AI models to search biomedical literature, retrieve detailed article metadata, and download open-access full texts.
    5
    MIT

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/PancrePal-xiaoyibao/mcp-pubmed-server-pancrpal'

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