Skip to main content
Glama
Augmented-Nature

Unofficial PubChem MCP Server

search_by_smiles

Find chemical compounds in PubChem using their SMILES string representation for exact molecular structure matching.

Instructions

Search for compounds by SMILES string (exact match)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
smilesYesSMILES string of the query molecule

Implementation Reference

  • The main handler function for the 'search_by_smiles' tool. It validates input using isValidSmilesArgs, queries PubChem API for exact SMILES match to get CID, then fetches compound details (formula, weight, SMILES, IUPAC name), and returns formatted JSON response or error if no match.
    private async handleSearchBySmiles(args: any) {
      if (!isValidSmilesArgs(args)) {
        throw new McpError(ErrorCode.InvalidParams, 'Invalid SMILES arguments');
      }
    
      try {
        const response = await this.apiClient.get(`/compound/smiles/${encodeURIComponent(args.smiles)}/cids/JSON`);
    
        if (response.data?.IdentifierList?.CID?.length > 0) {
          const cid = response.data.IdentifierList.CID[0];
          const detailsResponse = await this.apiClient.get(`/compound/cid/${cid}/property/MolecularFormula,MolecularWeight,CanonicalSMILES,IUPACName/JSON`);
    
          return {
            content: [
              {
                type: 'text',
                text: JSON.stringify({
                  query_smiles: args.smiles,
                  found_cid: cid,
                  details: detailsResponse.data,
                }, null, 2),
              },
            ],
          };
        }
    
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify({ message: 'No exact match found', query_smiles: args.smiles }, null, 2),
            },
          ],
        };
      } catch (error) {
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to search by SMILES: ${error instanceof Error ? error.message : 'Unknown error'}`
        );
      }
    }
  • The input schema definition for the 'search_by_smiles' tool, specifying that it requires a 'smiles' string parameter.
    {
      name: 'search_by_smiles',
      description: 'Search for compounds by SMILES string (exact match)',
      inputSchema: {
        type: 'object',
        properties: {
          smiles: { type: 'string', description: 'SMILES string of the query molecule' },
        },
        required: ['smiles'],
      },
    },
  • src/index.ts:744-745 (registration)
    The switch case in the CallToolRequestSchema handler that registers and dispatches calls to the search_by_smiles handler function.
    case 'search_by_smiles':
      return await this.handleSearchBySmiles(args);
  • Input validation helper function isValidSmilesArgs used by the handler to validate arguments before API call.
    const isValidSmilesArgs = (
      args: any
    ): args is { smiles: string; threshold?: number; max_records?: number } => {
      return (
        typeof args === 'object' &&
        args !== null &&
        typeof args.smiles === 'string' &&
        args.smiles.length > 0 &&
        (args.threshold === undefined || (typeof args.threshold === 'number' && args.threshold >= 0 && args.threshold <= 100)) &&
        (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 'exact match', which hints at search behavior, but doesn't cover critical aspects like permissions, rate limits, response format, pagination, or error handling. For a search tool with zero annotation coverage, this leaves significant gaps.

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 extremely concise—a single sentence that directly states the tool's function. It's front-loaded with the core purpose and wastes no words, making it easy to parse quickly.

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. It doesn't explain what the search returns (e.g., compound IDs, properties, or just existence), how results are formatted, or any behavioral traits. For a tool with no structured metadata, more context is needed to be fully helpful.

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%, so the schema fully documents the 'smiles' parameter. The description adds no additional parameter details beyond what's in the schema. According to guidelines, when schema coverage is high (>80%), the baseline score is 3 even with no param info in the description.

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 tool's purpose: 'Search for compounds by SMILES string (exact match)'. It specifies the verb ('Search'), resource ('compounds'), and method ('by SMILES string'), but doesn't explicitly differentiate from sibling tools like 'search_by_inchi' or 'search_by_cas_number' beyond the SMILES focus.

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. It doesn't mention sibling tools like 'search_by_inchi', 'search_by_cas_number', or 'search_compounds', nor does it specify any prerequisites, exclusions, or contextual usage scenarios.

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/Augmented-Nature/Augmented-Nature-PubChem-MCP-Server'

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