Skip to main content
Glama

search_compounds

Find chemical compounds in PubChem by name, CAS number, formula, or identifier to access detailed chemical information and properties.

Instructions

Search PubChem database for compounds by name, CAS number, formula, or identifier

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query (compound name, CAS, formula, or identifier)
search_typeNoType of search to perform (default: name)
max_recordsNoMaximum number of results (1-10000, default: 100)

Implementation Reference

  • The handler function that executes the search_compounds tool. Validates input, queries PubChem API for compound CIDs by various search types, fetches details for top results, and returns formatted JSON response.
    private async handleSearchCompounds(args: any) {
      if (!isValidCompoundSearchArgs(args)) {
        throw new McpError(ErrorCode.InvalidParams, 'Invalid compound search arguments');
      }
    
      try {
        const searchType = args.search_type || 'name';
        const maxRecords = args.max_records || 100;
    
        const response = await this.apiClient.get(`/compound/${searchType}/${encodeURIComponent(args.query)}/cids/JSON`, {
          params: {
            MaxRecords: maxRecords,
          },
        });
    
        if (response.data?.IdentifierList?.CID?.length > 0) {
          const cids = response.data.IdentifierList.CID.slice(0, 10);
          const detailsResponse = await this.apiClient.get(`/compound/cid/${cids.join(',')}/property/MolecularFormula,MolecularWeight,CanonicalSMILES,IUPACName/JSON`);
    
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify({
                  query: args.query,
                  search_type: searchType,
                  total_found: response.data.IdentifierList.CID.length,
                  details: detailsResponse.data,
                }, null, 2),
              },
            ],
          };
        }
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({ message: 'No compounds found', query: args.query }, null, 2),
            },
          ],
        };
      } catch (error) {
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to search compounds: ${error instanceof Error ? error.message : 'Unknown error'}`
        );
      }
    }
  • Input schema defining parameters for search_compounds: query (required string), search_type (enum), max_records (number 1-10000).
    inputSchema: {
      type: 'object',
      properties: {
        query: { type: 'string', description: 'Search query (compound name, CAS, formula, or identifier)' },
        search_type: { type: 'string', enum: ['name', 'smiles', 'inchi', 'sdf', 'cid', 'formula'], description: 'Type of search to perform (default: name)' },
        max_records: { type: 'number', description: 'Maximum number of results (1-10000, default: 100)', minimum: 1, maximum: 10000 },
      },
      required: ['query'],
    },
  • src/index.ts:370-382 (registration)
    Registration of search_compounds tool in the ListTools response, including name, description, and input schema.
    {
      name: 'search_compounds',
      description: 'Search PubChem database for compounds by name, CAS number, formula, or identifier',
      inputSchema: {
        type: 'object',
        properties: {
          query: { type: 'string', description: 'Search query (compound name, CAS, formula, or identifier)' },
          search_type: { type: 'string', enum: ['name', 'smiles', 'inchi', 'sdf', 'cid', 'formula'], description: 'Type of search to perform (default: name)' },
          max_records: { type: 'number', description: 'Maximum number of results (1-10000, default: 100)', minimum: 1, maximum: 10000 },
        },
        required: ['query'],
      },
    },
  • src/index.ts:740-741 (registration)
    Dispatcher case in CallToolRequest handler that routes search_compounds calls to the handleSearchCompounds method.
    case 'search_compounds':
      return await this.handleSearchCompounds(args);
  • Type guard function for validating input arguments to search_compounds handler.
    const isValidCompoundSearchArgs = (
      args: any
    ): args is { query: string; search_type?: string; max_records?: number } => {
      return (
        typeof args === 'object' &&
        args !== null &&
        typeof args.query === 'string' &&
        args.query.length > 0 &&
        (args.search_type === undefined || ['name', 'smiles', 'inchi', 'sdf', 'cid', 'formula'].includes(args.search_type)) &&
        (args.max_records === undefined || (typeof args.max_records === 'number' && args.max_records > 0 && args.max_records <= 10000))
      );
    };
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions the search action but fails to describe key behavioral traits like rate limits, authentication needs, error handling, or the format of results (e.g., pagination, data structure). For a search tool with no annotation coverage, this leaves significant gaps in understanding its operation.

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 a single, efficient sentence that front-loads the core functionality without unnecessary details. It uses clear language and avoids redundancy, making it easy to parse quickly while conveying the essential purpose.

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

Completeness2/5

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

Given the lack of annotations and output schema, the description is incomplete for a search tool with 3 parameters. It does not explain the return values, result format, or behavioral aspects like performance or limitations. While the schema covers inputs well, the overall context for effective tool use is insufficient, especially compared to sibling tools that might offer more specialized functionality.

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%, meaning the input schema already documents all parameters thoroughly. The description adds minimal value by listing searchable attributes ('name, CAS number, formula, or identifier'), which partially overlaps with the 'query' and 'search_type' schema descriptions. It does not provide additional syntax, examples, or constraints beyond what the schema specifies, meeting the baseline for high schema coverage.

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

Purpose4/5

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

The description clearly states the action ('Search PubChem database for compounds') and the searchable attributes ('by name, CAS number, formula, or identifier'), making the purpose specific and understandable. However, it does not explicitly differentiate from sibling tools like 'search_by_cas_number' or 'search_by_smiles', which perform similar but more specialized searches, leaving some ambiguity in tool selection.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives, such as the more specific sibling tools (e.g., 'search_by_cas_number' for CAS-only searches). It lacks context on prerequisites, exclusions, or recommended scenarios, offering only a basic functional statement without usage direction.

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

Install Server

Other Tools

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/k-lordbodin7/PubChem-MCP-Server'

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