get_variants
Retrieve genetic variants within a specified genomic region for a given species. Filter results by consequence types and export in JSON or VCF format using Ensembl MCP Server.
Instructions
Get genetic variants in a genomic region
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| consequence_type | No | Filter by consequence types | |
| format | No | Output format (default: json) | |
| region | Yes | Genomic region (chr:start-end) | |
| species | No | Species name (default: homo_sapiens) |
Implementation Reference
- src/index.ts:1290-1336 (handler)The handler function for the 'get_variants' tool. Validates input using isValidVariantArgs, queries Ensembl REST API using /overlap/region/... with feature=variation first, falls back to /variation/region/..., formats response as JSON and returns it.private async handleGetVariants(args: any) { if (!isValidVariantArgs(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid variant arguments'); } try { const species = this.getDefaultSpecies(args.species); const format = args.format || 'json'; const region = this.formatGenomicRegion(args.region); // Try overlap endpoint first as variation/region may not have data for all regions try { const response = await this.apiClient.get(`/overlap/region/${species}/${region}`, { params: { feature: 'variation' } }); return { content: [ { type: 'text', text: JSON.stringify(response.data, null, 2), }, ], }; } catch (overlapError) { // Fallback to variation endpoint const params: any = { format }; if (args.consequence_type) { params.consequence_type = args.consequence_type.join(','); } const response = await this.apiClient.get(`/variation/region/${species}/${region}`, { params }); return { content: [ { type: 'text', text: JSON.stringify(response.data, null, 2), }, ], }; } } catch (error) { return this.handleError(error, 'fetching variants'); } }
- src/index.ts:199-212 (schema)Type guard and validation function for 'get_variants' tool input parameters: checks region (required string), optional species, format (json/vcf), and consequence_type array.const isValidVariantArgs = ( args: any ): args is { region: string; species?: string; format?: string; consequence_type?: string[] } => { return ( typeof args === 'object' && args !== null && typeof args.region === 'string' && args.region.length > 0 && (args.species === undefined || typeof args.species === 'string') && (args.format === undefined || ['json', 'vcf'].includes(args.format)) && (args.consequence_type === undefined || (Array.isArray(args.consequence_type) && args.consequence_type.every((c: any) => typeof c === 'string'))) ); };
- src/index.ts:684-695 (registration)Tool registration in ListToolsRequestSchema response, including name, description, and inputSchema definition.name: 'get_variants', description: 'Get genetic variants in a genomic region', inputSchema: { type: 'object', properties: { region: { type: 'string', description: 'Genomic region (chr:start-end)' }, species: { type: 'string', description: 'Species name (default: homo_sapiens)' }, format: { type: 'string', enum: ['json', 'vcf'], description: 'Output format (default: json)' }, consequence_type: { type: 'array', items: { type: 'string' }, description: 'Filter by consequence types' }, }, required: ['region'], },
- src/index.ts:854-855 (registration)Dispatch case in CallToolRequestSchema handler that routes 'get_variants' calls to the handleGetVariants method.case 'get_variants': return this.handleGetVariants(args);