get_external_references
Retrieve external database links for ChEMBL compounds or targets, connecting to PubChem, DrugBank, PDB, and other resources.
Instructions
Get links to external databases (PubChem, DrugBank, PDB, etc.)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chembl_id | Yes | ChEMBL compound or target ID |
Implementation Reference
- src/index.ts:1839-1897 (handler)The handler function that executes the tool logic: validates input, fetches ChEMBL entity data (molecule or target), extracts cross_references, groups them by database source, generates URLs using helper, and returns formatted JSON.private async handleGetExternalReferences(args: any) { if (!isValidChemblIdArgs(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid external references arguments'); } try { // Try to get molecule data first let response; let entityType = 'molecule'; try { response = await this.apiClient.get(`/molecule/${args.chembl_id}.json`); } catch (e) { // If not a molecule, try target try { response = await this.apiClient.get(`/target/${args.chembl_id}.json`); entityType = 'target'; } catch (e2) { throw new McpError(ErrorCode.InvalidParams, 'ChEMBL ID not found as molecule or target'); } } const entity = response.data; const crossRefs = entity.cross_references || []; // Organize external references by database const externalReferences = { chembl_id: args.chembl_id, entity_type: entityType, databases: {} as any, }; // Group references by source crossRefs.forEach((ref: any) => { const source = ref.xref_src || ref.xref_name; if (!externalReferences.databases[source]) { externalReferences.databases[source] = []; } externalReferences.databases[source].push({ id: ref.xref_id, name: ref.xref_name, url: this.getExternalUrl(source, ref.xref_id), }); }); return { content: [ { type: 'text', text: JSON.stringify(externalReferences, null, 2), }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `Failed to get external references: ${error instanceof Error ? error.message : 'Unknown error'}` ); }
- src/index.ts:711-717 (schema)Input schema definition for the tool, specifying required chembl_id parameter.inputSchema: { type: 'object', properties: { chembl_id: { type: 'string', description: 'ChEMBL compound or target ID' }, }, required: ['chembl_id'], },
- src/index.ts:708-718 (registration)Tool registration in the listTools response, defining name, description, and input schema.{ name: 'get_external_references', description: 'Get links to external databases (PubChem, DrugBank, PDB, etc.)', inputSchema: { type: 'object', properties: { chembl_id: { type: 'string', description: 'ChEMBL compound or target ID' }, }, required: ['chembl_id'], }, },
- src/index.ts:800-801 (registration)Dispatch registration in the CallToolRequestSchema handler switch statement.case 'get_external_references': return await this.handleGetExternalReferences(args);
- src/index.ts:1900-1911 (helper)Helper utility to map external database sources to their corresponding URLs.private getExternalUrl(source: string, id: string): string { const urlMap: { [key: string]: string } = { 'PubChem': `https://pubchem.ncbi.nlm.nih.gov/compound/${id}`, 'DrugBank': `https://www.drugbank.ca/drugs/${id}`, 'PDB': `https://www.rcsb.org/structure/${id}`, 'UniProt': `https://www.uniprot.org/uniprot/${id}`, 'Wikipedia': `https://en.wikipedia.org/wiki/${id}`, 'KEGG': `https://www.genome.jp/entry/${id}`, 'Reactome': `https://reactome.org/content/detail/${id}`, }; return urlMap[source] || `https://www.ebi.ac.uk/chembl/`; }