Skip to main content

MCP / AI Tool Integration

eSheet provides Model Context Protocol (MCP) compatible tool definitions and hooks for integrating AI assistants with the builder and renderer.

Overview

The MCP integration allows AI assistants to:

  • Builder: Add fields, modify properties, reorder elements, manage options/rows/columns, add logic rules, fill preview responses
  • Renderer: Fill field responses, get form state, validate submissions, clear responses

Builder Integration

Exports

import {
// MCP tool execution
executeToolCall,
// Tool definitions array (25 tools)
BUILDER_TOOL_DEFINITIONS,
// System prompt constant
BUILDER_SYSTEM_PROMPT,
// React hook for handling AI tool calls
useBuilderMcpToolHandler,
// Types
type ToolDefinition,
type UseBuilderMcpToolHandlerOptions,
} from '@esheet/builder';

Using onBuilderToolsReady

The useBuilderMcpToolHandler hook returns a callback for the builder's onBuilderToolsReady prop. It listens for custom events on a target element and routes them to the appropriate MCP tool.

import { EsheetBuilder, useBuilderMcpToolHandler } from '@esheet/builder';

function App() {
const onBuilderToolsReady = useBuilderMcpToolHandler({
eventName: 'ozwell-tool-call',
target: document, // Optional, defaults to document
});

return <EsheetBuilder onBuilderToolsReady={onBuilderToolsReady} />;
}

Options

interface UseBuilderMcpToolHandlerOptions {
/** The DOM element to listen on for tool-call events. Defaults to document. */
target?: EventTarget;
/** The event name to listen for, e.g. 'ozwell-tool-call'. */
eventName: string;
}

Available Builder Tools

The BUILDER_TOOL_DEFINITIONS array contains 25 tools for form building operations:

Form Overview Tools

ToolDescriptionParameters
get_form_summaryCALL FIRST. Returns {formId, fieldCount, fields} with condensed field info (id, fieldType, question, required, optionCount, rowCount, columnCount, editWith, hasRules, hasValue).None
get_fieldGet full details of one field including options/rows/columns with IDs.fieldQuestion?: string, fieldId?: string
get_definitionExport complete form as JSON definition tree with all fields, options, rows, columns, and logic rules.None
get_field_typesList all available field types with key, label, category, and capabilities.None
get_field_specGet full spec for a specific field type: capabilities, defaults, placeholder hints.fieldType: string (required)

Field CRUD Tools

ToolDescriptionParameters
create_fieldAdd one field. Supports all field types including sections with parentId.fieldType: string, question: string, required?: boolean, options?: {value}[], afterFieldId?: string, parentId?: string, properties?: object
update_fieldChange scalar field properties (question, required, inputType, min, max, step, placeholder).fieldQuestion?: string, fieldId?: string, updates: object
delete_fieldDelete a field by question or ID.fieldQuestion?: string, fieldId?: string
move_fieldReorder a field to a new index position (0-based).fieldQuestion?: string, fieldId?: string, toIndex: number, toParentId?: string
reset_formClear all fields.None

Option Management Tools

For radio, check, dropdown, rating, ranking, slider, multitext fields. NOT for matrix fields.

ToolDescriptionParameters
add_optionAdd an option.fieldQuestion?: string, fieldId?: string, value?: string
update_optionUpdate the label of an existing option.fieldQuestion?: string, fieldId?: string, optionId?: string, currentValue?: string, value: string
remove_optionRemove an option by ID or current label.fieldQuestion?: string, fieldId?: string, optionId?: string, currentValue?: string

Matrix Row/Column Tools

For singlematrix and multimatrix fields only.

ToolDescriptionParameters
add_rowAdd a row to a matrix field.fieldQuestion?: string, fieldId?: string, value?: string
update_rowUpdate a matrix row label.fieldQuestion?: string, fieldId?: string, rowId?: string, currentValue?: string, value: string
remove_rowRemove a matrix row by ID.fieldQuestion?: string, fieldId?: string, rowId: string
add_columnAdd a column to a matrix field.fieldQuestion?: string, fieldId?: string, value?: string
update_columnUpdate a matrix column label.fieldQuestion?: string, fieldId?: string, columnId?: string, currentValue?: string, value: string
remove_columnRemove a matrix column by ID.fieldQuestion?: string, fieldId?: string, columnId: string

Response/Preview Tools

ToolDescriptionParameters
fill_fieldSet a preview response for ONE field. Returns {result, filledCount, unfilledFields}.fieldQuestion?: string, fieldId?: string, value: any
get_responsesGet current response values.None
clear_responsesClear all responses.None

Form Metadata Tools

ToolDescriptionParameters
set_form_idUpdate the top-level form ID.id: string

Conditional Logic Tools

ToolDescriptionParameters
add_field_ruleAdd a conditional logic rule based on another field's response.fieldQuestion?: string, fieldId?: string, effect: 'visible'|'enable'|'required', logic: 'AND'|'OR', conditions: {targetId, operator, expected}[]
add_expression_ruleAdd a conditional rule using a custom expression. Field IDs must be wrapped in {fieldId}.fieldQuestion?: string, fieldId?: string, effect: 'visible'|'enable'|'required', expression: string
remove_ruleRemove a conditional logic rule by 0-based index.fieldQuestion?: string, fieldId?: string, ruleIndex: number

Supported Field Types

text, longtext, multitext, radio, check, boolean, dropdown, multiselectdropdown, rating, ranking, slider, singlematrix, multimatrix, image, html, signature, diagram, display, section

Hook: useBuilderMcpToolHandler

function useBuilderMcpToolHandler(
options: UseBuilderMcpToolHandlerOptions
): (tools: BuilderTools) => void;

The hook returns a function that accepts BuilderTools (provided by the builder via onBuilderToolsReady). When an event matching eventName is dispatched, the hook extracts the tool name and arguments from the event detail and calls executeToolCall.


Renderer Integration

Exports

import {
// MCP tool execution
executeToolCall,
// Tool definitions array (7 tools)
RENDERER_TOOL_DEFINITIONS,
// System prompt constant
RENDERER_SYSTEM_PROMPT,
// React hook for handling AI tool calls
useRendererMcpToolHandler,
// Types
type ToolDefinition,
type UseRendererMcpToolHandlerOptions,
type RendererTools,
} from '@esheet/renderer';

Using onRendererToolsReady

import { EsheetRenderer, useRendererMcpToolHandler } from '@esheet/renderer';

function App() {
const onRendererToolsReady = useRendererMcpToolHandler({
eventName: 'ozwell-tool-call',
});

return (
<EsheetRenderer
formDataInput={definition}
onRendererToolsReady={onRendererToolsReady}
/>
);
}

Available Renderer Tools

The RENDERER_TOOL_DEFINITIONS array contains 7 tools for form filling operations:

ToolDescriptionParameters
get_formReturns visible fields split into filled vs unfilled. Response: {formId, totalFields, filledCount, unfilledFields, filledFieldIds}.None
get_form_rawReturns ALL fields regardless of visibility, conditional rules, or enabled state.None
get_responsesGet current raw response values for all fields.None
get_valid_responseRun form validation. Returns full response if valid, or null plus field-level errors if validation fails.None
fill_fieldSet a response value for ONE visible field. Returns {result, filledCount, unfilledFields}.fieldId?: string, fieldQuestion?: string, value: any
clear_responsesClear all current form responses.None
get_form_treeGet full rendered field tree including visibility, enabled, and required state.None

Fill Field Format Rules

Both Builder and Renderer MCP tools enforce these value formats for fill_field:

Field TypeValue FormatExample
radio / dropdown / boolean / rating / sliderSingle string matching an option value"Yes", "Option A"
check / multiselectdropdownArray of strings matching option values["Option A", "Option B"]
rankingOrdered array of option value strings["First", "Second", "Third"]
multitextArray of strings, one per option slot["John", "Doe"]
singlematrixObject: { "Row Label": "Column Label" }{"Satisfaction": "Very Good"}
multimatrixObject: { "Row Label": ["Col1", "Col2"] }{"Features": ["Speed", "Design"]}
text (date)YYYY-MM-DD"2026-05-21"
text (datetime-local)YYYY-MM-DDTHH:mm"2026-05-21T14:30"
text (month)YYYY-MM"2026-05"
text (time)HH:mm (24-hour)"14:30"
warning

Wrong formats are rejected with an error. Always use the valueFormat property from the field schema.


Expression Rule Syntax

The add_expression_rule tool accepts safe sandbox expressions with these rules:

Field References

Field IDs MUST be wrapped in curly braces: {fieldId}

Available Operators

  • Arithmetic: +, -, *, /, %
  • Comparison: ==, !=, ===, !==, >, >=, <, <=
  • Logical: &&, ||, !
  • Property access: .length, .count on field refs

NOT Available

Function calls (parseInt, parseFloat, .includes, etc.), bare field names, loops, assignments

Examples

// Valid expressions
{f1} > 4 && {f2} < 3
{f3}.length > 0
{f4} == "Yes"

// Invalid expressions
parseInt({f1}) > 4 // No function calls
f1 > 4 // Missing braces

Condition Operators

For add_field_rule conditions:

OperatorDescription
equalsValue equals expected
notEqualsValue does not equal expected
containsString contains substring
includesArray includes value (for multi-select)
emptyValue is empty/null (no expected needed)
notEmptyValue is not empty/null (no expected needed)
greaterThanNumeric comparison
greaterThanOrEqualNumeric comparison
lessThanNumeric comparison
lessThanOrEqualNumeric comparison

System Prompts

eSheet exports system prompts optimized for AI assistants:

Builder System Prompt

import { BUILDER_SYSTEM_PROMPT } from '@esheet/builder';

Includes field type guidance, workflow instructions (call get_form_summary first, use reset_form when building from scratch), matrix vs option tool distinctions, section nesting, preview fill workflow, and text format rules.

Renderer System Prompt

import { RENDERER_SYSTEM_PROMPT } from '@esheet/renderer';

Includes fill workflow (iterate on unfilledFields), format rules for all field types, and guidance on using get_form_raw, get_form_tree, and get_valid_response.


Direct Tool Execution

For advanced integrations, you can call executeToolCall directly:

import { executeToolCall, type BuilderTools } from '@esheet/builder';

// builderTools is provided via onBuilderToolsReady callback
const result = executeToolCall(
'create_field',
{ fieldType: 'text', question: 'Your name' },
builderTools
);