get_sequence
Retrieve DNA sequences for specified genomic coordinates, gene IDs, or transcript IDs. Supports multiple species, output formats (JSON or FASTA), and optional repeat masking. Part of the Ensembl MCP Server for genomic data access.
Instructions
Get DNA sequence for genomic coordinates or gene/transcript ID
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| format | No | Output format (default: fasta) | |
| mask | No | Repeat masking type (optional) | |
| multiple_sequences | No | Return multiple sequences if applicable (default: false) | |
| region | Yes | Genomic region (chr:start-end) or feature ID | |
| species | No | Species name (default: homo_sapiens) |
Implementation Reference
- src/index.ts:1032-1078 (handler)The primary handler function for the 'get_sequence' tool. It validates input arguments using isValidSequenceArgs, determines the Ensembl REST API endpoint based on whether the region is a feature ID or genomic coordinates, adds optional parameters like masking, fetches the sequence data using axios, and returns formatted content (JSON or FASTA).private async handleGetSequence(args: any) { if (!isValidSequenceArgs(args)) { throw new McpError(ErrorCode.InvalidParams, 'Invalid sequence arguments'); } try { const species = this.getDefaultSpecies(args.species); const format = args.format || 'fasta'; const region = this.formatGenomicRegion(args.region); let endpoint: string; const params: any = {}; if (region.startsWith('ENS')) { // Feature ID endpoint = `/sequence/id/${region}`; params.type = 'genomic'; } else { // Genomic region endpoint = `/sequence/region/${species}/${region}`; } if (args.mask) { params.mask = args.mask; } if (args.multiple_sequences) { params.multiple_sequences = 1; } const response = await this.apiClient.get(endpoint, { params }); return { content: [ { type: 'text', text: format === 'json' ? JSON.stringify(response.data, null, 2) : typeof response.data === 'string' ? response.data : JSON.stringify(response.data, null, 2), }, ], }; } catch (error) { return this.handleError(error, 'fetching sequence'); }
- src/index.ts:615-625 (schema)JSON Schema defining the input parameters for the 'get_sequence' tool, including required 'region' and optional fields for species, format, masking, and multiple sequences.inputSchema: { type: 'object', properties: { region: { type: 'string', description: 'Genomic region (chr:start-end) or feature ID' }, species: { type: 'string', description: 'Species name (default: homo_sapiens)' }, format: { type: 'string', enum: ['json', 'fasta'], description: 'Output format (default: fasta)' }, mask: { type: 'string', enum: ['hard', 'soft'], description: 'Repeat masking type (optional)' }, multiple_sequences: { type: 'boolean', description: 'Return multiple sequences if applicable (default: false)' }, }, required: ['region'], },
- src/index.ts:842-843 (registration)Registration of the 'get_sequence' tool handler in the CallToolRequestSchema switch statement, mapping the tool name to its execution function.case 'get_sequence': return this.handleGetSequence(args);
- src/index.ts:613-626 (registration)Tool registration in the ListToolsRequestSchema response, defining name, description, and input schema for 'get_sequence'.name: 'get_sequence', description: 'Get DNA sequence for genomic coordinates or gene/transcript ID', inputSchema: { type: 'object', properties: { region: { type: 'string', description: 'Genomic region (chr:start-end) or feature ID' }, species: { type: 'string', description: 'Species name (default: homo_sapiens)' }, format: { type: 'string', enum: ['json', 'fasta'], description: 'Output format (default: fasta)' }, mask: { type: 'string', enum: ['hard', 'soft'], description: 'Repeat masking type (optional)' }, multiple_sequences: { type: 'boolean', description: 'Return multiple sequences if applicable (default: false)' }, }, required: ['region'], }, },
- src/index.ts:169-182 (helper)Type guard function used by the handler to validate input arguments against the expected schema for 'get_sequence'.const isValidSequenceArgs = ( args: any ): args is { region: string; species?: string; format?: string; mask?: string; multiple_sequences?: boolean } => { 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', 'fasta'].includes(args.format)) && (args.mask === undefined || ['hard', 'soft'].includes(args.mask)) && (args.multiple_sequences === undefined || typeof args.multiple_sequences === 'boolean') ); };