Skip to content

Components

A component definition describes structured content the model may produce and how that content projects back into stable text. MFUI uses component definitions to build model prompts, validate model output, and provide text fallbacks for clients without matching renderers.

A component definition contains:

  • name
  • schema
  • model hints
  • projection templates

Component definitions do not include visual renderers or interaction logic. The application still owns UI, state, and business workflows.

Custom Components

Define a custom component when the builtin components do not express your domain semantics. Custom components should represent domain content, such as an order status, account summary, or quote result, instead of wrapping Markdown or visual arrangement.

Use a namespaced component name so model output, server validation, renderer lookup, and persisted history stay unambiguous. App-owned definitions should use an app or domain prefix, such as app.order_status or crm.account_summary, instead of unqualified names like timeline.

ts
import { createMFUIManifest, defineMFUIComponent } from '@mfui/client';
import { z } from 'zod';

const orderStatus = defineMFUIComponent({
  name: 'app.order_status',
  schema: z.object({
    orderId: z.string(),
    status: z.string(),
  }),
  model: {
    description: 'Show the current status of an order.',
  },
  projection: {
    text: '**Order {{ orderId }}:** {{ status }}',
  },
});

The renderer stays in your app. When sending a request, pass component definitions to createMFUIManifest(). It creates the serializable request manifest that tells the server which components the model may generate.

ts
const mfui = createMFUIManifest({
  components: [orderStatus],
});

Builtin Components

MFUI provides common semantic component definitions under @mfui/client/definitions. Builtin components are still only definitions: they provide schemas, model hints, and projection templates, not renderers.

Builtin components are not added to requests automatically. Applications choose which definitions to put in the manifest for the current request; they can include only a subset or mix builtins with custom components. The server only exposes components from the current manifest to the model.

If a client does not have a renderer for a builtin component, it can display part.projection.text.

The example below enables all current builtin components. In production, select only the definitions the current surface supports.

ts
import { createMFUIManifest } from '@mfui/client';
import {
  alertDefinition,
  timelineDefinition,
  formDefinition,
  barChartDefinition,
  lineChartDefinition,
  pieChartDefinition,
} from '@mfui/client/definitions';

const mfui = createMFUIManifest({
  components: [
    alertDefinition,
    timelineDefinition,
    formDefinition,
    barChartDefinition,
    lineChartDefinition,
    pieChartDefinition,
  ],
});

mfui.alert

Shows a contextual message that should stand out from normal prose, such as an info, success, warning, or error notice.

FieldTypeRequiredDescription
type'info' | 'success' | 'warning' | 'error'YesNotice type.
titlestringNoShort heading.
descriptionstringYesMain notice text.

The projection includes the notice type, optional title, and description.

mfui.timeline

Shows ordered events, plans, milestones, or schedules.

FieldTypeRequiredDescription
titlestringYesTimeline title.
itemsTimelineItem[]YesOne or more ordered items.

The projection includes the title and lists each item in order.

TimelineItem

FieldTypeRequiredDescription
timestringYesTime, date, or phase label.
titlestringYesItem title.
descriptionstringNoAdditional item details.

mfui.form

Describes a short form that asks the user to provide structured information.

FieldTypeRequiredDescription
titlestringYesForm title.
descriptionstringNoOptional form context.
fieldsFormField[]YesOne or more fields.
submitTextstringNoSubmit button label.

FormField can be any of the following field types.

InputField

FieldTypeRequiredDescription
type'input'YesSingle-line input field.
namestringYesField name, usually used as the submitted value key.
labelstringYesUser-facing field label.
descriptionstringNoField help text.
requiredbooleanNoWhether the field is required.
inputType'text' | 'email' | 'password' | 'url' | 'tel' | 'number'NoInput type.
placeholderstringNoPlaceholder text.
defaultValuestringNoDefault value.

TextareaField

FieldTypeRequiredDescription
type'textarea'YesMulti-line text field.
namestringYesField name, usually used as the submitted value key.
labelstringYesUser-facing field label.
descriptionstringNoField help text.
requiredbooleanNoWhether the field is required.
placeholderstringNoPlaceholder text.
defaultValuestringNoDefault value.

ChoiceField

FieldTypeRequiredDescription
type'choice'YesChoice field that can render as a select, radio group, checkbox group, or similar control.
namestringYesField name, usually used as the submitted value key.
labelstringYesUser-facing field label.
descriptionstringNoField help text.
requiredbooleanNoWhether the field is required.
optionsChoiceOption[]YesOne or more choices.
multiplebooleanNoWhether multiple values can be selected.
placeholderstringNoPlaceholder text.
defaultValuestring | string[]NoDefault selected value. Use a string array for multiple values.

ChoiceOption

FieldTypeRequiredDescription
labelstringYesUser-facing option label.
valuestringYesOption value.
descriptionstringNoAdditional option details.

SwitchField

FieldTypeRequiredDescription
type'switch'YesBoolean switch field.
namestringYesField name, usually used as the submitted value key.
labelstringYesUser-facing field label.
descriptionstringNoField help text.
requiredbooleanNoWhether the field is required.
defaultValuebooleanNoDefault switch state.

DateField

FieldTypeRequiredDescription
type'date'YesDate field.
namestringYesField name, usually used as the submitted value key.
labelstringYesUser-facing field label.
descriptionstringNoField help text.
requiredbooleanNoWhether the field is required.
placeholderstringNoPlaceholder text.
defaultValuestringNoDefault date value.

TimeField

FieldTypeRequiredDescription
type'time'YesTime field.
namestringYesField name, usually used as the submitted value key.
labelstringYesUser-facing field label.
descriptionstringNoField help text.
requiredbooleanNoWhether the field is required.
placeholderstringNoPlaceholder text.
defaultValuestringNoDefault time value.

DatetimeField

FieldTypeRequiredDescription
type'datetime'YesDate-time field.
namestringYesField name, usually used as the submitted value key.
labelstringYesUser-facing field label.
descriptionstringNoField help text.
requiredbooleanNoWhether the field is required.
placeholderstringNoPlaceholder text.
defaultValuestringNoDefault date-time value.

mfui.form does not define submit behavior. Applications decide whether submitting the form disables it, replaces it with text, sends a new user message, or runs another business workflow.

mfui.bar_chart

Compares numeric values across categories. The optional series field can represent grouped bars.

FieldTypeRequiredDescription
titlestringYesChart title.
descriptionstringNoOptional context.
xLabelstringNoX-axis label.
yLabelstringNoY-axis label.
unitstringNoUnit suffix or label, such as users, USD, or %.
dataBarChartDataPoint[]YesData points, up to 100.

BarChartDataPoint

FieldTypeRequiredDescription
labelstringYesCategory label.
valuenumberYesNumeric value.
seriesstringNoGroup name.

mfui.line_chart

Shows numeric change over time or another ordered axis. The optional series field can represent multiple lines.

FieldTypeRequiredDescription
titlestringYesChart title.
descriptionstringNoOptional context.
xLabelstringNoX-axis label.
yLabelstringNoY-axis label.
unitstringNoUnit suffix or label, such as users, USD, or %.
dataLineChartDataPoint[]YesOrdered data points, up to 100.

LineChartDataPoint

FieldTypeRequiredDescription
labelstringYesTime point, phase, or ordered-axis label.
valuenumberYesNumeric value.
seriesstringNoLine series name.

mfui.pie_chart

Shows how non-negative numeric values compose a whole.

FieldTypeRequiredDescription
titlestringYesChart title.
descriptionstringNoOptional context.
unitstringNoUnit suffix or label, such as %.
dataPieChartDataPoint[]YesNon-negative category values, up to 100.

PieChartDataPoint

FieldTypeRequiredDescription
labelstringYesCategory label.
valuenumberYesNon-negative numeric value.