PubChem MCP Server

PubChem MCP Server

Enables AI agents and applications to search, retrieve, and analyze chemical compounds, substances, and bioassays from PubChem's vast chemical information database through comprehensive tools for chemical research and discovery.

Category
访问服务器

README

PubChem MCP Server

TypeScript Model Context Protocol Version License Status GitHub

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
pubchem_search_compound_by_identifier Searches for PubChem Compound IDs (CIDs) using a common chemical identifier. - Search by name, smiles, or inchikey.<br/>- The primary entry point for most compound-based workflows.
pubchem_fetch_compound_properties Fetches a list of specified physicochemical properties for one or more CIDs. - Retrieve properties like MolecularWeight, XLogP, IUPACName, etc.<br/>- Essential for gathering detailed chemical data in bulk.
pubchem_get_compound_image Fetches a 2D image of a compound's structure for a given CID. - Returns the raw image data as a binary blob.<br/>- Supports small (100x100) and large (300x300) image sizes.
pubchem_search_compounds_by_structure Performs a structural search using a SMILES string or a CID as the query. - Supports substructure, superstructure, and identity search types.<br/>- Essential for finding structurally related compounds.
pubchem_search_compounds_by_similarity Finds compounds with a similar 2D structure to a query compound. - Based on a Tanimoto similarity score.<br/>- Search by smiles or cid.<br/>- Configurable threshold and maxRecords.
pubchem_search_compounds_by_formula Finds PubChem Compound IDs (CIDs) that match a given molecular formula. - Supports exact matches and formulas with additional elements.<br/>- Configurable maxRecords.
pubchem_fetch_substance_details Retrieves details for a given PubChem Substance ID (SID). - Fetches synonyms, source, dates, and related CIDs.
pubchem_fetch_assay_summary Fetches a detailed summary for a specific PubChem BioAssay ID (AID). - Includes name, description, source, and statistics.
pubchem_search_assays_by_target Finds PubChem BioAssay IDs (AIDs) associated with a specific biological target. - Search by genesymbol or proteinname.
pubchem_fetch_compound_xrefs Fetches external cross-references (XRefs) for a given CID. - Retrieve RegistryID, PubMedID, PatentID, etc.<br/>- 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 zod for 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 Dockerfile for 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)

npm install @cyanheads/pubchem-mcp-server

Alternatively Install from Source

  1. Clone the repository:

    git clone https://github.com/cyanheads/pubchem-mcp-server.git
    cd pubchem-mcp-server
    
  2. Install dependencies:

    npm install
    
  3. Build 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
MCP_TRANSPORT_TYPE Transport mechanism: 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 list of allowed origins for CORS (if MCP_TRANSPORT_TYPE=http). (none)
MCP_LOG_LEVEL Logging level (debug, info, notice, warning, error, crit, alert, emerg). info
LOG_OUTPUT_MODE Logging output mode: file or stdout. file
MCP_AUTH_MODE Authentication mode for HTTP: jwt or oauth. jwt
MCP_AUTH_SECRET_KEY Required for jwt auth. Minimum 32-character secret key for JWT authentication. (none)
LOGS_DIR Directory for log file storage (if LOG_OUTPUT_MODE=file). logs/

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:

{
  "mcpServers": {
    "pubchem-mcp-server": {
      "command": "npx",
      "args": ["@cyanheads/pubchem-mcp-server"],
      "env": {},
      "disabled": false,
      "autoApprove": []
    }
  }
}

Project Structure

The codebase follows a modular structure within the src/ directory:

src/
├── index.ts              # Entry point: Initializes and starts the server
├── config/               # Configuration loading (env vars, package info)
│   └── index.ts
├── mcp-server/           # Core MCP server logic and capability registration
│   ├── server.ts         # Server setup, capability registration
│   ├── transports/       # Transport handling (stdio, http)
│   └── tools/            # MCP Tool implementations (subdirs per tool)
├── services/             # External service integrations
│   └── pubchem/          # PubChem API client
├── types-global/         # Shared TypeScript type definitions
└── utils/                # Common utility functions (logger, error handler, etc.)

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
pubchem_search_compound_by_identifier Searches for CIDs using an identifier (name, SMILES, InChIKey). identifierType, identifier
pubchem_fetch_compound_properties Fetches physicochemical properties for one or more CIDs. cids, properties
pubchem_get_compound_image Fetches a 2D structural image for a given CID. cid, size?
pubchem_search_compounds_by_structure Performs a structural search (substructure, superstructure, identity). searchType, query, queryType, maxRecords?
pubchem_search_compounds_by_similarity Finds compounds with a similar 2D structure to a query. query, queryType, threshold?, maxRecords?
pubchem_search_compounds_by_formula Finds CIDs that match a given molecular formula. formula, allowOtherElements?, maxRecords?
pubchem_fetch_substance_details Retrieves details for a given Substance ID (SID). sid
pubchem_fetch_assay_summary Fetches a summary for a specific BioAssay ID (AID). aid
pubchem_search_assays_by_target Finds BioAssay IDs (AIDs) associated with a biological target. targetType, targetQuery
pubchem_fetch_compound_xrefs Fetches external cross-references for a given CID. cid, xrefTypes, page?, pageSize?

Note: All tools support comprehensive error handling and return structured JSON responses.

Development

Build and Test

# Build the project (compile TS to JS in dist/ and make executable)
npm run build

# Test the server locally using the MCP inspector tool (stdio transport)
npm run inspector

# Test the server locally using the MCP inspector tool (http transport)
npm run inspector:http

# Clean build artifacts
npm run clean

# Generate a file tree representation for documentation
npm run tree

# Clean build artifacts and then rebuild the project
npm run rebuild

# Format code with Prettier
npm run format

# Start the server using stdio (default)
npm start
# Or explicitly:
npm run start:stdio

# Start the server using HTTP transport
npm run start:http

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.


<div align="center"> Built with the <a href="https://modelcontextprotocol.io/">Model Context Protocol</a> </div>

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选