search_similar_compounds
Find chemically similar compounds to a query molecule using Tanimoto similarity, with configurable thresholds and result limits.
Instructions
Find chemically similar compounds using Tanimoto similarity
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| smiles | Yes | SMILES string of the query molecule | |
| similarity | No | Similarity threshold (0-1, default: 0.7) | |
| limit | No | Number of results to return (1-1000, default: 25) |
Implementation Reference
- src/index.ts:935-963 (handler)The main handler function that implements the 'search_similar_compounds' tool logic. It validates input, calls the ChEMBL similarity search API using the provided SMILES and similarity threshold, and returns the results.private async handleSearchSimilarCompounds(args: any) { if (!isValidSimilaritySearchArgs(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid similarity search arguments'); } try { // ChEMBL similarity search using SMILES const similarity = args.similarity !== undefined ? Math.round(args.similarity * 100) : 70; const response = await this.apiClient.get('/similarity/' + encodeURIComponent(args.smiles) + '/' + similarity + '.json', { params: { limit: args.limit || 25, }, }); 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:445-456 (schema)The input schema definition for the 'search_similar_compounds' tool, registered in the ListTools handler. Defines parameters: smiles (required), similarity, limit.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' }, similarity: { type: 'number', description: 'Similarity threshold (0-1, default: 0.7)', minimum: 0, maximum: 1 }, limit: { type: 'number', description: 'Number of results to return (1-1000, default: 25)', minimum: 1, maximum: 1000 }, }, required: ['smiles'], }, },
- src/index.ts:753-754 (registration)The switch case in the CallToolRequestSchema handler that dispatches calls to the search_similar_compounds tool to its handler function.case 'search_similar_compounds': return await this.handleSearchSimilarCompounds(args);
- src/index.ts:101-112 (helper)Type guard and validation function for the input arguments of the search_similar_compounds tool.const isValidSimilaritySearchArgs = ( args: any ): args is { smiles: string; similarity?: number; limit?: number } => { return ( typeof args === 'object' && args !== null && typeof args.smiles === 'string' && args.smiles.length > 0 && (args.similarity === undefined || (typeof args.similarity === 'number' && args.similarity >= 0 && args.similarity <= 1)) && (args.limit === undefined || (typeof args.limit === 'number' && args.limit > 0 && args.limit <= 1000)) ); };