substructure_search
Search for chemical compounds containing specific molecular substructures using SMILES queries in the ChEMBL database.
Instructions
Find compounds containing specific substructures
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| smiles | Yes | SMILES string of the substructure query | |
| limit | No | Number of results to return (1-1000, default: 25) |
Implementation Reference
- src/index.ts:1788-1815 (handler)The handler function that executes the substructure_search tool. It validates input, queries the ChEMBL API substructure endpoint with the SMILES query, and returns the results as JSON.private async handleSubstructureSearch(args: any) { if (!isValidSubstructureSearchArgs(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid substructure search arguments'); } try { // ChEMBL substructure search using SMILES const response = await this.apiClient.get('/substructure/' + encodeURIComponent(args.smiles) + '.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 perform substructure search: ${error instanceof Error ? error.message : 'Unknown error'}` ); } }
- src/index.ts:686-696 (registration)Registration of the substructure_search tool in the ListTools response, including name, description, and input schema.name: 'substructure_search', description: 'Find compounds containing specific substructures', inputSchema: { type: 'object', properties: { smiles: { type: 'string', description: 'SMILES string of the substructure query' }, limit: { type: 'number', description: 'Number of results to return (1-1000, default: 25)', minimum: 1, maximum: 1000 }, }, required: ['smiles'], }, },
- src/index.ts:796-797 (registration)Dispatcher case in CallToolRequestSchema handler that routes to the substructure_search implementation.case 'substructure_search': return await this.handleSubstructureSearch(args);
- src/index.ts:114-124 (schema)Type guard function for validating input arguments to the substructure_search tool.const isValidSubstructureSearchArgs = ( args: any ): args is { smiles: string; limit?: number } => { return ( typeof args === 'object' && args !== null && typeof args.smiles === 'string' && args.smiles.length > 0 && (args.limit === undefined || (typeof args.limit === 'number' && args.limit > 0 && args.limit <= 1000)) ); };