get_gene_tree
Retrieve phylogenetic trees for gene families to analyze evolutionary relationships and gene function across species using Ensembl genomic data.
Instructions
Get phylogenetic tree for gene family
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| gene_id | Yes | Ensembl gene ID | |
| species | No | Species name (default: homo_sapiens) | |
| format | No | Tree format (default: json) | |
| clusterset_id | No | Specific clusterset ID (optional) |
Implementation Reference
- src/index.ts:1254-1288 (handler)The handler function for the 'get_gene_tree' tool. Validates input using isValidGeneTreeArgs, constructs Ensembl REST API request to /genetree/id/{gene_id}, handles format and clusterset_id parameters, fetches the phylogenetic tree data, and returns it as formatted text content.
private async handleGetGeneTree(args: any) { if (!isValidGeneTreeArgs(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid gene tree arguments'); } try { const format = args.format || 'json'; let endpoint = `/genetree/id/${args.gene_id}`; const params: any = {}; if (args.clusterset_id) { params.clusterset_id = args.clusterset_id; } 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, 'fetching gene tree'); } } - src/index.ts:309-321 (schema)Input validation type guard (schema) for get_gene_tree tool arguments: requires gene_id string, optional species, format (json/newick/phyloxml), clusterset_id.
const isValidGeneTreeArgs = ( args: any ): args is { gene_id: string; species?: string; format?: string; clusterset_id?: 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.format === undefined || ['json', 'newick', 'phyloxml'].includes(args.format)) && (args.clusterset_id === undefined || typeof args.clusterset_id === 'string') ); }; - src/index.ts:669-681 (registration)Tool registration definition in the listTools response, including name, description, and detailed inputSchema matching the validator.
name: 'get_gene_tree', description: 'Get phylogenetic tree for gene family', inputSchema: { type: 'object', properties: { gene_id: { type: 'string', description: 'Ensembl gene ID' }, species: { type: 'string', description: 'Species name (default: homo_sapiens)' }, format: { type: 'string', enum: ['json', 'newick', 'phyloxml'], description: 'Tree format (default: json)' }, clusterset_id: { type: 'string', description: 'Specific clusterset ID (optional)' }, }, required: ['gene_id'], }, }, - src/index.ts:851-852 (registration)Dispatch case in the CallToolRequestSchema switch statement that routes 'get_gene_tree' calls to the handleGetGeneTree handler.
case 'get_gene_tree': return this.handleGetGeneTree(args);