Skip to main content
Glama
Augmented-Nature

PubChem MCP Server

search_by_smiles

Find exact chemical compound matches using SMILES strings from PubChem's extensive database. Ideal for structure-based searches in chemical research and analysis.

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. Performs an exact match search using PubChem's SMILES endpoint, retrieves the first matching CID, fetches compound details (formula, weight, SMILES, IUPAC name), and returns formatted JSON response. Includes input validation using isValidSmilesArgs.
    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'}`
        );
      }
    }
  • Input schema definition for the 'search_by_smiles' tool, specifying a required 'smiles' string parameter.
    inputSchema: {
      type: 'object',
      properties: {
        smiles: { type: 'string', description: 'SMILES string of the query molecule' },
      },
      required: ['smiles'],
    },
  • src/index.ts:395-405 (registration)
    Tool registration in the ListToolsRequestSchema response, defining name, description, and input schema.
    {
      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)
    Dispatch case in the main CallToolRequestSchema switch statement that routes 'search_by_smiles' calls to the handler.
    case 'search_by_smiles':
      return await this.handleSearchBySmiles(args);
  • Validation helper function used in handleSearchBySmiles (and similar tools) to check input arguments for SMILES string and optional threshold/max_records.
    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?

With no annotations provided, the description carries full burden for behavioral disclosure. It states it's a search operation but doesn't describe what happens if no match is found, whether it's case-sensitive, if it returns multiple results, or any performance characteristics. The 'exact match' hint is minimal behavioral context.

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 with zero wasted words. It's appropriately sized for a simple search tool and front-loads the essential information about what the tool does.

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?

For a search tool with no annotations and no output schema, the description is insufficient. It doesn't explain what format the results will be in, whether it returns compound IDs or full records, or any limitations. Given the rich ecosystem of sibling tools, more context about this tool's specific role is needed.

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?

The schema has 100% description coverage with the parameter 'smiles' clearly documented as 'SMILES string of the query molecule'. The description adds no additional parameter semantics beyond what the schema already provides, so it meets 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 for compounds') and the resource ('by SMILES string'), with the specific constraint 'exact match' that distinguishes it from similarity-based searches. However, it doesn't explicitly differentiate from sibling tools like 'search_by_inchi' or 'search_compounds' which might have overlapping functionality.

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 like 'search_by_inchi', 'search_similar_compounds', or 'substructure_search'. It mentions 'exact match' but doesn't explain what this means in practice or when other search methods would be more appropriate.

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

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

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