> ## Documentation Index
> Fetch the complete documentation index at: https://mcpjam-docs-coming-from-mcp-inspector.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# PromptResult

> API reference for PromptResult

The `PromptResult` class wraps every response from `HostRunner.run()`. It provides methods to inspect tool calls, performance metrics, errors, and conversation history.

## Import

```typescript theme={null}
// PromptResult is returned by HostRunner.run()
// You don't import it directly

const result = await agent.run("...");
// result is a PromptResult
```

***

## Text Response

### text

The final text response from the LLM.

```typescript theme={null}
readonly text: string
```

#### Value

`string` - The assistant's text response. Empty string if no text response.

#### Example

```typescript theme={null}
const result = await agent.run("What is 2 + 2?");
console.log(result.text); // "2 + 2 equals 4."
```

***

## Tool Call Methods

### toolsCalled()

Returns the names of all tools that were called.

```typescript theme={null}
toolsCalled(): string[]
```

#### Returns

`string[]` - Array of tool names in call order.

#### Example

```typescript theme={null}
const result = await agent.run("Add 2 and 3, then multiply by 4");
console.log(result.toolsCalled()); // ["add", "multiply"]
```

***

### hasToolCall()

Checks if a specific tool was called.

```typescript theme={null}
hasToolCall(toolName: string): boolean
```

#### Parameters

| Parameter  | Type     | Description            |
| ---------- | -------- | ---------------------- |
| `toolName` | `string` | The tool name to check |

#### Returns

`boolean` - `true` if the tool was called.

#### Example

```typescript theme={null}
if (result.hasToolCall("add")) {
  console.log("Addition was performed");
}
```

***

### getToolCalls()

Returns detailed information about all tool calls.

```typescript theme={null}
getToolCalls(): ToolCall[]
```

#### Returns

`ToolCall[]` - Array of tool call objects.

#### ToolCall Type

| Property    | Type               | Description                  |
| ----------- | ------------------ | ---------------------------- |
| `toolName`  | `string`           | Name of the tool             |
| `arguments` | `Record<any, any>` | Arguments passed to the tool |

#### Example

```typescript theme={null}
const calls = result.getToolCalls();

for (const call of calls) {
  console.log(`${call.toolName}(${JSON.stringify(call.arguments)})`);
}
// add({"a":2,"b":3})
// multiply({"a":5,"b":4})
```

***

### getToolArguments()

Returns the arguments passed to a specific tool.

```typescript theme={null}
getToolArguments(toolName: string): Record<string, unknown> | undefined
```

#### Parameters

| Parameter  | Type     | Description   |
| ---------- | -------- | ------------- |
| `toolName` | `string` | The tool name |

#### Returns

`Record<string, unknown> | undefined` - The arguments, or `undefined` if tool wasn't called.

<Note>
  If the tool was called multiple times, returns arguments from the **first** call. Use `getToolCalls()` to access all calls.
</Note>

#### Example

```typescript theme={null}
const args = result.getToolArguments("add");
console.log(args); // { a: 2, b: 3 }
```

***

## Error Handling

### hasError()

Checks if an error occurred.

```typescript theme={null}
hasError(): boolean
```

#### Returns

`boolean` - `true` if an error occurred.

#### Example

```typescript theme={null}
if (result.hasError()) {
  console.error("Something went wrong");
}
```

***

### getError()

Returns the error message if one occurred.

```typescript theme={null}
getError(): string | undefined
```

#### Returns

`string | undefined` - The error message, or `undefined` if no error.

#### Example

```typescript theme={null}
if (result.hasError()) {
  console.error("Error:", result.getError());
}
```

***

## Latency Metrics

### e2eLatencyMs()

Total wall-clock time for the prompt.

```typescript theme={null}
e2eLatencyMs(): number
```

#### Returns

`number` - Milliseconds.

***

### llmLatencyMs()

Time spent waiting for LLM API responses.

```typescript theme={null}
llmLatencyMs(): number
```

#### Returns

`number` - Milliseconds.

***

### mcpLatencyMs()

Time spent executing MCP tools.

```typescript theme={null}
mcpLatencyMs(): number
```

#### Returns

`number` - Milliseconds.

***

### getLatency()

Returns the complete latency breakdown.

```typescript theme={null}
getLatency(): LatencyBreakdown
```

#### Returns

```typescript theme={null}
interface LatencyBreakdown {
  e2eMs: number;   // Total time
  llmMs: number;   // LLM API time
  mcpMs: number;   // Tool execution time
}
```

#### Example

```typescript theme={null}
const latency = result.getLatency();

console.log(`Total: ${latency.e2eMs}ms`);
console.log(`LLM: ${latency.llmMs}ms`);
console.log(`Tools: ${latency.mcpMs}ms`);
```

***

## Token Usage

### totalTokens()

Total tokens used (input + output).

```typescript theme={null}
totalTokens(): number
```

***

### inputTokens()

Tokens used for input (prompt + context).

```typescript theme={null}
inputTokens(): number
```

***

### outputTokens()

Tokens generated by the LLM.

```typescript theme={null}
outputTokens(): number
```

#### Example

```typescript theme={null}
console.log(`Input: ${result.inputTokens()}`);
console.log(`Output: ${result.outputTokens()}`);
console.log(`Total: ${result.totalTokens()}`);
```

***

## Conversation History

### getMessages()

Returns the full conversation as a `CoreMessage[]` array.

```typescript theme={null}
getMessages(): CoreMessage[]
```

#### Returns

`CoreMessage[]` - The full conversation message format used by the SDK.

#### Example

```typescript theme={null}
const messages = result.getMessages();

for (const msg of messages) {
  console.log(`[${msg.role}]:`, msg.content);
}
```

***

### getUserMessages()

Returns only user messages.

```typescript theme={null}
getUserMessages(): CoreMessage[]
```

***

### getAssistantMessages()

Returns only assistant messages.

```typescript theme={null}
getAssistantMessages(): CoreMessage[]
```

***

### getToolMessages()

Returns only tool result messages.

```typescript theme={null}
getToolMessages(): CoreMessage[]
```

#### Example

```typescript theme={null}
const toolMsgs = result.getToolMessages();

for (const msg of toolMsgs) {
  console.log("Tool result:", msg.content);
}
```

***

## MCP App widget snapshots

### getWidgetSnapshots()

Returns HTML snapshot payloads captured during tool execution for **MCP Apps** (one entry per relevant tool call when replay data was collected).

```typescript theme={null}
getWidgetSnapshots(): EvalWidgetSnapshotInput[]
```

#### Returns

`EvalWidgetSnapshotInput[]` — metadata plus inline HTML (before upload) or storage ids after reporting. Empty if no MCP App tools ran or if [`HostRunner`](/sdk/reference/host-runner) was created **without** [`mcpClientManager`](/sdk/reference/host-runner#parameters).

#### Why the manager matters

MCP App UIs reference HTML via **`ui.resourceUri`**. That HTML is fetched with MCP **`resources/read`**, which only the connected [`MCPClientManager`](/sdk/reference/mcp-client-manager) can perform. The model’s tool **result** is not a substitute for that document, so **`getWidgetSnapshots()` stays empty unless you pass the same `manager` into `new HostRunner({ …, mcpClientManager: manager })`**.

When you report results to MCPJam (for example via [`createEvalRunReporter`](/sdk/reference/eval-reporting#createevalrunreporter) or [`PromptResult.toEvalResult()`](/sdk/reference/prompt-result)), snapshots are uploaded and linked from the trace so the dashboard can **replay widgets offline**.

#### Example

```typescript theme={null}
const result = await agent.run("Open the chart widget");

const snapshots = result.getWidgetSnapshots();
console.log("Snapshots:", snapshots.length);
// After reporting, snapshots are merged into each eval result's trace on MCPJam
```

***

## toEvalResult()

Builds an [`EvalResultInput`](/sdk/reference/eval-reporting#evalresultinput) for MCPJam reporting (messages, spans, tool calls, tokens, optional widget snapshots).

```typescript theme={null}
toEvalResult(
  options?: Partial<Omit<EvalResultInput, "actualToolCalls" | "tokens" | "trace">> & {
    failOnToolError?: boolean;
  },
): EvalResultInput
```

The **`passed`** field combines your explicit or inferred structural outcome with **tool execution** checks (see [Tool execution and `passed`](/sdk/reference/eval-reporting#tool-execution-and-passed)): by default, failures in the trace (MCP `isError`, errored tool spans, error-shaped tool-results) force `passed: false` even if you pass `passed: true` in `options`. Set **`failOnToolError: false`** in `options` to keep structural / explicit `passed` only.

See [Tool execution and `passed`](/sdk/reference/eval-reporting#tool-execution-and-passed) in the eval reporting reference.

***

## Using as Context

Pass `PromptResult` as context for multi-turn conversations.

```typescript theme={null}
const r1 = await agent.run("Create a project");

// Single result as context
const r2 = await agent.run("Add a task", { context: r1 });

// Multiple results as context
const r3 = await agent.run("Show summary", { context: [r1, r2] });
```

***

## Complete Example

```typescript theme={null}
const result = await agent.run("Add 100 and 200");

// Response
console.log("Text:", result.text);

// Tool calls
console.log("Tools:", result.toolsCalled());
console.log("Has add?", result.hasToolCall("add"));
console.log("Add args:", result.getToolArguments("add"));

for (const call of result.getToolCalls()) {
  console.log(`  ${call.toolName}:`, call.arguments);
}

// Errors
if (result.hasError()) {
  console.error("Error:", result.getError());
}

// Performance
console.log("Latency:", result.e2eLatencyMs(), "ms");
console.log("  LLM:", result.llmLatencyMs(), "ms");
console.log("  Tools:", result.mcpLatencyMs(), "ms");

// Tokens
console.log("Tokens:", result.totalTokens());
console.log("  Input:", result.inputTokens());
console.log("  Output:", result.outputTokens());

// History
console.log("Messages:", result.getMessages().length);
```

***

## Related

* [Testing with LLMs](/sdk/concepts/testing-with-llms) - Conceptual guide
* [Validators Reference](/sdk/reference/validators) - Assert tool calls
* [HostRunner Reference](/sdk/reference/host-runner) - Agent configuration
