advanced_search
Perform complex chemical and biological data queries on the ChEMBL MCP Server using multiple filters like molecular weight, LogP, hydrogen bond donors, and acceptors to retrieve precise results.
Instructions
Complex queries with multiple chemical and biological filters
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Number of results to return (1-1000, default: 25) | |
| max_hba | No | Maximum hydrogen bond acceptors | |
| max_hbd | No | Maximum hydrogen bond donors | |
| max_logp | No | Maximum LogP value | |
| max_mw | No | Maximum molecular weight (Da) | |
| min_logp | No | Minimum LogP value | |
| min_mw | No | Minimum molecular weight (Da) |
Implementation Reference
- src/index.ts:1913-1961 (handler)The handler function that executes the 'advanced_search' tool. It validates input using isValidPropertyFilterArgs, builds a filter query for ChEMBL API based on molecular properties (MW, logP, HBD, HBA), fetches matching molecules, and returns the filtered results.private async handleAdvancedSearch(args: any) { if (!isValidPropertyFilterArgs(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid advanced search arguments'); } try { // Build filter query for ChEMBL API const filters: string[] = []; if (args.min_mw !== undefined) { filters.push(`molecule_properties__mw_freebase__gte=${args.min_mw}`); } if (args.max_mw !== undefined) { filters.push(`molecule_properties__mw_freebase__lte=${args.max_mw}`); } if (args.min_logp !== undefined) { filters.push(`molecule_properties__alogp__gte=${args.min_logp}`); } if (args.max_logp !== undefined) { filters.push(`molecule_properties__alogp__lte=${args.max_logp}`); } if (args.max_hbd !== undefined) { filters.push(`molecule_properties__hbd__lte=${args.max_hbd}`); } if (args.max_hba !== undefined) { filters.push(`molecule_properties__hba__lte=${args.max_hba}`); } const filterString = filters.join('&'); const response = await this.apiClient.get(`/molecule.json?${filterString}&limit=${args.limit || 25}`); return { content: [ { type: 'text', text: JSON.stringify({ filters: args, results: response.data, }, null, 2), }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `Failed to perform advanced search: ${error instanceof Error ? error.message : 'Unknown error'}` ); } }
- src/index.ts:720-735 (schema)The tool definition in the ListTools response, including name, description, and inputSchema defining the parameters for property-based filtering.name: 'advanced_search', description: 'Complex queries with multiple chemical and biological filters', inputSchema: { type: 'object', properties: { min_mw: { type: 'number', description: 'Minimum molecular weight (Da)', minimum: 0 }, max_mw: { type: 'number', description: 'Maximum molecular weight (Da)', minimum: 0 }, min_logp: { type: 'number', description: 'Minimum LogP value' }, max_logp: { type: 'number', description: 'Maximum LogP value' }, max_hbd: { type: 'number', description: 'Maximum hydrogen bond donors', minimum: 0 }, max_hba: { type: 'number', description: 'Maximum hydrogen bond acceptors', minimum: 0 }, limit: { type: 'number', description: 'Number of results to return (1-1000, default: 25)', minimum: 1, maximum: 1000 }, }, required: [], }, },
- src/index.ts:802-803 (registration)The switch case in the CallToolRequestSchema handler that routes calls to the 'advanced_search' tool to its handler function.case 'advanced_search': return await this.handleAdvancedSearch(args);
- src/index.ts:141-163 (helper)Type guard function used by the handler to validate input arguments for the 'advanced_search' tool, checking types and ranges for property filters.const isValidPropertyFilterArgs = ( args: any ): args is { min_mw?: number; max_mw?: number; min_logp?: number; max_logp?: number; max_hbd?: number; max_hba?: number; limit?: number } => { return ( typeof args === 'object' && args !== null && (args.min_mw === undefined || (typeof args.min_mw === 'number' && args.min_mw >= 0)) && (args.max_mw === undefined || (typeof args.max_mw === 'number' && args.max_mw >= 0)) && (args.min_logp === undefined || typeof args.min_logp === 'number') && (args.max_logp === undefined || typeof args.max_logp === 'number') && (args.max_hbd === undefined || (typeof args.max_hbd === 'number' && args.max_hbd >= 0)) && (args.max_hba === undefined || (typeof args.max_hba === 'number' && args.max_hba >= 0)) && (args.limit === undefined || (typeof args.limit === 'number' && args.limit > 0 && args.limit <= 1000)) ); };