search_similar_compounds
Find chemically similar compounds in PubChem using Tanimoto similarity. Input a SMILES string to discover molecules with structural resemblance for research and analysis.
Instructions
Find chemically similar compounds using Tanimoto similarity
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| smiles | Yes | SMILES string of the query molecule | |
| threshold | No | Similarity threshold (0-100, default: 90) | |
| max_records | No | Maximum number of results (1-10000, default: 100) |
Implementation Reference
- src/index.ts:981-1010 (handler)The handler function for 'search_similar_compounds' tool. Validates input using isValidSmilesArgs, performs POST request to PubChem similarity search endpoint with SMILES, threshold, and maxRecords, returns JSON response.private async handleSearchSimilarCompounds(args: any) { if (!isValidSmilesArgs(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid similarity search arguments'); } try { const threshold = args.threshold || 90; const maxRecords = args.max_records || 100; const response = await this.apiClient.post('/compound/similarity/smiles/JSON', { smiles: args.smiles, Threshold: threshold, MaxRecords: maxRecords, }); return { content: [ { type: 'text', text: JSON.stringify(response.data, null, 2), }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `Failed to search similar compounds: ${error instanceof Error ? error.message : 'Unknown error'}` ); } }
- src/index.ts:441-453 (registration)Registration of the 'search_similar_compounds' tool in the ListToolsRequestSchema response, including name, description, and input schema.{ name: 'search_similar_compounds', description: 'Find chemically similar compounds using Tanimoto similarity', inputSchema: { type: 'object', properties: { smiles: { type: 'string', description: 'SMILES string of the query molecule' }, threshold: { type: 'number', description: 'Similarity threshold (0-100, default: 90)', minimum: 0, maximum: 100 }, max_records: { type: 'number', description: 'Maximum number of results (1-10000, default: 100)', minimum: 1, maximum: 10000 }, }, required: ['smiles'], }, },
- src/index.ts:444-452 (schema)JSON Schema for input validation of the tool: requires 'smiles', optional 'threshold' (0-100) and 'max_records' (1-10000).inputSchema: { type: 'object', properties: { smiles: { type: 'string', description: 'SMILES string of the query molecule' }, threshold: { type: 'number', description: 'Similarity threshold (0-100, default: 90)', minimum: 0, maximum: 100 }, max_records: { type: 'number', description: 'Maximum number of results (1-10000, default: 100)', minimum: 1, maximum: 10000 }, }, required: ['smiles'], },
- src/index.ts:76-87 (helper)Helper validation function isValidSmilesArgs used in the handler to check input parameters matching the schema.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)) ); };