Provides access to PubChem's chemical information database, enabling searches for chemical compounds by identifier, structure, similarity, and molecular formula. Retrieves compound properties, structural images, substance details, bioassay summaries, and cross-references to external databases including PubMed.
PubChem MCP Server
Empower your AI agents and scientific tools with seamless PubChem integration!
An MCP (Model Context Protocol) server providing comprehensive access to PubChem's vast chemical information database. Enables LLMs and AI agents to search, retrieve, and analyze chemical compounds, substances, and bioassays through the PubChem PUG REST API.
Built on the cyanheads/mcp-ts-template, this server follows a modular architecture with robust error handling, logging, and security features.
🚀 Core Capabilities: PubChem Tools 🛠️
This server equips your AI with specialized tools to interact with PubChem:
Tool Name | Description | Key Features |
Searches for PubChem Compound IDs (CIDs) using a common chemical identifier. | - Search by
,
, or
. - The primary entry point for most compound-based workflows. | |
Fetches a list of specified physicochemical properties for one or more CIDs. | - Retrieve properties like
,
,
, etc. - Essential for gathering detailed chemical data in bulk. | |
Fetches a 2D image of a compound's structure for a given CID. | - Returns the raw image data as a binary blob. - Supports
(100x100) and
(300x300) image sizes. | |
Performs a structural search using a SMILES string or a CID as the query. | - Supports
,
, and
search types. - Essential for finding structurally related compounds. | |
Finds compounds with a similar 2D structure to a query compound. | - Based on a Tanimoto similarity score. - Search by
or
. - Configurable
and
. | |
Finds PubChem Compound IDs (CIDs) that match a given molecular formula. | - Supports exact matches and formulas with additional elements. - Configurable
. | |
Retrieves details for a given PubChem Substance ID (SID). | - Fetches synonyms, source, dates, and related CIDs. | |
Fetches a detailed summary for a specific PubChem BioAssay ID (AID). | - Includes name, description, source, and statistics. | |
Finds PubChem BioAssay IDs (AIDs) associated with a specific biological target. | - Search by
or
. | |
Fetches external cross-references (XRefs) for a given CID. | - Retrieve
,
,
, etc. - Supports pagination for large result sets. |
Table of Contents
| Overview | Features | Installation |
| Configuration | Project Structure |
| Tools | Development | License |
Overview
The PubChem MCP Server acts as a bridge, allowing applications (MCP Clients) that understand the Model Context Protocol (MCP) – like advanced AI assistants (LLMs), IDE extensions, or custom research tools – to interact directly and efficiently with PubChem's vast chemical database.
Instead of complex API integration or manual searches, your tools can leverage this server to:
Automate chemical research: Search for compounds, fetch detailed properties, find similar structures, and analyze bioassay results programmatically.
Gain chemical insights: Access detailed compound data, substance information, and bioassay metadata without leaving the host application.
Integrate PubChem into AI-driven science: Enable LLMs to conduct chemical research, analyze structure-activity relationships, and support evidence-based discovery.
Built on the robust mcp-ts-template, this server provides a standardized, secure, and efficient way to expose PubChem functionality via the MCP standard. It achieves this by integrating with the PubChem PUG REST API, ensuring compliance with rate limits and providing comprehensive error handling.
Developer Note: This repository includes a .clinerules file that serves as a developer cheat sheet for your LLM coding agent with quick reference for the codebase patterns, file locations, and code snippets.
Features
Core Utilities
Leverages the robust utilities provided by the mcp-ts-template:
Logging: Structured, configurable logging (file rotation, stdout JSON, MCP notifications) with sensitive data redaction.
Error Handling: Centralized error processing, standardized error types (
McpError), and automatic logging.Configuration: Environment variable loading (
dotenv) with comprehensive validation.Input Validation/Sanitization: Uses
zodfor schema validation and custom sanitization logic.Request Context: Tracking and correlation of operations via unique request IDs using
AsyncLocalStorage.Type Safety: Strong typing enforced by TypeScript and Zod schemas.
HTTP Transport: High-performance HTTP server using Hono, featuring session management with garbage collection and CORS support.
Authentication: Robust authentication layer supporting JWT and OAuth 2.1, with fine-grained scope enforcement.
Deployment: Multi-stage
Dockerfilefor creating small, secure production images with native dependency support.
PubChem Integration
PubChem PUG REST Integration: Comprehensive access to the PubChem API via a dedicated, rate-limited client.
Advanced Search Capabilities: Search by identifier, structure, similarity, and molecular formula.
Full Compound Data: Retrieve complete compound properties, including physicochemical data, names, and identifiers.
Substance and Assay Information: Fetch detailed records for substances (SIDs) and bioassays (AIDs).
Cross-Referencing: Find links to other databases like PubMed, patent registries, and gene databases.
Image Generation: Directly fetch 2D structural images of compounds.
Installation
Prerequisites
Install via npm (recommended)
Alternatively Install from Source
Clone the repository:
git clone https://github.com/cyanheads/pubchem-mcp-server.git cd pubchem-mcp-serverInstall dependencies:
npm installBuild the project:
npm run build *or npm run rebuild*
Configuration
Environment Variables
Configure the server using environment variables. These environmental variables are set within your MCP client config/settings (e.g. cline_mcp_settings.json for Cline).
Variable | Description | Default |
| Transport mechanism:
or
. |
|
| Port for the HTTP server (if
). |
|
| Host address for the HTTP server (if
). |
|
| Comma-separated list of allowed origins for CORS (if
). | (none) |
| Logging level (
,
,
,
,
,
,
,
). |
|
| Logging output mode:
or
. |
|
| Authentication mode for HTTP:
or
. |
|
| Required for Minimum 32-character secret key for JWT authentication. | (none) |
| Directory for log file storage (if
). |
|
Note: The PubChem API does not require an API key for basic use, so no key is needed in the environment configuration.
MCP Client Settings
Add the following to your MCP client's configuration file (e.g., cline_mcp_settings.json). This configuration uses npx to run the server, which will automatically install the package if not already present:
Project Structure
The codebase follows a modular structure within the src/ directory:
For a detailed file tree, run npm run tree or see docs/tree.md.
Tools
The PubChem MCP Server provides a comprehensive suite of tools for chemical information retrieval, callable via the Model Context Protocol.
Tool Name | Description | Key Arguments |
| Searches for CIDs using an identifier (name, SMILES, InChIKey). |
,
|
| Fetches physicochemical properties for one or more CIDs. |
,
|
| Fetches a 2D structural image for a given CID. |
,
|
| Performs a structural search (substructure, superstructure, identity). |
,
,
,
|
| Finds compounds with a similar 2D structure to a query. |
,
,
,
|
| Finds CIDs that match a given molecular formula. |
,
,
|
| Retrieves details for a given Substance ID (SID). |
|
| Fetches a summary for a specific BioAssay ID (AID). |
|
| Finds BioAssay IDs (AIDs) associated with a biological target. |
,
|
| Fetches external cross-references for a given CID. |
,
,
,
|
Note: All tools support comprehensive error handling and return structured JSON responses.
Development
Build and Test
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.