get_xrefs
Retrieve cross-references from external databases for specific genes using an Ensembl gene ID. Optionally filter by species, database, and include transcript or translation details.
Instructions
Get external database cross-references for genes
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| all_levels | No | Include transcript and translation xrefs (default: false) | |
| external_db | No | Specific external database (optional) | |
| gene_id | Yes | Ensembl gene ID | |
| species | No | Species name (default: homo_sapiens) |
Implementation Reference
- src/index.ts:1448-1479 (handler)The main handler function for the 'get_xrefs' tool. Validates input using isValidXrefArgs, constructs API parameters, calls Ensembl REST API /xrefs/id/{gene_id} endpoint, and returns formatted JSON response or error.private async handleGetXrefs(args: any) { if (!isValidXrefArgs(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid xref arguments'); } try { const species = this.getDefaultSpecies(args.species); const params: any = { species }; if (args.external_db) { params.external_db = args.external_db; } if (args.all_levels) { params.all_levels = 1; } const response = await this.apiClient.get(`/xrefs/id/${args.gene_id}`, { params }); return { content: [ { type: 'text', text: JSON.stringify(response.data, null, 2), }, ], }; } catch (error) { return this.handleError(error, 'fetching cross-references'); } }
- src/index.ts:739-751 (registration)Tool registration in ListToolsRequestSchema response, defining name, description, and input schema for 'get_xrefs'.name: 'get_xrefs', description: 'Get external database cross-references for genes', inputSchema: { type: 'object', properties: { gene_id: { type: 'string', description: 'Ensembl gene ID' }, species: { type: 'string', description: 'Species name (default: homo_sapiens)' }, external_db: { type: 'string', description: 'Specific external database (optional)' }, all_levels: { type: 'boolean', description: 'Include transcript and translation xrefs (default: false)' }, }, required: ['gene_id'], }, },
- src/index.ts:864-865 (registration)Dispatch case in CallToolRequestSchema handler that routes calls to the 'get_xrefs' handler function.case 'get_xrefs': return this.handleGetXrefs(args);
- src/index.ts:243-255 (schema)Type guard function for input validation/schema of 'get_xrefs' tool arguments.const isValidXrefArgs = ( args: any ): args is { gene_id: string; species?: string; external_db?: string; all_levels?: boolean } => { return ( typeof args === 'object' && args !== null && typeof args.gene_id === 'string' && args.gene_id.length > 0 && (args.species === undefined || typeof args.species === 'string') && (args.external_db === undefined || typeof args.external_db === 'string') && (args.all_levels === undefined || typeof args.all_levels === 'boolean') ); };
- src/index.ts:119-128 (helper)TypeScript interface defining the structure of Ensembl cross-reference (xref) data returned by the API.interface EnsemblXref { primary_id: string; display_id: string; version?: string; description?: string; dbname: string; info_type: string; info_text?: string; linkage_annotation?: string[]; }