mcp-rune 0.107.0
Be star #1 Get started
SECTION III · GUIDE 13 OF 49
Reading
6 min
Topic
ui
Spec
v0.107.0
Source
03-the-prompt/sections-groups.md
On this page9 sections

Customization: declared on your BasePrompt subclass via static sections and static fieldGroups. This chapter is the reference for those two structures. See Prompt Creation for how a strategy (stateless / hybrid / stateful) consumes them.

Sections & Field Groups

Sections and field groups are the two halves of mcp-rune’s prompt structure. Sections define the user-facing workflow — how an LLM walks the user through a creation or update flow. Field groups define validation — which fields belong together and what rules apply. They live side by side in every prompt class, and the framework derives field tables, flow diagrams, and per-section docs from both.

This guide is the reference for how the two work together. For the strategy that consumes them (stateless / hybrid / stateful), see the Prompt Creation guide.

Why sections?

  1. Separation of concerns — display structure (sections) vs validation structure (fieldGroups)
  2. Scalability — add new fieldGroups to existing sections without changing the user-facing workflow
  3. Flexibility — multiple fieldGroups can be grouped under one section
  4. Single source of truth — section titles and descriptions defined once

The relationship is one-section-to-many-groups, with fields mapped at the group level:

SECTIONS → FIELD GROUPSSECTIONSuser-facing flowFIELD GROUPSvalidationbasicstitle : "Basics"required: truebasicsfields: ['title', 'desc']required: truegroups: basicsclassificationtitle : "Classify"required: trueclassificationfields: ['theme_id', 'category_id']groups: classificationtimingtitle : "Timing"required: falsetiming-whenfields: ['occurred_at']timing-durationfields: ['duration_min']groups: 2

Left column is what the LLM walks the user through; right column is what validateSection evaluates. A section can carry one or many field groups — that’s how a “Timing” section can host both a “when” group and a “duration” group without changing the user-facing flow.

Sections vs FieldGroups

AspectSectionsFieldGroups
PurposeUser-facing workflowValidation & technical organization
Containstitle, description, required, groups[]fields[], required, conditional, validateSection
Used by.flowDiagram() (flow-diagram generator), StatefulFormStrategy.getSections()StatefulFormStrategy.validateSection(), getProgress()
GranularityCoarse (user journey)Fine (field validation)

Defining sections

examples/sections-groups-guide-01.ts
static sections = {
  basics: {
    title: 'Basic Information',
    description: 'Title and description for the activity',
    required: true,
    groups: ['basics'],
    content: {
      intro: 'The title and description that identify the activity.'
    }
  },
  classification: {
    title: 'Classification',
    description: 'Theme and category for organizing the activity',
    required: true,
    groups: ['classification'],
    content: {
      notes: [
        'Use `find_records(model: "theme")` to find the theme',
        'Use `find_records(model: "category")` to find the category'
      ]
    }
  },
  timing: {
    title: 'Timing',
    description: 'When the activity occurred and how long it lasted',
    required: false,
    groups: ['timing'],
    content: {
      intro: 'When the activity occurred and how long it lasted.'
    }
  }
}
static sections = {
  basics: {
    title: 'Basic Information',
    description: 'Title and description for the activity',
    required: true,
    groups: ['basics'],
    content: {
      intro: 'The title and description that identify the activity.'
    }
  },
  classification: {
    title: 'Classification',
    description: 'Theme and category for organizing the activity',
    required: true,
    groups: ['classification'],
    content: {
      notes: [
        'Use `find_records(model: "theme")` to find the theme',
        'Use `find_records(model: "category")` to find the category'
      ]
    }
  },
  timing: {
    title: 'Timing',
    description: 'When the activity occurred and how long it lasted',
    required: false,
    groups: ['timing'],
    content: {
      intro: 'When the activity occurred and how long it lasted.'
    }
  }
}

Section content enrichment

Sections support a content property with intro and notes that are automatically rendered in the generated section documentation. Use these to add domain-specific context without writing custom section generator methods.

PropertyTypeDescription
content.introstringIntroductory text rendered at the top of the section, before the field table. Supports full markdown.
content.notesstring[]Array of notes rendered as a bullet list after the field table and enum tables.
askPromptstringCustom prompt shown as “Ask the user: …” at the end of the section.

How it works: When .allSections() or .section() renders a section, it automatically:

  1. Adds content.intro before the field table
  2. Generates the field table from fieldDefinitions
  3. Generates enum tables for any field with enumDescriptions
  4. Adds content.notes as a bullet list
  5. Adds the askPrompt prompt

Key principle: Prefer content.intro and content.notes over custom generateSectionXDocumentation() methods. This keeps domain content in configuration and lets the framework auto-generate field tables and enum tables alongside it.

Per-group content (multi-group sections)

When a section contains multiple groups (groups: ['group_a', 'group_b']), each group can have its own context (display name) and content: { intro, notes } defined in fieldGroups. The generator renders each group as a ### sub-section with its own field table.

Key behaviors:

  • context defaults to title-cased group name if absent (snake_case_name → “Snake Case Name”)
  • Groups without content render just a heading and field table (no intro/notes)
  • Single-group sections are completely unchanged — they read from section.content as before
  • context and content on fieldGroups are ignored by StatefulFormStrategy (no breaking changes to validation)

Defining fieldGroups (simplified)

With sections as first-class citizens, fieldGroups focus on validation:

examples/sections-groups-guide-02.ts
static fieldGroups = {
  basics: {
    fields: ['title', 'description'],
    context: 'Basic Information',
    required: true,
    description: 'Title and description for the activity'
  },
  classification: {
    fields: ['theme_id', 'category_id'],
    context: 'Classification',
    required: true,
    description: 'Theme and category for organizing the activity'
  }
}
static fieldGroups = {
  basics: {
    fields: ['title', 'description'],
    context: 'Basic Information',
    required: true,
    description: 'Title and description for the activity'
  },
  classification: {
    fields: ['theme_id', 'category_id'],
    context: 'Classification',
    required: true,
    description: 'Theme and category for organizing the activity'
  }
}

Section helper methods

BasePrompt keeps a small set of section-related statics:

MethodDescription
getSectionForGroup(groupName)Reverse lookup: find which section a group belongs to
getDefaults()Collect default values across all field definitions
getStrategyIntro()Strategy-specific description fragment for static description

For section enumeration with metadata (fields, numbering, progress), use StatefulFormStrategy.getSections(PromptClass) from the Stateful Strategies guide.

Flow diagram generation

The builder’s .flowDiagram() step (backed by generateFlowDiagram in generators/flow-diagram-generator.ts) uses sections to create a compact flow overview:

examples/sections-groups-guide-03.ts
// Auto-generated from sections config
**Flow:** (● required, ○ optional)
1. BASIC INFORMATION - title, description
2. CLASSIFICATION - theme_id, category_id
3. TIMING - started_at, ended_at, duration_minutes
4. RESOURCES - book_ids, notes_generated
5. SUMMARY
// Auto-generated from sections config
**Flow:** (● required, ○ optional)
1. BASIC INFORMATION - title, description
2. CLASSIFICATION - theme_id, category_id
3. TIMING - started_at, ended_at, duration_minutes
4. RESOURCES - book_ids, notes_generated
5. SUMMARY

See also