Skip to content

Class: ResponseBuilder

Defined in: packages/core/src/presenter/ResponseBuilder.ts:84

Fluent builder for multi-content-block MCP responses.

Each method appends a semantic layer. The final .build() compiles all layers into an array of { type: "text", text: "..." } blocks, one per layer, following MCP's multimodal content specification.

Content block order:

  1. Data (JSON-serialized raw data)
  2. UI Blocks (fenced code blocks from Presenter/manual)
  3. Raw Blocks (merged from embedded child Presenters)
  4. LLM Hints (inline directives)
  5. System Rules (domain-level [DOMAIN RULES] block)
  6. Action Suggestions (HATEOAS-style [SYSTEM HINT] block)

See

response for the factory function

Methods

build()

ts
build(): ToolResponse;

Defined in: packages/core/src/presenter/ResponseBuilder.ts:296

Compile all layers into a multi-block MCP ToolResponse.

Block order:

  1. Data — JSON-serialized raw data
  2. UI Blocks — one content entry per UI block, each with a [SYSTEM] pass-through instruction
  3. Hints — inline LLM directives
  4. Rules — domain-level [DOMAIN RULES] block

Returns

ToolResponse

A valid MCP ToolResponse


getData()

ts
getData(): string;

Defined in: packages/core/src/presenter/ResponseBuilder.ts:242

Get the serialized data payload.

Returns the JSON-stringified (or raw string) data that was passed to the constructor.

Returns

string

The data string

Remarks

Used by PromptMessage.fromView to decompose a Presenter view into prompt messages without calling .build().


getHints()

ts
getHints(): readonly string[];

Defined in: packages/core/src/presenter/ResponseBuilder.ts:269

Get the accumulated LLM hints.

Returns

readonly string[]

Read-only array of hint strings


getRules()

ts
getRules(): readonly string[];

Defined in: packages/core/src/presenter/ResponseBuilder.ts:251

Get the accumulated domain rules.

Returns

readonly string[]

Read-only array of rule strings


getSuggestions()

ts
getSuggestions(): readonly ActionSuggestion[];

Defined in: packages/core/src/presenter/ResponseBuilder.ts:278

Get the accumulated action suggestions.

Returns

readonly ActionSuggestion[]

Read-only array of action suggestions


getUiBlocks()

ts
getUiBlocks(): readonly UiBlock[];

Defined in: packages/core/src/presenter/ResponseBuilder.ts:260

Get the accumulated UI blocks.

Returns

readonly UiBlock[]

Read-only array of UI blocks


llmHint()

ts
llmHint(hint): this;

Defined in: packages/core/src/presenter/ResponseBuilder.ts:163

Append an inline LLM hint to the response.

Hints are action-specific directives that guide the LLM's behavior for this particular response. Unlike system rules, hints are typically added manually in handlers for dynamic context.

Parameters

ParameterTypeDescription
hintstringDirective text for the LLM

Returns

this

this for chaining

Example

typescript
response(invoice)
    .llmHint('This client has an overdue balance. Mention it.')
    .build();

systemHint()

ts
systemHint(suggestions): this;

Defined in: packages/core/src/presenter/ResponseBuilder.ts:209

Append HATEOAS-style action suggestions to the response.

Generates a [SYSTEM HINT] block with recommended next tools, guiding the AI through the business state machine.

Parameters

ParameterTypeDescription
suggestionsreadonly ActionSuggestion[]Array of action suggestions

Returns

this

this for chaining

Example

typescript
builder.systemHint([
    { tool: 'billing.pay', reason: 'Offer immediate payment' },
]);

systemRules()

ts
systemRules(rules): this;

Defined in: packages/core/src/presenter/ResponseBuilder.ts:188

Append domain-level system rules to the response.

Rules are JIT context directives that travel with the data, eliminating the need for bloated system prompts. They are rendered as a [DOMAIN RULES] block in the response.

Parameters

ParameterTypeDescription
rulesreadonly string[]Array of rule strings

Returns

this

this for chaining

Example

typescript
response(data)
    .systemRules([
        'CRITICAL: amounts are in CENTS — divide by 100.',
        'Use emojis: ✅ Paid, ⚠️ Pending.',
    ])
    .build();

uiBlock()

Call Signature

ts
uiBlock(block): this;

Defined in: packages/core/src/presenter/ResponseBuilder.ts:122

Append a UI block to the response.

Each UI block becomes a separate content entry in the MCP response, with a system instruction for the LLM to pass it through unchanged.

Accepts either a UiBlock object (recommended) or a manual (type, content) pair.

Parameters
ParameterType
blockUiBlock
Returns

this

this for chaining

Example
typescript
// ✅ Recommended: pass a UiBlock directly
response(data).uiBlock(ui.echarts(chartConfig)).build();

// Also valid: manual type + content
response(data).uiBlock('echarts', '```echarts\n{...}\n```').build();

Call Signature

ts
uiBlock(type, content): this;

Defined in: packages/core/src/presenter/ResponseBuilder.ts:123

Append a UI block to the response.

Each UI block becomes a separate content entry in the MCP response, with a system instruction for the LLM to pass it through unchanged.

Accepts either a UiBlock object (recommended) or a manual (type, content) pair.

Parameters
ParameterType
typestring
contentstring
Returns

this

this for chaining

Example
typescript
// ✅ Recommended: pass a UiBlock directly
response(data).uiBlock(ui.echarts(chartConfig)).build();

// Also valid: manual type + content
response(data).uiBlock('echarts', '```echarts\n{...}\n```').build();