Skip to content

App class does not store hostContext from initialize response #129

Closed

Description

@KushagraAgarwal525

Summary

The App class receives hostContext in the McpUiInitializeResult response but does not store it internally, making initial host context inaccessible to apps after connection.

Current Behavior

The McpUiInitializeResult interface includes hostContext:
https://github.com/modelcontextprotocol/ext-apps/blob/main/src/spec.types.ts#L313-L327

export interface McpUiInitializeResult {
  protocolVersion: string;
  hostInfo: Implementation;
  hostCapabilities: McpUiHostCapabilities;
  hostContext: McpUiHostContext;  // Present in response
}

However, the connect method only stores hostCapabilities and hostInfo:
https://github.com/modelcontextprotocol/ext-apps/blob/main/src/app.ts#L879-L880

this._hostCapabilities = result.hostCapabilities;
this._hostInfo = result.hostInfo;
// hostContext is not stored

Impact

Apps cannot access initial host context after connection. This creates several issues:

  1. toolInfo is permanently inaccessible - The toolInfo field (containing the tool definition and request ID that triggered this app) is only sent in the initial response, never via the host-context-changed notification.
  2. Theme/layout flash - Apps may render with incorrect theme or layout initially before receiving the first host-context-changed notification.
  3. Missing initial viewport/locale - Apps cannot synchronously access viewport dimensions, locale, or timezone during first render.

Expected Behavior

The App class should store and expose initial hostContext:

class App extends Protocol<...> {
  private _hostContext?: McpUiHostContext;
  
  getHostContext(): McpUiHostContext | undefined {
    return this._hostContext;
  }
  
  async connect(transport: Transport, options?: RequestOptions): Promise<void> {
    // ...
    this._hostCapabilities = result.hostCapabilities;
    this._hostInfo = result.hostInfo;
    this._hostContext = result.hostContext;  // Add this
    // ...
  }
}

Proposed API

Add a getHostContext method parallel to existing getHostCapabilities and getHostVersion:

const app = new App({ name: "MyApp", version: "1.0.0" }, {});
await app.connect(transport);
const context = app.getHostContext();
console.log(context?.toolInfo?.tool.name);  // Which tool spawned this app
console.log(context?.theme);                 // Initial theme

Additional Consideration

The host-context-changed handler should merge updates into the stored context, so getHostContext always returns the current state:

app.onhostcontextchanged = (params) => {
  // Handler fires
};
// getHostContext returns merged initial + updates
const currentContext = app.getHostContext();

This would provide a unified way to access context state without apps needing to manually track and merge partial updates.

Activity

  1. added 2 commits that reference this issue on Dec 11, 2025
    36aa8a8
    1a95181
  2. added a commit that references this issue on Dec 11, 2025
    eaea3f9
  3. ochafik commented on Dec 11, 2025

    @ochafik
    Contributor

    Thanks @KushagraAgarwal525 for the report / suggestion! App.getHostContext() has just shipped in v0.1.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions