Skip to main content
Glama

search_by_smiles

Find chemical compounds in PubChem using SMILES string queries to identify exact molecular matches and access compound data.

Instructions

Search for compounds by SMILES string (exact match)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
smilesYesSMILES string of the query molecule

Implementation Reference

  • Executes the tool logic: validates SMILES input, queries PubChem API for exact match CID, fetches compound properties, returns JSON response or no-match message.
    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'}` ); } }
  • Defines the input schema for the search_by_smiles tool, requiring a 'smiles' string parameter.
    inputSchema: { type: 'object', properties: { smiles: { type: 'string', description: 'SMILES string of the query molecule' }, }, required: ['smiles'], },
  • src/index.ts:396-405 (registration)
    Registers the search_by_smiles tool in the list returned by ListToolsRequestSchema, including name, description, and 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)
    Switch case in CallToolRequestSchema handler that routes calls to the specific handler method.
    case 'search_by_smiles': return await this.handleSearchBySmiles(args);
  • Type guard function that validates input arguments for SMILES-based searches (used in handler).
    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)) ); };

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