Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ Local builds retain the `development` telemetry environment. Public releases use
Claude's server shows Mobile Dev in a browser beside the chat; in the Claude desktop
app's Code tab that is its built-in browser pane. The terminal advertises no MCP Apps
support, but the Code tab does (Claude Code runs there with `CLAUDE_CODE_MCP_APPS_HOST=1`)
and would render the panel inline. So Claude's server passes `createPanel({ inline: false })`,
and would render the panel inline. So Claude's server passes `createPanel({ placement: "browser" })`,
whose opening tools carry no `ui.resourceUri` for a host to render and name their page under
`mobile-dev/panel` instead, and `browserPanel({ always: true })`, which links the page for
every host. Opening a recording in the workspace is left out there; recordings stay chat
Expand Down
2 changes: 1 addition & 1 deletion apps/claude/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ if (pinned !== undefined) {
const download = downloadedPanelRuntime(release);
usePanelRuntime(download.ensure);
}
await runStdioServer({ panel: createPanel({ inline: false }), features: [agentDeviceTools(readAgentDeviceCatalog()), browserPanel({ always: true })] });
await runStdioServer({ panel: createPanel({ placement: "browser" }), features: [agentDeviceTools(readAgentDeviceCatalog()), browserPanel({ always: true })] });
6 changes: 3 additions & 3 deletions apps/codex-plugin/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ if (!process.env.MOBILE_DEV_E2E_RUNTIME?.trim()) {
const release = panelRuntimeReleaseSchema.parse(metadata);
useDownloadedTestingRuntime(release);
}
const inline = panelPlacement("inline") === "inline";
const panelContext = inline ? panelSelection : browserPanel({ always: true });
const placement = panelPlacement("inline") === "browser" ? "browser" : "sidebar";
const panelContext = placement === "sidebar" ? panelSelection : browserPanel({ always: true });
const features = [agentDeviceTools(readAgentDeviceCatalog()), codexUpdates, panelContext];
await runStdioServer({ panel: createPanel({ inline }), features });
await runStdioServer({ panel: createPanel({ placement }), features });
20 changes: 12 additions & 8 deletions apps/codex-plugin/test/display-mode-control.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { setTimeout } from "node:timers/promises";
import { build } from "esbuild";
import { JSDOM } from "jsdom";

// Both hosts advertise inline and fullscreen. Claude has no control of its own to
// leave the expanded view, so the shared panel offers one; Codex has its own.
// The shared panel can return to chat. Codex closes its sidebar through the host tab.
for (const [host, entry, shown] of [
["shared MCP Apps panel", "packages/mcp-app/src/main.tsx", true],
["Codex panel", "apps/codex-plugin/ui/main.tsx", false],
Expand All @@ -14,7 +13,8 @@ for (const [host, entry, shown] of [
entryPoints: [entry], bundle: true, write: false, format: "iife", platform: "browser", jsx: "automatic",
loader: { ".css": "empty", ".woff2": "empty", ".woff": "empty" }, define: { "process.env.NODE_ENV": '"production"' },
});
const dom = new JSDOM('<html data-view="workspace"><head><meta name="mobile-dev-environment" content="development"><meta name="mobile-dev-telemetry" content="off"></head><body><div id="root"></div></body></html>', {
const placement = shown ? "" : "data-sidebar-only";
const dom = new JSDOM(`<html ${placement} data-view="workspace"><head><meta name="mobile-dev-environment" content="development"><meta name="mobile-dev-telemetry" content="off"></head><body><div id="root"></div></body></html>`, {
pretendToBeVisual: true, runScripts: "outside-only", url: "https://mobile-dev.test/",
});
const window = dom.window;
Expand All @@ -23,17 +23,20 @@ for (const [host, entry, shown] of [
window.HTMLCanvasElement.prototype.getContext = () => ({ drawImage() {} });
Object.defineProperty(window.HTMLElement.prototype, "clientWidth", { get: () => 400 });
Object.defineProperty(window.HTMLElement.prototype, "clientHeight", { get: () => 800 });
let advertisedModes: string[] | undefined;
let initialized = false;
let tornDown = false;
function send(message: object) {
window.dispatchEvent(new window.MessageEvent("message", { data: { jsonrpc: "2.0", ...message }, source: window }));
}
window.postMessage = message => {
if (message.method === "ui/initialize") send({ id: message.id, result: {
protocolVersion: "2026-01-26", hostInfo: { name: "test", version: "1" }, hostCapabilities: { serverTools: {}, serverResources: {} },
hostContext: { displayMode: "fullscreen", availableDisplayModes: ["inline", "fullscreen"] },
} });
else if (message.method === "ui/notifications/initialized") initialized = true;
if (message.method === "ui/initialize") {
advertisedModes = message.params.appCapabilities.availableDisplayModes;
send({ id: message.id, result: {
protocolVersion: "2026-01-26", hostInfo: { name: "test", version: "1" }, hostCapabilities: { serverTools: {}, serverResources: {} },
hostContext: { displayMode: "fullscreen", availableDisplayModes: ["inline", "fullscreen"] },
} });
} else if (message.method === "ui/notifications/initialized") initialized = true;
else if (message.id === "teardown") tornDown = true;
else if (message.id !== undefined) send({ id: message.id, result: { content: [] } });
};
Expand All @@ -48,6 +51,7 @@ for (const [host, entry, shown] of [
});
window.eval(built.outputFiles[0].text);
await until(() => initialized);
assert.deepEqual(Array.from(advertisedModes ?? []), shown ? ["inline", "fullscreen"] : ["fullscreen"]);
await until(() => window.document.querySelector(".workspace-toolbar") !== null);
// Hosts follow the handshake with context changes; the control reacts to those.
send({ method: "ui/notifications/host-context-changed", params: { displayMode: "fullscreen", availableDisplayModes: ["inline", "fullscreen"] } });
Expand Down
2 changes: 1 addition & 1 deletion docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ A host adds to the shared pieces without changing them:
and the native device form. Codex, Cursor's shared entry and the Mac app pass it.
Codex and Cursor add agent-device's commands, and Codex the self-updater, which
installs through Codex's marketplace; the Mac app, which has no agent, adds its page
resource. Claude's entry (`apps/claude/server`) passes the panel with `inline: false`,
resource. Claude's entry (`apps/claude/server`) passes the panel with `placement: "browser"`,
so even MCP Apps hosts such as the desktop app's Code tab render none in the chat, and
the browser panel feature with `always: true`, which shows it beside the chat in a
browser; it adds agent-device's commands. `MOBILE_DEV_PANEL=browser`
Expand Down
2 changes: 1 addition & 1 deletion docs/devices.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Android tools look for the SDK in `ANDROID_HOME`, `ANDROID_SDK_ROOT`, and the de

## Device panel

Open a new chat after installing. Open Mobile Dev in the sidebar or call `mobile_open_workspace` for the fullscreen view. Call `mobile_open_simulator` for the panel beside a chat. Both opening tools accept optional `platform`, `kind`, and discovered `deviceId` arguments. For example, `{ platform: "android", kind: "emulator" }` opens Android and selects an emulator before connecting; `kind: "physical"` selects a connected phone. An unavailable requested target stays unselected, with a message and the device picker available. Opening never boots a device. Without targeting, iOS opens when both platforms have running devices; Android opens when it has the only running device. Later manual device selections replace the opening choice.
Open a new chat after installing. Open Mobile Dev in the sidebar or call `mobile_open_workspace` for the fullscreen view. Call `mobile_open_simulator` for the panel beside a chat. In Codex, the live device stays in the sidebar. Closing its tab leaves the chat entry collapsed. Both opening tools accept optional `platform`, `kind`, and discovered `deviceId` arguments. For example, `{ platform: "android", kind: "emulator" }` opens Android and selects an emulator before connecting; `kind: "physical"` selects a connected phone. An unavailable requested target stays unselected, with a message and the device picker available. Opening never boots a device. Without targeting, iOS opens when both platforms have running devices; Android opens when it has the only running device. Later manual device selections replace the opening choice.

Choose **+ Add device** in a tab strip and select the screens to display. The menu groups devices into iOS and Android columns. Choosing a device closes the menu. Open **+ Add device** again to choose another. Selecting a stopped simulator or emulator starts it. Each screen has its own Home, App Switcher, Screenshot, and Select controls. Each new device opens as a tab in that group. Drag a tab to the left, right, top, or bottom edge of a view to split it. Drop it in the center to join that group or on the tab strip to reorder it. Drag a divider to resize the views. Drag the empty part of a tab strip to move the whole group. Each group streams its selected tab. Deselecting a device closes its screen and leaves the device running. The panel uses Apple’s device bezel and screen mask from the installed DeviceKit assets, with a simple frame as a fallback when assets are unavailable. Use the settings button at the bottom right for appearance, text size, location, and the device frame. iOS also offers contrast; Android offers rotation. The menu shows only settings supported by the bundled backend. Click the screen to type or drag. Closing the panel closes its stream.

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mobile-dev",
"version": "0.1.197",
"version": "0.1.198",
"private": true,
"workspaces": [
"packages/shared",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/browser-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export type BrowserPanelOptions = {
template?: URL;
/**
* Offers the page to every host, also those that render MCP Apps in the chat, for a
* server whose panel does not render inline (see createPanel's `inline`).
* server using browser placement.
*/
always?: boolean;
};
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import { panelPlacement } from "./panel-placement.ts";

// The shared server with Mobile Dev's panel and agent-device's commands, as Cursor and other
// MCP hosts run it. Hosts that render no MCP Apps panel can show it in a browser beside the chat.
const inline = panelPlacement("inline") === "inline";
await runStdioServer({ panel: createPanel({ inline }), features: [agentDeviceTools(readAgentDeviceCatalog()), browserPanel({ always: !inline })] });
const placement = panelPlacement("inline");
await runStdioServer({ panel: createPanel({ placement }), features: [agentDeviceTools(readAgentDeviceCatalog()), browserPanel({ always: placement === "browser" })] });
33 changes: 14 additions & 19 deletions packages/core/src/panel-tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { PLUGIN_VERSION } from "@mobile-dev/shared/version.ts";
import { SENTRY_ORIGIN } from "@mobile-dev/shared/telemetry.ts";
import { errorMessage, streamMessageSchema, udidSchema } from "@mobile-dev/shared/protocol.ts";
import type { Status } from "@mobile-dev/shared/protocol.ts";
import { PANEL_PAGE_META, panelTargetSchema } from "@mobile-dev/shared/panel-target.ts";
import { PANEL_PAGE_META, panelDisplayModes, panelTargetSchema } from "@mobile-dev/shared/panel-target.ts";
import type { PanelTarget } from "@mobile-dev/shared/panel-target.ts";
import type { PanelOpener } from "./server-feature.ts";
import { captureServerError } from "./telemetry.ts";
Expand Down Expand Up @@ -81,8 +81,7 @@ const INSTRUCTIONS = "Use mobile_open_simulator before the first device launch o

/** Mobile Dev's own device views, which a host adds to the server it runs (see createPanel). */
export type Panel = {
/** Whether the panel renders in the chat, where it can also open recordings in the workspace. */
readonly inline: boolean;
readonly placement: "inline" | "sidebar" | "browser";
instructions: string;
simulatorForeground: SimulatorForeground;
register(server: McpServer, shared: PanelShared): () => Promise<void>;
Expand All @@ -109,12 +108,8 @@ export type PanelOptions = {
simulatorInput?: SimulatorInput;
copyScreenshot?: typeof copyPNGToClipboard;
resourceSaving?: ResourceSaving;
/**
* Whether MCP Apps hosts render the panel in the chat from its opening tools. A host that
* shows it beside the chat instead, in a browser, passes false: the tools then name their
* page under PANEL_PAGE_META, which hosts ignore and the browser panel reads.
*/
inline?: boolean;
/** Native tool results may open inline or only in the sidebar. Browser placement uses a separate page. */
placement?: Panel["placement"];
};

/**
Expand All @@ -124,19 +119,19 @@ export type PanelOptions = {
* the workspace and asking for devices in a native form. Hosts that show devices
* themselves, such as Claude, leave it out.
*/
export function createPanel({ baguette = new Baguette(), simulatorInput, copyScreenshot = copyPNGToClipboard, resourceSaving = new ResourceSaving(), inline = true }: PanelOptions = {}): Panel {
export function createPanel({ baguette = new Baguette(), simulatorInput, copyScreenshot = copyPNGToClipboard, resourceSaving = new ResourceSaving(), placement = "inline" }: PanelOptions = {}): Panel {
return {
inline,
placement,
instructions: INSTRUCTIONS,
simulatorForeground: foregroundSimulatorPid,
register: (server, shared) => registerPanel(server, shared, {
baguette, copyScreenshot, resourceSaving, inline, simulatorInput: simulatorInput ?? new SimulatorInputService(udid => baguette.repairInput(udid)),
baguette, copyScreenshot, resourceSaving, placement, simulatorInput: simulatorInput ?? new SimulatorInputService(udid => baguette.repairInput(udid)),
}),
};
}

function registerPanel(server: McpServer, { android, cpu, fps, drivers, page, showRecording, opened, reopenNotice }: PanelShared,
{ baguette, simulatorInput, copyScreenshot, resourceSaving, inline }: Required<PanelOptions>) {
{ baguette, simulatorInput, copyScreenshot, resourceSaving, placement }: Required<PanelOptions>) {
const streams = new StreamSessions(baguette);
const closeIosMirror = registerIosMirrorTools(server, APP_URI);
const closeInspection = registerInspectionTools(server, baguette, android);
Expand All @@ -148,9 +143,10 @@ function registerPanel(server: McpServer, { android, cpu, fps, drivers, page, sh
const closeDeviceSettings = registerDeviceSettingsTools(server, baguette, android);
registerResourceSavingTools(server, baguette, android, resourceSaving);
registerPanelAppControlTools(server, drivers);
// Opening a recording renders the workspace in the chat; beside the chat, recordings stay cards.
if (inline) registerOpenRecordingTool(server, showRecording, WORKSPACE_URI);
// Native panels can open a saved recording in the workspace. Browser panels keep recordings in cards.
if (placement !== "browser") registerOpenRecordingTool(server, showRecording, WORKSPACE_URI);

const availableDisplayModes = panelDisplayModes(placement === "sidebar");
const readApp = async (uri: URL): Promise<ReadResourceResult> => {
const content = await page();
return { contents: [{
Expand All @@ -159,7 +155,7 @@ function registerPanel(server: McpServer, { android, cpu, fps, drivers, page, sh
: content,
_meta: {
ui: { permissions: { clipboardWrite: {} }, csp: { connectDomains: [SENTRY_ORIGIN], resourceDomains: [] } },
"openai/ui": { preferredDisplayMode: "fullscreen", availableDisplayModes: ["inline", "fullscreen"] },
"openai/ui": { preferredDisplayMode: "fullscreen", availableDisplayModes },
},
}] };
};
Expand Down Expand Up @@ -251,14 +247,13 @@ function registerPanel(server: McpServer, { android, cpu, fps, drivers, page, sh
return response;
});

// Inline, the host renders each opening tool's page in the chat; otherwise the tool only
// names it, and a host feature such as the browser panel shows it.
// Native hosts open the tool's UI resource. Browser placement gives the page URI only to the browser panel.
const openingTool = (name: string, config: { description: string; resourceUri: string; entrypoint: "global" | "thread"; defaults?: Partial<PanelTarget>; startBackend?: boolean }) => {
const definition = {
title: "Mobile Dev", description: config.description,
inputSchema: panelTargetSchema, outputSchema: { ...statusOutput, panelTarget: panelTargetSchema, browserPanel: browserPanelOutput }, annotations: write,
};
if (inline === false) {
if (placement === "browser") {
server.registerTool(name, { ...definition, _meta: { [PANEL_PAGE_META]: { resourceUri: config.resourceUri } } }, openPanel(name, config.defaults, config.startBackend));
return;
}
Expand Down
17 changes: 14 additions & 3 deletions packages/core/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,31 @@ export async function createPlugin(html: string | (() => Promise<UIResource>), o
registerTestingAgentTools(server, testingDevices, testingRecordings);

const resource = async () => typeof html === "string" ? { html } : await html();
const page = async () => configureUI((await resource()).html);
function configurePanelPage(content: string) {
const configured = configureUI(content);
if (panel?.placement === "sidebar") return configured.replace('data-view="panel"', 'data-sidebar-only data-view="panel"');
return configured;
}
const page = async () => {
const current = await resource();
return configurePanelPage(current.html);
};
server.registerResource("mobile-dev-live", new ResourceTemplate(`${LIVE_UI_URI}?after={revision}`, { list: undefined }), {
mimeType: "application/json",
description: "Read a changed local development UI through MCP. Unchanged reads omit the HTML.",
}, async uri => {
const { html: content, liveRevision: revision } = await resource();
return { contents: [{ uri: uri.href, mimeType: "application/json", text: JSON.stringify({
revision,
html: revision && revision !== uri.searchParams.get("after") ? configureUI(content) : undefined,
html: revision && revision !== uri.searchParams.get("after") ? configurePanelPage(content) : undefined,
}) }] };
});
const readCard = (view: string) => async (uri: URL) => {
// Cards from a server whose panel opens recordings in the workspace can open them there.
const content = (await page()).replace('data-view="panel"', `data-view="${view}"${panel?.inline ? " data-workspace" : ""}`);
const current = await resource();
const html = configureUI(current.html);
const workspace = panel && panel.placement !== "browser" ? " data-workspace" : "";
const content = html.replace('data-view="panel"', `data-view="${view}"${workspace}`);
return { contents: [{ uri: uri.href, mimeType: RESOURCE_MIME_TYPE, text: content, _meta: {
ui: { prefersBorder: true, permissions: { clipboardWrite: {} }, csp: { connectDomains: [SENTRY_ORIGIN], resourceDomains: [] } },
"openai/ui": { preferredDisplayMode: "inline", availableDisplayModes: ["inline", "fullscreen"] },
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/browser-panel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ test("a panel that never renders inline links the browser page for MCP Apps host
t.after(() => fake.close());
const [hostSide, serverSide] = InMemoryTransport.createLinkedPair();
const shared = new SharedTransport(serverSide);
const panel = createPanel({ baguette: new Baguette(fake.url), simulatorInput: fakeSimulatorInput(), inline: false });
const panel = createPanel({ baguette: new Baguette(fake.url), simulatorInput: fakeSimulatorInput(), placement: "browser" });
const plugin = await createTestPlugin("<html></html>", { panel, features: [browserPanel({ template: pathToFileURL(page), always: true })], connections: shared });
// The desktop app's Code tab renders MCP Apps.
const host = new Client({ name: "claude-code", version: "1" }, { capabilities: { extensions: { [EXTENSION_ID]: { mimeTypes: [RESOURCE_MIME_TYPE] } } } as ClientCapabilities });
Expand Down
Loading
Loading