PU

PubChem Drug Information MCP Server

Extract drug information from the PubChem API using the MCP server to retrieve chemical, bioactivity, and safety data quickly and reliably.

Quick Install
npx -y @sssjiang/pubchem_mcp_server

Overview

The PubChem Drug Information MCP Server provides a lightweight HTTP service that wraps the PubChem REST APIs and exposes chemical, bioactivity, and safety information in a consistent, machine-friendly format compatible with Model Context Protocol (MCP) consumers. It acts as an intermediary between PubChem and applications (including LLM-based agents) that need quick, reliable access to structured drug-related data without having to orchestrate multiple PubChem endpoints.

This server is useful for developers building tools that need on-demand compound summaries, activity assays, toxicity flags, or downloadable property tables. By normalizing PubChem responses, caching common queries, and presenting results as predictable JSON objects, the MCP server simplifies integration into pipelines, interactive agents, and dashboards.

Features

  • Unified MCP-compatible endpoints for compound data, bioassays, and safety summaries
  • Query by CID, InChIKey, SMILES, or common name
  • Aggregated chemical properties (formula, weight, synonyms, SMILES)
  • Bioactivity and assay summaries (counts, top assays, IC50/EC50 examples)
  • Safety information extraction (toxicity flags, LD50 where available)
  • Optional caching and configurable TTL to reduce PubChem load
  • Docker-ready and simple local run via Python

Installation / Configuration

Prerequisites: Python 3.9+ and Docker (optional).

Clone and install:

git clone https://github.com/sssjiang/pubchem_mcp_server.git
cd pubchem_mcp_server
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt

Environment configuration (.env example):

PORT=8080
LOG_LEVEL=info
CACHE_TTL=3600            # seconds
PUBCHEM_API_BASE=https://pubchem.ncbi.nlm.nih.gov/rest/pug

Run locally (example using Uvicorn):

uvicorn mcp_server.main:app --host 0.0.0.0 --port ${PORT:-8080} --reload

Docker build and run:

docker build -t pubchem_mcp_server:latest .
docker run -p 8080:8080 \
  -e PORT=8080 \
  -e CACHE_TTL=3600 \
  pubchem_mcp_server:latest

Available Tools / Resources

The server exposes a small set of MCP-style endpoints that return JSON objects optimized for context injection into models or tools.

Endpoint summary:

MethodPathQuery paramsPurpose
GET/mcp/compoundcid, inchikey, smiles, nameCompound summary — properties, synonyms, structure strings
GET/mcp/bioassaycid, inchikeyBioactivity summary — assay counts, top activity values
GET/mcp/safetycid, inchikeySafety/toxicity summary — LD50, toxicity flags, warnings
GET/mcp/searchqSimple search returning candidate CIDs for free-text queries
POST/mcp/batchcids:[]Batch retrieval for multiple CIDs (aggregated)

Example compound response (abridged):

{
  "cid": 2244,
  "name": "Aspirin",
  "formula": "C9H8O4",
  "molecular_weight": 180.16,
  "smiles": "CC(=O)OC1=CC=CC=C1C(=O)O",
  "synonyms": ["Acetylsalicylic acid", "ASA"],
  "properties": { "xlogp": 1.19, "hbond_donor": 1, "hbond_acceptor": 4 }
}

Use Cases

  1. LLM augmentation for scientific chatbots

    • An agent can call /mcp/compound?cid=2244 to retrieve structured context for answering questions about aspirin (structure, synonyms, molecular weight) and then augment answers with assay or safety summaries from /mcp/bioassay and /mcp/safety.
  2. Automated safety checks in pipelines

    • Before adding a compound to a screening list, a pipeline POSTs a batch of CIDs to /mcp/batch and consumes safety warnings to filter or flag problematic entries.
  3. Interactive dashboards and notebooks

    • Use the search endpoint to map user-entered names to CIDs, then fetch properties and activity summaries for visualization in dashboards or Jupyter notebooks.

Concrete examples

  • cURL: fetch compound summary for aspirin (CID 2244)
curl "http://localhost:8080/mcp/compound?cid=2244"
  • Python: get bioassay summary and print top assay count
import requests
r = requests.get("http://localhost:8080/mcp/bioassay", params={"cid": 2244})
data = r.json()
print("Total assays:", data.get("total_assays"))
print("Top activity example:", data.get("top_activity"))
  • Batch request (JSON POST)
curl -X POST http://localhost:8080/mcp/batch \
  -H "Content-Type: application/json" \
  -d '{"cids": [2244, 1983, 12345]}'

Tips for Developers

  • PubChem rate limits are modest; enable caching (CACHE_TTL) in production to reduce repeated lookups.
  • Normalize identifiers early: use /mcp/search for free-text mapping to CIDs before downstream calls.
  • Responses are designed to be small and model-friendly; fetch additional raw PubChem records only if you need full assay tables or documents.

Repository and issues: https://github.com/sssjiang/pubchem_mcp_server

This server is intended as a bridge between PubChem’s rich datasets and applications that require concise, structured drug context for automation, agents, and developer tools.