Skip to main content
Glama
Augmented-Nature

Ensembl MCP Server

get_variants

Retrieve genetic variants from a specified genomic region using Ensembl data. Filter results by species, consequence types, and output format to analyze DNA sequence variations.

Instructions

Get genetic variants in a genomic region

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
regionYesGenomic region (chr:start-end)
speciesNoSpecies name (default: homo_sapiens)
formatNoOutput format (default: json)
consequence_typeNoFilter by consequence types

Implementation Reference

  • The handler function that implements the get_variants tool. It validates input, queries the Ensembl API using /overlap/region (feature=variation) or falls back to /variation/region, and returns the variants data as JSON.
    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:684-695 (registration)
    Tool registration in the ListToolsRequestSchema response, defining the name, description, and input schema for get_variants.
    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'],
    },
  • Type guard function that validates the input parameters for the get_variants tool.
    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:854-855 (registration)
    Registration/dispatch in the CallToolRequestSchema switch statement that routes calls to get_variants to its handler.
    case 'get_variants':
      return this.handleGetVariants(args);
  • TypeScript interface defining the structure of Ensembl variant data objects returned by the API.
    interface EnsemblVariant {
      id: string;
      seq_region_name: string;
      start: number;
      end: number;
      strand: number;
      allele_string: string;
      variant_class: string;
      source: string;
      most_severe_consequence: string;
      MAF?: number;
      minor_allele?: string;
      clinical_significance?: string[];
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Augmented-Nature/Ensembl-MCP-Server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server