get_gene_tree
Generate a phylogenetic tree for a gene family using an Ensembl gene ID, with options for species, tree format, and clusterset ID. Accessible via the Ensembl MCP Server.
Instructions
Get phylogenetic tree for gene family
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| clusterset_id | No | Specific clusterset ID (optional) | |
| format | No | Tree format (default: json) | |
| gene_id | Yes | Ensembl gene ID | |
| species | No | Species name (default: homo_sapiens) |
Implementation Reference
- src/index.ts:1254-1288 (handler)The main handler function for the 'get_gene_tree' tool. Validates arguments, constructs the Ensembl REST API endpoint `/genetree/id/{gene_id}`, makes the API call, formats the response as JSON or other specified format, and handles errors.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)Type guard function validating input arguments for the get_gene_tree tool, ensuring required gene_id and optional parameters like 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:851-852 (registration)Switch case in CallToolRequestSchema handler that routes calls to the get_gene_tree tool to its handler function.case 'get_gene_tree': return this.handleGetGeneTree(args);
- src/index.ts:669-681 (registration)Tool registration in ListToolsRequestSchema response, defining name, description, and inputSchema for get_gene_tree.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:309-321 (schema)Input validation schema matching the tool's inputSchema, used in the handler.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') ); };