Repository navigation
Open
Description
Summary
All on* request-handler setters on App (onteardown, oncalltool, onlisttools) and AppBridge (onmessage, onopenlink, ondownloadfile, onrequestdisplaymode, onupdatemodelcontext, oncalltool, oncreatesamplingmessage, onlistresources, onlistresourcetemplates, onreadresource, onlistprompts) accept undefined to clear a previously registered handler (or forward an optional callback property).
Currently, assigning undefined still invokes this.replaceRequestHandler(...) with a fallback closure that throws Error("No on... handler set"), causing four problems:
AppBridge.onrequestdisplaymode = undefinedbreaks the built-in default handler:AppBridgeinstalls a defaultui/request-display-modehandler in its constructor that returns{ mode: this._hostContext.displayMode ?? "inline" }. Assigningbridge.onrequestdisplaymode = undefined(either to clear a custom override or when forwarding an optionalprops.onRequestDisplayMode) overwrites that default handler, causingapp.requestDisplayMode(...)to reject with JSON-RPC-32603(No onrequestdisplaymode handler set).App.oncalltool = undefinedandApp.onlisttools = undefinedthrow withouttoolscapability: Assigningundefinedon anAppconstructed without{ tools }capability callsreplaceRequestHandler("tools/call", ...), which triggersassertRequestHandlerCapabilityand synchronously throwsClient does not support tool capability (required for tools/call).- Cleared optional handlers return
-32603instead of-32601: Before an optionalon*request setter (such asapp.onteardownorbridge.onopenlink) is set, incoming requests fail with JSON-RPC-32601(Method not found). After assigning a handler and clearing it with= undefined, incoming requests instead fail with-32603(Internal error: No on... handler set). MethodRegistryremains locked after clearing: BecausereplaceRequestHandlerkeeps the method claimed in_methodsinstead of callingremoveRequestHandler, callingsetRequestHandler(method, ...)afteron* = undefinedstill throwsHandler for "<method>" already registered.
Minimal reproduction
import { InMemoryTransport } from "@modelcontextprotocol/client";
import { App } from "@modelcontextprotocol/ext-apps";
import { AppBridge } from "@modelcontextprotocol/ext-apps/app-bridge";
// 1. App without tools capability throws when assigning undefined:
const app = new App({ name: "view", version: "1.0.0" }, {}, { autoResize: false });
app.oncalltool = undefined; // Throws: Client does not support tool capability (required for tools/call)
// 2. AppBridge loses default ui/request-display-mode handler when assigned undefined:
const [appTransport, bridgeTransport] = InMemoryTransport.createLinkedPair();
const bridge = new AppBridge(null, { name: "host", version: "1.0.0" }, {});
bridge.onrequestdisplaymode = undefined;
await bridge.connect(bridgeTransport);
await app.connect(appTransport);
await app.requestDisplayMode({ mode: "fullscreen" });
// Rejects with ProtocolError (-32603): No onrequestdisplaymode handler setExpected behavior
- Assigning
undefinedto anon*request setter when a handler was previously set via that setter should unregister the request handler viaremoveRequestHandler(method)(releasingMethodRegistryand returning-32601on subsequent requests), exceptAppBridge.onrequestdisplaymode = undefined, which should restoreAppBridge's defaultui/request-display-modehandler. - Assigning
undefinedwhen theon*request setter is alreadyundefinedshould be a no-op (not throwing capability errors, not overwritingAppBridge's defaultui/request-display-modehandler, and not removing a handler registered directly viasetRequestHandler).
AI-assisted: root-caused and drafted with an AI coding agent; verified locally against main.
Metadata
Metadata
Assignees
Labels
No labels
Activity