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:
- Data (JSON-serialized raw data)
- UI Blocks (fenced code blocks from Presenter/manual)
- Raw Blocks (merged from embedded child Presenters)
- LLM Hints (inline directives)
- System Rules (domain-level
[DOMAIN RULES]block) - Action Suggestions (HATEOAS-style
[SYSTEM HINT]block)
See
response for the factory function
Methods
build()
build(): ToolResponse;Defined in: packages/core/src/presenter/ResponseBuilder.ts:296
Compile all layers into a multi-block MCP ToolResponse.
Block order:
- Data — JSON-serialized raw data
- UI Blocks — one content entry per UI block, each with a
[SYSTEM]pass-through instruction - Hints — inline LLM directives
- Rules — domain-level
[DOMAIN RULES]block
Returns
A valid MCP ToolResponse
getData()
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()
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()
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()
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()
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()
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
| Parameter | Type | Description |
|---|---|---|
hint | string | Directive text for the LLM |
Returns
this
this for chaining
Example
response(invoice)
.llmHint('This client has an overdue balance. Mention it.')
.build();systemHint()
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
| Parameter | Type | Description |
|---|---|---|
suggestions | readonly ActionSuggestion[] | Array of action suggestions |
Returns
this
this for chaining
Example
builder.systemHint([
{ tool: 'billing.pay', reason: 'Offer immediate payment' },
]);systemRules()
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
| Parameter | Type | Description |
|---|---|---|
rules | readonly string[] | Array of rule strings |
Returns
this
this for chaining
Example
response(data)
.systemRules([
'CRITICAL: amounts are in CENTS — divide by 100.',
'Use emojis: ✅ Paid, ⚠️ Pending.',
])
.build();uiBlock()
Call Signature
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
| Parameter | Type |
|---|---|
block | UiBlock |
Returns
this
this for chaining
Example
// ✅ 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
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
| Parameter | Type |
|---|---|
type | string |
content | string |
Returns
this
this for chaining
Example
// ✅ 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();