Skip to main content
Glama

search_by_smiles

Find chemical compounds in PubChem's database using SMILES string queries for exact 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 handler function that executes the search_by_smiles tool: validates input, queries PubChem API for exact SMILES match, retrieves CID and details if found.
    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, returned in ListToolsRequestSchema handler.
    {
      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)
    Registration/dispatch case in CallToolRequestSchema handler that routes calls to the search_by_smiles handler.
    case 'search_by_smiles':
      return await this.handleSearchBySmiles(args);
  • Helper function for validating input arguments to search_by_smiles (and similar tools).
    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 full burden. It states the tool searches for compounds by SMILES with exact matching, but doesn't disclose behavioral traits like what happens if no match is found, whether it's case-sensitive, if it requires authentication, rate limits, or what the output format might be. For a search tool with zero annotation coverage, this leaves significant gaps in understanding its behavior.

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 ('Search for compounds by SMILES string') and adds a crucial qualifier ('exact match'). Every word earns its place with no redundancy or unnecessary elaboration, 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 tool has no annotations, no output schema, and 1 parameter with full schema coverage, the description is incomplete. It adequately explains the purpose but fails to address key contextual aspects like what the search returns (e.g., compound IDs, properties, or just existence), error conditions, or performance characteristics. For a search tool in a chemistry context, more completeness is needed to guide effective use.

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 description adds minimal semantic context beyond the schema, which has 100% coverage with a clear parameter description. It mentions 'SMILES string' and 'exact match', reinforcing the parameter's purpose, but doesn't provide additional details like SMILES format requirements, validation rules, or examples. With high schema coverage, the baseline 3 is appropriate as the description doesn't significantly enhance parameter understanding.

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 verb ('Search') and resource ('compounds'), specifying the search method ('by SMILES string') and match type ('exact match'). It distinguishes from siblings like 'search_by_cas_number' or 'search_similar_compounds' by focusing on SMILES-based exact matching. However, it doesn't explicitly differentiate from 'search_compounds' which might be more general.

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

Usage Guidelines3/5

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

The description implies usage when searching with a SMILES string for exact matches, but provides no explicit guidance on when to use this tool versus alternatives like 'search_by_inchi' or 'search_similar_compounds'. It mentions 'exact match' which helps differentiate from similarity searches, but lacks clear when-not-to-use scenarios or prerequisites.

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