search_compounds
Find chemical compounds in the ChEMBL database by entering names, synonyms, or identifiers to retrieve relevant results.
Instructions
Search ChEMBL database for compounds by name, synonym, or identifier
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search query (compound name, synonym, or identifier) | |
| limit | No | Number of results to return (1-1000, default: 25) | |
| offset | No | Number of results to skip (default: 0) |
Implementation Reference
- src/index.ts:825-853 (handler)The main handler function that validates the input arguments using isValidCompoundSearchArgs and performs an API request to the ChEMBL '/molecule/search.json' endpoint with the query, limit, and offset parameters. Returns the JSON response as text content.private async handleSearchCompounds(args: any) { if (!isValidCompoundSearchArgs(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid compound search arguments'); } try { const response = await this.apiClient.get('/molecule/search.json', { params: { q: args.query, limit: args.limit || 25, offset: args.offset || 0, }, }); return { content: [ { type: 'text', text: JSON.stringify(response.data, null, 2), }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `Failed to search compounds: ${error instanceof Error ? error.message : 'Unknown error'}` ); } }
- src/index.ts:399-406 (schema)The input schema definition for the search_compounds tool, specifying the expected parameters: query (required string), optional limit and offset numbers with constraints.inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search query (compound name, synonym, or identifier)' }, limit: { type: 'number', description: 'Number of results to return (1-1000, default: 25)', minimum: 1, maximum: 1000 }, offset: { type: 'number', description: 'Number of results to skip (default: 0)', minimum: 0 }, }, required: ['query'],
- src/index.ts:396-407 (registration)Tool registration in the ListToolsRequestSchema response, including name, description, and input schema.{ name: 'search_compounds', description: 'Search ChEMBL database for compounds by name, synonym, or identifier', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search query (compound name, synonym, or identifier)' }, limit: { type: 'number', description: 'Number of results to return (1-1000, default: 25)', minimum: 1, maximum: 1000 }, offset: { type: 'number', description: 'Number of results to skip (default: 0)', minimum: 0 }, }, required: ['query'], },
- src/index.ts:745-746 (registration)Dispatch registration in the CallToolRequestSchema switch statement, routing calls to the handleSearchCompounds method.case 'search_compounds': return await this.handleSearchCompounds(args);
- src/index.ts:77-88 (helper)Type guard and validation function for search_compounds input arguments, ensuring query is a non-empty string and limit/offset are valid numbers.const isValidCompoundSearchArgs = ( args: any ): args is { query: string; limit?: number; offset?: number } => { return ( typeof args === 'object' && args !== null && typeof args.query === 'string' && args.query.length > 0 && (args.limit === undefined || (typeof args.limit === 'number' && args.limit > 0 && args.limit <= 1000)) && (args.offset === undefined || (typeof args.offset === 'number' && args.offset >= 0)) ); };