Skip to main content
Glama
coreymhudson

MCP Sequence Simulation Server

by coreymhudson

generate_dna_sequence

Generate random DNA sequences with customizable length, GC content, and generation models for bioinformatics research and testing.

Instructions

Generate random DNA sequences with specified parameters

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
lengthYesLength of the DNA sequence to generate
gcContentNoGC content (0-1), default is 0.5
countNoNumber of sequences to generate, default is 1
seedNoRandom seed for reproducible results (optional)
modelNoGeneration model: 'random', 'markov', or 'codon-biased'
outputFormatNoOutput format: 'fasta' or 'plain'

Implementation Reference

  • Main handler function that executes the generate_dna_sequence tool logic. Accepts parameters for length, GC content, count, seed, model (random/markov/codon-biased), and output format (fasta/plain). Uses SequenceGenerator utility and supports three different generation models.
    async handler({ 
      length, 
      gcContent = 0.5, 
      count = 1, 
      seed, 
      model = "random",
      outputFormat = "fasta"
    }: { 
      length: number; 
      gcContent?: number; 
      count?: number; 
      seed?: number;
      model?: string;
      outputFormat?: string;
    }) {
      const generator = new SequenceGenerator(seed);
      const sequences = [];
    
      for (let i = 0; i < count; i++) {
        let sequence: string;
        
        switch (model) {
          case "random":
            sequence = generator.generateRandomDNA(length, gcContent);
            break;
          case "markov":
            sequence = generateMarkovDNA(length, gcContent, generator);
            break;
          case "codon-biased":
            sequence = generateCodonBiasedDNA(length, generator);
            break;
          default:
            sequence = generator.generateRandomDNA(length, gcContent);
        }
    
        const actualGC = (sequence.match(/[GC]/g) || []).length / sequence.length;
        
        sequences.push({
          id: `sim_dna_${i + 1}`,
          sequence,
          length: sequence.length,
          gcContent: Math.round(actualGC * 10000) / 100,
          model
        });
      }
    
      let output = '';
      if (outputFormat === 'fasta') {
        output = sequences.map(seq => 
          `>${seq.id} length=${seq.length} gc=${seq.gcContent}% model=${seq.model}\n${seq.sequence}`
        ).join('\n\n');
      } else {
        output = sequences.map(seq => seq.sequence).join('\n');
      }
    
      const stats = {
        totalSequences: sequences.length,
        averageLength: Math.round(sequences.reduce((sum, seq) => sum + seq.length, 0) / sequences.length),
        averageGC: Math.round(sequences.reduce((sum, seq) => sum + seq.gcContent, 0) / sequences.length * 100) / 100,
        model,
        seed: seed || "random"
      };
    
      return {
        content: [{
          type: "text",
          text: JSON.stringify({
            statistics: stats,
            sequences: outputFormat === 'fasta' ? output : sequences,
            rawOutput: outputFormat === 'plain' ? output : undefined
          }, null, 2)
        }]
      };
    }
  • Tool definition and input schema for generate_dna_sequence. Defines the tool name, description, and JSON Schema validation for all input parameters including length (required), gcContent, count, seed, model, and outputFormat.
    export const generateDNA = {
      definition: {
        name: "generate_dna_sequence",
        description: "Generate random DNA sequences with specified parameters",
        inputSchema: {
          type: "object",
          properties: {
            length: {
              type: "number",
              description: "Length of the DNA sequence to generate"
            },
            gcContent: {
              type: "number",
              description: "GC content (0-1), default is 0.5",
              minimum: 0,
              maximum: 1
            },
            count: {
              type: "number",
              description: "Number of sequences to generate, default is 1",
              minimum: 1
            },
            seed: {
              type: "number",
              description: "Random seed for reproducible results (optional)"
            },
            model: {
              type: "string",
              description: "Generation model: 'random', 'markov', or 'codon-biased'",
              enum: ["random", "markov", "codon-biased"]
            },
            outputFormat: {
              type: "string",
              description: "Output format: 'fasta' or 'plain'",
              enum: ["fasta", "plain"]
            }
          },
          required: ["length"]
        },
      },
  • src/server.ts:47-55 (registration)
    Registration of the generate_dna_sequence tool handler in the MCP server's CallToolRequestSchema request handler. Maps the tool name to the generateDNA.handler function with proper TypeScript type annotations.
    case "generate_dna_sequence":
      return await generateDNA.handler(args as {
        length: number;
        gcContent?: number;
        count?: number;
        seed?: number;
        model?: string;
        outputFormat?: string;
      });
  • SequenceGenerator utility class with seedable RNG and the generateRandomDNA method used by the handler. Supports generating random DNA sequences with specified GC content bias.
    export class SequenceGenerator {
      public rng: () => number;
    
      constructor(seed?: number) {
        if (seed !== undefined) {
          let s = seed;
          this.rng = () => {
            s = Math.sin(s) * 10000;
            return s - Math.floor(s);
          };
        } else {
          this.rng = Math.random;
        }
      }
    
      generateRandomDNA(length: number, gcContent: number = 0.5): string {
        const gcProb = gcContent / 2;
        const atProb = (1 - gcContent) / 2;
        
        let sequence = '';
        for (let i = 0; i < length; i++) {
          const rand = this.rng();
          if (rand < atProb) {
            sequence += 'A';
          } else if (rand < atProb * 2) {
            sequence += 'T';
          } else if (rand < atProb * 2 + gcProb) {
            sequence += 'G';
          } else {
            sequence += 'C';
          }
        }
        return sequence;
      }
  • Helper functions for alternative DNA generation models: generateMarkovDNA (uses Markov chain transitions) and generateCodonBiasedDNA (uses codon usage tables). These are called by the main handler when model parameter is set to 'markov' or 'codon-biased'.
    function generateMarkovDNA(length: number, gcContent: number, generator: SequenceGenerator): string {
      const transitions = {
        'A': { 'A': 0.3, 'T': 0.3, 'G': 0.2, 'C': 0.2 },
        'T': { 'A': 0.3, 'T': 0.3, 'G': 0.2, 'C': 0.2 },
        'G': { 'A': 0.2, 'T': 0.2, 'G': 0.3, 'C': 0.3 },
        'C': { 'A': 0.2, 'T': 0.2, 'G': 0.3, 'C': 0.3 }
      };
    
      let sequence = generator.generateRandomDNA(1, gcContent);
      
      for (let i = 1; i < length; i++) {
        const lastBase = sequence[i - 1] as keyof typeof transitions;
        const probs = transitions[lastBase];
        const rand = Math.random();
        
        let cumProb = 0;
        for (const [base, prob] of Object.entries(probs)) {
          cumProb += prob;
          if (rand < cumProb) {
            sequence += base;
            break;
          }
        }
      }
      
      return sequence;
    }
    
    function generateCodonBiasedDNA(length: number, generator: SequenceGenerator): string {
      const codonUsage = {
        'F': ['TTT', 'TTC'], 'L': ['TTA', 'TTG', 'CTT', 'CTC', 'CTA', 'CTG'],
        'S': ['TCT', 'TCC', 'TCA', 'TCG', 'AGT', 'AGC'], 'Y': ['TAT', 'TAC'],
        'C': ['TGT', 'TGC'], 'W': ['TGG'], 'P': ['CCT', 'CCC', 'CCA', 'CCG'],
        'H': ['CAT', 'CAC'], 'Q': ['CAA', 'CAG'], 'R': ['CGT', 'CGC', 'CGA', 'CGG', 'AGA', 'AGG'],
        'I': ['ATT', 'ATC', 'ATA'], 'M': ['ATG'], 'T': ['ACT', 'ACC', 'ACA', 'ACG'],
        'N': ['AAT', 'AAC'], 'K': ['AAA', 'AAG'], 'V': ['GTT', 'GTC', 'GTA', 'GTG'],
        'A': ['GCT', 'GCC', 'GCA', 'GCG'], 'D': ['GAT', 'GAC'], 'E': ['GAA', 'GAG'],
        'G': ['GGT', 'GGC', 'GGA', 'GGG'], '*': ['TAA', 'TAG', 'TGA']
      };
    
      const aminoAcids = Object.keys(codonUsage).filter(aa => aa !== '*');
      let sequence = '';
      
      const targetCodons = Math.floor(length / 3);
      for (let i = 0; i < targetCodons; i++) {
        const aa = aminoAcids[Math.floor(Math.random() * aminoAcids.length)];
        const codons = codonUsage[aa as keyof typeof codonUsage];
        const codon = codons[Math.floor(Math.random() * codons.length)];
        sequence += codon;
      }
      
      return sequence.substring(0, length);
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but offers minimal behavioral context. It mentions 'random' generation but doesn't explain what makes sequences random, whether results are deterministic with seeds, performance characteristics, or output structure. For a generation tool with 6 parameters, this leaves significant behavioral gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that immediately communicates the core functionality. Every word earns its place with no redundancy or unnecessary elaboration. It's appropriately sized for a generation tool with well-documented parameters.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a generation tool with 6 parameters, no annotations, and no output schema, the description is insufficiently complete. It doesn't explain what the output looks like (sequences, metadata), how parameters interact, or behavioral constraints. The high parameter count and lack of structured output information create significant gaps in understanding.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all parameters. The description adds no additional parameter semantics beyond implying parameters control the generation process. This meets the baseline for high schema coverage but doesn't enhance understanding of how parameters interact or affect results.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'generate' and resource 'random DNA sequences', making the purpose immediately understandable. It distinguishes from siblings like 'evolve_sequence' or 'mutate_sequence' by focusing on generation rather than modification. However, it doesn't explicitly differentiate from 'generate_protein_sequence' beyond the resource type.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'generate_protein_sequence' for proteins or 'simulate_fastq_file' for file output. There's no mention of prerequisites, typical use cases, or scenarios where other tools might be more appropriate.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/coreymhudson/mcp-sequence-simulation'

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