Skip to main content
Glama

dhis2_generate_ui_form_patterns

Generate UI form components for DHIS2 applications including inputs, validation, date pickers, file uploads, and multi-select elements with configurable options.

Instructions

Generate @dhis2/ui form patterns (inputs, validation, date picker, file upload, multi-select)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
componentNameNoComponent name
includeValidationNoInclude client-side validation
includeDatePickerNoInclude DatePicker
includeFileUploadNoInclude FileInput upload
includeMultiSelectNoInclude MultiSelect
includeSelectsNoInclude SingleSelect inputs
i18nNoInclude @dhis2/d2-i18n usage
rtlNoAdd RTL considerations
accessibilityNoAdd accessibility attributes and checklist
densityNoForm density guidance

Implementation Reference

  • Handler logic in main server switch statement: extracts args, calls generateUIFormPatterns helper, returns generated code as text content.
    case 'dhis2_generate_ui_form_patterns':
      const formArgs = args as any;
      const formCode = generateUIFormPatterns(formArgs);
      return {
        content: [
          { type: 'text', text: formCode }
        ]
      };
  • Core helper function that generates React code for DHIS2 UI form patterns using @dhis2/ui components, supporting validation, date picker, file upload, multi-select etc.
    export function generateUIFormPatterns(args: any): string {
      const { 
        componentName = 'AdvancedForm',
        includeValidation = true,
        includeDatePicker = true,
        includeFileUpload = true,
        includeMultiSelect = true,
        includeSelects = true
      } = args;
    
      return `# @dhis2/ui Form Patterns: ${componentName}
    
    ## Implementation
    \`\`\`jsx
    import React from 'react';
    import {
      Button,
      Field,
      InputField,
      TextAreaField,
      SingleSelectField,
      SingleSelectOption,
      ${includeMultiSelect ? 'MultiSelectField, MultiSelectOption,' : ''}
      ${includeDatePicker ? 'DatePicker,' : ''}
      ${includeFileUpload ? 'FileInput,' : ''}
    } from '@dhis2/ui';
    ${includeValidation ? "import { useState } from 'react';" : ''}
    
    export const ${componentName} = () => {
      ${includeValidation ? 'const [errors, setErrors] = useState<Record<string, string | null>>({});' : ''}
      const [form, setForm] = React.useState({
        name: '',
        description: '',
        valueType: 'NUMBER',
        date: '',
        ${includeMultiSelect ? 'options: [],' : ''}
      });
    
      const onChange = (key, value) => setForm(prev => ({ ...prev, [key]: value }));
    
      const onSubmit = (e) => {
        e.preventDefault();
        ${includeValidation ? `
        const nextErrors: Record<string, string | null> = {};
        if (!form.name?.trim()) nextErrors.name = 'Name is required';
        if (form.name && form.name.length > 50) nextErrors.name = 'Max 50 characters';
        setErrors(nextErrors);
        if (Object.keys(nextErrors).length > 0) return;
        ` : ''}
        // Submit logic here
        console.log('Submitting form', form);
      };
    
      return (
        <form onSubmit={onSubmit} style={{ display: 'grid', gap: 16 }}>
          <InputField
            label="Name"
            name="name"
            value={form.name}
            onChange={({ value }) => onChange('name', value)}
            ${includeValidation ? 'validationText={errors.name || undefined}' : ''}
            ${includeValidation ? 'error={Boolean(errors.name)}' : ''}
            required
          />
    
          <TextAreaField
            label="Description"
            name="description"
            value={form.description}
            onChange={({ value }) => onChange('description', value)}
            rows={4}
          />
    
          ${includeSelects ? `
          <SingleSelectField
            label="Value type"
            selected={form.valueType}
            onChange={({ selected }) => onChange('valueType', selected)}
          >
            <SingleSelectOption value="NUMBER" label="Number" />
            <SingleSelectOption value="INTEGER" label="Integer" />
            <SingleSelectOption value="TEXT" label="Text" />
          </SingleSelectField>
          ` : ''}
    
          ${includeMultiSelect ? `
          <MultiSelectField
            label="Categories"
            selected={form.options}
            onChange={({ selected }) => onChange('options', selected)}
          >
            <MultiSelectOption value="male" label="Male" />
            <MultiSelectOption value="female" label="Female" />
          </MultiSelectField>
          ` : ''}
    
          ${includeDatePicker ? `
          <Field label="Start date">
            <DatePicker
              calendar="gregorian"
              date={form.date}
              onDateSelect={({ date }) => onChange('date', date)}
            />
          </Field>
          ` : ''}
    
          ${includeFileUpload ? `
          <Field label="Attachment">
            <FileInput onChange={({ files }) => onChange('file', files?.[0])} buttonLabel="Choose file" />
          </Field>
          ` : ''}
    
          <Button type="submit" primary>Save</Button>
        </form>
      );
    };
    \`\`\`
    
    ## Notes
    - Includes validation, date picker, file upload, and multi-select patterns.
    - Replace options with dynamic lists as needed.
    `;
  • Tool permission mapping: requires 'canUseUITools' permission to access.
    ['dhis2_generate_ui_form_patterns', 'canUseUITools'],
  • src/index.ts:25-35 (registration)
    Import statement registering the helper function for use in tool handler.
      generateUIComponents,
      generateUIFormPatterns,
      generateUIDataDisplayPatterns,
      generateUINavigationLayout,
      generateDesignSystemConfig,
      generateAndroidMaterialForm,
      generateAndroidListAdapter,
      generateAndroidNavigationDrawer,
      generateAndroidBottomSheet,
      generateTestSetup
    } from './webapp-generators.js';
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 insight. It mentions 'generate' but doesn't specify output format (e.g., code snippets, configuration files), whether it's idempotent, or any side effects. It lists pattern types but doesn't explain how they're integrated or if there are dependencies. This is inadequate for a tool with 10 parameters.

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

Conciseness4/5

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

The description is a single, efficient sentence that front-loads the core action ('Generate @dhis2/ui form patterns') followed by specific pattern types. There's no wasted text, though it could be slightly more structured (e.g., separating core from optional features).

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?

Given the tool's complexity (10 parameters, no annotations, no output schema), the description is incomplete. It doesn't explain what 'patterns' entail (e.g., code templates, best practices), how outputs are delivered, or any behavioral constraints. For a generation tool with many options, more context is needed to guide effective use.

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 10 parameters with clear descriptions. The description adds no additional parameter semantics beyond implying the tool covers the listed pattern types (inputs, validation, etc.), which partially maps to parameters like includeValidation. Baseline 3 is appropriate as the schema does the heavy lifting.

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 tool's purpose: 'Generate @dhis2/ui form patterns' with specific component types listed (inputs, validation, date picker, file upload, multi-select). It distinguishes from siblings like 'dhis2_generate_ui_data_display' or 'dhis2_generate_ui_navigation_layout' by focusing on form patterns. However, it doesn't explicitly contrast with 'dhis2_create_ui_components' which might overlap.

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. It doesn't mention prerequisites, context (e.g., for DHIS2 web app development), or compare to siblings like 'dhis2_generate_design_system' or 'dhis2_android_configure_ui_patterns'. Usage is implied but not explicitly stated.

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/Dradebo/dhis2-mcp'

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