lookup_gene
Retrieve detailed gene information by Ensembl ID or symbol, including transcript and exon data, in JSON, FASTA, or GFF formats for specified species.
Instructions
Get detailed gene information by stable ID or symbol
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| expand | No | Include transcript and exon details (default: false) | |
| format | No | Output format (default: json) | |
| gene_id | Yes | Ensembl gene ID or gene symbol (e.g., ENSG00000139618, BRCA2) | |
| species | No | Species name (default: homo_sapiens) |
Implementation Reference
- src/index.ts:923-958 (handler)The core handler function for the 'lookup_gene' tool. It validates input arguments, calls the Ensembl REST API endpoint `/lookup/id/{gene_id}` with optional species, expand, and format parameters, and returns the gene information as formatted JSON.private async handleLookupGene(args: any) { if (!isValidGeneArgs(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid gene lookup arguments'); } try { const species = this.getDefaultSpecies(args.species); const format = args.format || 'json'; let endpoint = `/lookup/id/${args.gene_id}`; const params: any = { species }; if (args.expand) { params.expand = 1; } if (format !== 'json') { params.format = format; } const response = await this.apiClient.get(endpoint, { params }); return { content: [ { type: 'text', text: typeof response.data === 'object' ? JSON.stringify(response.data, null, 2) : String(response.data), }, ], }; } catch (error) { return this.handleError(error, 'looking up gene'); } }
- src/index.ts:569-582 (schema)Tool metadata and input schema definition for 'lookup_gene' provided in the ListToolsRequestSchema response.{ name: 'lookup_gene', description: 'Get detailed gene information by stable ID or symbol', inputSchema: { type: 'object', properties: { gene_id: { type: 'string', description: 'Ensembl gene ID or gene symbol (e.g., ENSG00000139618, BRCA2)' }, species: { type: 'string', description: 'Species name (default: homo_sapiens)' }, expand: { type: 'boolean', description: 'Include transcript and exon details (default: false)' }, format: { type: 'string', enum: ['json', 'fasta', 'gff'], description: 'Output format (default: json)' }, }, required: ['gene_id'], }, },
- src/index.ts:835-837 (registration)Registers the 'lookup_gene' tool handler in the CallToolRequestSchema switch dispatcher.case 'lookup_gene': return this.handleLookupGene(args); case 'get_transcripts':
- src/index.ts:155-167 (schema)Input validation type guard function specifically for 'lookup_gene' tool arguments.const isValidGeneArgs = ( args: any ): args is { gene_id: string; species?: string; expand?: boolean; format?: string } => { return ( typeof args === 'object' && args !== null && typeof args.gene_id === 'string' && args.gene_id.length > 0 && (args.species === undefined || typeof args.species === 'string') && (args.expand === undefined || typeof args.expand === 'boolean') && (args.format === undefined || ['json', 'fasta', 'gff'].includes(args.format)) ); };