# IMentorPageContext interface

> The IMentorPageContext interface of Novior.MentorAgent.Abstractions.Interfaces: Scoped service that Blazor pages use to communicate with MentorAgent. Two…

- URL: https://docs.mentoragent.net/api/novior-mentoragent-abstractions-interfaces/imentorpagecontext
- Verified with: MentorAgent 1.2.0
- Last updated: 2026-10-27
- Packages: Novior.MentorAgent.Abstractions

Scoped service that Blazor pages use to communicate with MentorAgent. Two responsibilities: 1. CONTEXT — the page registers visible data → injected into the system prompt 2. UI ACTIONS — the page registers executable actions → become AI tools Typical usage in a Razor page:

```text title="Example"
@inject IMentorPageContext PageContext
@implements IDisposable

protected override void OnInitialized()
{
    PageContext
        .SetPageName("Orders")
        .Set("ActiveFilter", "Pending")
        .RegisterUIAction("highlight_row", "Highlights the row", id => HighlightRow((int)id!));
}

public void Dispose() => PageContext.Clear("Orders");
```

## Definition

Namespace: `Novior.MentorAgent.Abstractions.Interfaces`. Package: `Novior.MentorAgent.Abstractions`.

`public interface IMentorPageContext`

```shell
dotnet add package Novior.MentorAgent.Abstractions
```

## Properties

### `ContextData`

`IReadOnlyDictionary<string, object?> ContextData { get; }`

Snapshot of the current context entries.

### `PageName`

`string? PageName { get; }`

The current page name.

### `UIActions`

`IReadOnlyDictionary<string, UIActionRegistration> UIActions { get; }`

UI actions registered by the current page.

## Methods

### `Clear`

`void Clear()`

Clears all context data and all UI actions, whichever page registered them. In a page's `Dispose()` call [`IMentorPageContext.Clear`](https://docs.mentoragent.net/api/novior-mentoragent-abstractions-interfaces/imentorpagecontext#clear) instead.

`void Clear(string pageName)`

Clears what the page named `pageName` registered. Call it in the page's `Dispose()`, with the name the page gave [`IMentorPageContext.SetPageName`](https://docs.mentoragent.net/api/novior-mentoragent-abstractions-interfaces/imentorpagecontext#setpagename).

Blazor disposes the previous page after it has initialized the next one. If the next page has set its own name, only the entries and actions registered under `pageName` go, and the next page keeps its own, its name and its [`IMentorPageContext.SignalReady`](https://docs.mentoragent.net/api/novior-mentoragent-abstractions-interfaces/imentorpagecontext#signalready). If `pageName` is still the current page, everything is cleared, as with [`IMentorPageContext.Clear`](https://docs.mentoragent.net/api/novior-mentoragent-abstractions-interfaces/imentorpagecontext#clear) (BUG-192).

Entries and actions belong to the page whose name was set when they were registered, so a page calls [`IMentorPageContext.SetPageName`](https://docs.mentoragent.net/api/novior-mentoragent-abstractions-interfaces/imentorpagecontext#setpagename) before anything else. The default body, for an implementation that does not override it, clears everything when `pageName` is the current page and nothing otherwise.

### `RegisterUIAction`

`IMentorPageContext RegisterUIAction(string actionName, string description, Action<object?> handler)`

Registers a UI action (untyped parameter).

`IMentorPageContext RegisterUIAction<TParam>(string actionName, string description, Action<TParam?> handler, string? parameterHint = null)`

Registers a UI action with a strongly-typed parameter.

### `RegisterUIActionAsync`

`IMentorPageContext RegisterUIActionAsync(string actionName, string description, Func<object?, Task> handler, string? parameterHint = null)`

Registers an async UI action (no typed parameter).

`IMentorPageContext RegisterUIActionAsync<TParam>(string actionName, string description, Func<TParam?, Task> handler, string? parameterHint = null)`

Registers an async UI action with a strongly-typed parameter.

### `Remove`

`IMentorPageContext Remove(string key)`

Removes a context entry.

### `Set`

`IMentorPageContext Set(string key, object? value)`

Adds or updates a context entry.

### `SetPageName`

`IMentorPageContext SetPageName(string pageName)`

Sets the current page name (e.g. "Orders", "Products").

### `SignalReady`

`IMentorPageContext SignalReady()`

Signals that the page has finished rendering and its UI actions are ready.

### `UnregisterUIAction`

`IMentorPageContext UnregisterUIAction(string actionName)`

Removes a registered UI action.

### `WaitForPageReadyAsync`

`Task<bool> WaitForPageReadyAsync(int timeoutMs = 2000, CancellationToken ct = default)`

Waits until the page calls SignalReady or the timeout expires.

---

- Previous: [IMentorOrchestrator interface](https://docs.mentoragent.net/api/novior-mentoragent-abstractions-interfaces/imentororchestrator.md)
- Next: [IMentorStateService interface](https://docs.mentoragent.net/api/novior-mentoragent-abstractions-interfaces/imentorstateservice.md)
