Skip to content
Open
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
191 changes: 191 additions & 0 deletions docs/mcp-apps.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
# MCP Apps

This adapter lets an ACP client host [MCP Apps](https://github.com/modelcontextprotocol/ext-apps) for the MCP servers that the agent connects to. The code is in `src/McpApps.ts`.

## Why

[MCP Apps](https://github.com/modelcontextprotocol/ext-apps) (SEP-1865) lets an MCP tool declare a
`ui://` resource in `_meta.ui.resourceUri`. A host shows that resource (an HTML page) in a
sandboxed frame next to the tool's result, and the page can call the server's tools.

In ACP the agent, not the client, connects to the MCP servers. A client that wants to show an
MCP App has three gaps:

1. It does not know that a tool call came from an app tool, or which resource goes with it.
2. It cannot read the `ui://` resource, because it has no connection to the server.
3. It cannot run the tool calls that the page makes.

This extension closes those gaps with one capability, one `_meta` key on tool calls, and three
methods. It uses only `_meta` and `_`-prefixed methods, so agents and clients that do not know it
are unaffected.

## 1. Capability

The client declares support in `initialize`:

| Protocol | Where |
| --- | --- |
| ACP v1 | `clientCapabilities._meta.mcpApps` |
| ACP v2 | `capabilities._meta.mcpApps` |

```json
{ "mcpApps": { "version": 1 } }
```

The agent answers with the methods it serves:

| Protocol | Where |
| --- | --- |
| ACP v1 | `agentCapabilities._meta.mcpApps` |
| ACP v2 | `capabilities._meta.mcpApps` |

```json
{
"mcpApps": {
"version": 1,
"resourcesRead": "_session/mcp/resources/read",
"toolsCall": "_session/mcp/tools/call",
"toolsList": "_session/mcp/tools/list"
}
}
```

An agent sends `_meta.mcpApp` (section 2) only to a client that declared a `version` of 1 or more.
The methods work for any client.

## 2. App tool calls: `_meta.mcpApp`

When a tool that declared a `ui://` resource finishes, the agent adds `_meta.mcpApp` to a report
of that tool call. It comes in a `tool_call_update` after the call's own result. When a session
is loaded or replayed, it can come in the `tool_call` itself.

```json
{
"sessionUpdate": "tool_call_update",
"toolCallId": "call_1",
"_meta": {
"mcpApp": {
"version": 1,
"server": "basic",
"tool": "get-time",
"resourceUri": "ui://get-time/mcp-app.html",
"toolResult": {
"content": [{ "type": "text", "text": "2026-11-26T16:42:32.567Z" }],
"structuredContent": { "time": "2026-11-26T16:42:32.567Z" }
}
}
}
}
```

| Field | Meaning |
| --- | --- |
| `server` | The MCP server's name, as the client passes it to the two methods. |
| `tool` | The tool's own name on the server, without any agent prefix such as `mcp__<server>__`. |
| `resourceUri` | The `ui://` resource from the tool's `_meta.ui.resourceUri`. The deprecated flat `_meta["ui/resourceUri"]` is also read. |
| `toolResult` | The server's own `CallToolResult`, including `structuredContent` and `_meta`. A failed call has `isError: true`. It is left out when its JSON is longer than 1,000,000 characters. |

The client sends `toolResult` to the page as `ui/notifications/tool-result`, and the tool call's
`rawInput.arguments` as `ui/notifications/tool-input` where it has them.

## 3. `_session/mcp/resources/read`

Reads the `ui://` resource through the agent's connection to the server. It sends no session update.

Request:

```json
{ "sessionId": "…", "server": "basic", "uri": "ui://get-time/mcp-app.html", "toolCallId": "call_1" }
```

- `uri` must start with `ui://`. Any other scheme fails with Invalid params (-32602), so the method
cannot be used to read the server's other resources.
- `toolCallId` is optional: the app tool call that the resource is read for. An agent may use it to
pick the right app (Codex passes it on as `originCallId`). Other agents ignore it.

Response: the MCP `ReadResourceResult` contents.

```json
{ "contents": [{ "uri": "ui://get-time/mcp-app.html", "mimeType": "text/html;profile=mcp-app", "text": "<!DOCTYPE html>…" }] }
```

The client reads the page's CSP and permissions from `contents[]._meta.ui`, as the MCP Apps spec says.

## 4. `_session/mcp/tools/call`

Runs a tool for the page on the session's live MCP connection. It runs between turns as well as
during one. It starts no model turn, it sends no session update, and the result goes only to the
client: the model does not see it.

Request:

```json
{ "sessionId": "…", "server": "basic", "name": "get-time", "arguments": {}, "checkPermissions": true }
```

| Field | Meaning |
| --- | --- |
| `name` | The tool's own name on the server. |
| `arguments` | An object. Optional, `{}` when left out. |
| `checkPermissions` | Optional. When `true`, the agent decides the call as it decides the model's own call to that tool, and asks the user through `session/request_permission` where it would ask. An agent that cannot do that must refuse the request with Invalid request (-32600) rather than run the tool unchecked; the client can then ask the user itself and call again without the flag. |

Response: the server's `CallToolResult`. A tool that fails comes back as a result with
`isError: true` where the agent can tell it apart from a transport error.

## 4a. `_session/mcp/tools/list`

The tools of one server of the session, with what a host needs to decide on a page's call: the
MCP annotations and the tool's MCP Apps `_meta.ui` (its `visibility`). It sends no session update.

Request: `{ "sessionId": "…", "server": "basic" }`

Response:

```json
{
"tools": [
{ "name": "list-tasks", "annotations": { "readOnlyHint": true }, "ui": { "visibility": ["app"] } },
{ "name": "complete-task", "annotations": { "readOnlyHint": false }, "ui": { "visibility": ["app"] } }
]
}
```

A host can run a read-only tool for the page at once, and ask the user first about any other, as
MCP says of tools without `readOnlyHint: true`. A server that the session has not connected fails
with Invalid params.

## 5. Errors

| Case | Error |
| --- | --- |
| Missing or empty `sessionId`, `server`, `uri` or `name`; `arguments` not an object; `checkPermissions` not a boolean | -32602 Invalid params |
| `uri` is not `ui://` | -32602 Invalid params |
| Unknown session | session not found / -32602 |
| The session's agent process has stopped | -32600 Invalid request: resume the session and retry |
| The agent cannot check permissions, or its version cannot call tools for an app | -32600 Invalid request, with a message saying what to update |
| Unknown tool, server error | -32603 Internal error, with the server's message |

## 6. What the client still owns

The extension carries data; the client is the MCP Apps host. It should:

- render the resource in a sandboxed frame with the CSP the resource declares;
- forward the page's `tools/call` only to the server the page came from (`mcpApp.server`);
- decide which of the page's calls need the user's consent (`_session/mcp/tools/list` gives the annotations), or pass `checkPermissions: true`;
- forward only calls to tools the page may use: a tool whose `ui.visibility` leaves out `"app"` is the model's only;
- treat everything the page sends as untrusted input.

## 7. Codex

Codex already records `mcpAppUi` on MCP tool call items and serves
`mcpServer/resource/read` and `mcpServer/tool/call`; the adapter maps them, and lists tools with
`mcpServerStatus/list`. Codex runs a client's
`mcpServer/tool/call` without an approval, so the adapter refuses `checkPermissions: true`.

## 8. Not in version 1

- Streaming tool input to the page (`ui/notifications/tool-input-partial`).
- The page adding to the model's context (`ui/update-model-context`) or sending a message.
- Hiding app-only tools (`_meta.ui.visibility: ["app"]`) from the model: that is up to the agent.
- `resources/list` and templates for apps.

14 changes: 14 additions & 0 deletions src/AcpAgentRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ import {
} from "./AcpExtensions";
import {ASYNC_TASK_STOP_METHOD} from "./async-tasks/AsyncTaskExtension";
import {SESSION_REWIND_METHOD} from "./SessionRewind";
import {
MCP_RESOURCES_READ_METHOD,
MCP_TOOLS_CALL_METHOD,
MCP_TOOLS_LIST_METHOD,
mcpResourcesReadParamsParser,
mcpToolsCallParamsParser,
mcpToolsListParamsParser,
} from "./McpApps";
import {CODEX_HOOKS_LIST_METHOD, CODEX_HOOKS_TRUST_METHOD} from "./CodexHookTrust";
import {
SESSION_ARCHIVE_METHOD,
Expand Down Expand Up @@ -239,6 +247,9 @@ function createRouter(
.onRequest(CODEX_HOOKS_LIST_METHOD, hooksListParamsParser, (ctx) => getAgent().listHooks(ctx.params.cwd))
.onRequest(CODEX_HOOKS_TRUST_METHOD, hooksTrustParamsParser, (ctx) => getAgent().trustHooks(ctx.params.cwd, ctx.params.hooks))
.onRequest(GOAL_CONTROL_METHOD, goalControlParamsParser, (ctx) => getAgent(ctx.params).extMethod(GOAL_CONTROL_METHOD, ctx.params))
.onRequest(MCP_RESOURCES_READ_METHOD, mcpResourcesReadParamsParser, (ctx) => getAgent().readMcpResource(ctx.params))
.onRequest(MCP_TOOLS_CALL_METHOD, mcpToolsCallParamsParser, (ctx) => getAgent(ctx.params).callMcpTool(ctx.params))
.onRequest(MCP_TOOLS_LIST_METHOD, mcpToolsListParamsParser, (ctx) => getAgent().listMcpAppTools(ctx.params))
.onRequest(SESSION_RENAME_METHOD, sessionRenameParamsParser, (ctx) => getAgent(ctx.params).sessionIndex.rename(ctx.params))
.onRequest(SESSION_BATCH_GET_METHOD, sessionBatchGetParamsParser, (ctx) => getAgent().sessionIndex.batchGet(ctx.params))
.onRequest(SESSION_ARCHIVE_METHOD, sessionArchiveParamsParser, (ctx) => getAgent(ctx.params).sessionIndex.setArchived(ctx.params, true))
Expand Down Expand Up @@ -292,6 +303,9 @@ function createRouter(
.onRequest(acpV2.methods.agent.providers.disable, (ctx) => getAgent().disableProvider(ctx.params))
.onRequest(SESSION_STEERING_METHOD, sessionSteerParamsParser, (ctx) => getAgent(ctx.params).extMethod(SESSION_STEERING_METHOD, ctx.params))
.onRequest(GOAL_CONTROL_METHOD, goalControlParamsParser, (ctx) => getAgent(ctx.params).extMethod(GOAL_CONTROL_METHOD, ctx.params))
.onRequest(MCP_RESOURCES_READ_METHOD, mcpResourcesReadParamsParser, (ctx) => getAgent().readMcpResource(ctx.params))
.onRequest(MCP_TOOLS_CALL_METHOD, mcpToolsCallParamsParser, (ctx) => getAgent(ctx.params).callMcpTool(ctx.params))
.onRequest(MCP_TOOLS_LIST_METHOD, mcpToolsListParamsParser, (ctx) => getAgent().listMcpAppTools(ctx.params))
.onRequest(ASYNC_TASK_STOP_METHOD, asyncTaskStopParamsParser, (ctx) => getAgent(ctx.params).extMethod(ASYNC_TASK_STOP_METHOD, ctx.params))
.onRequest(SESSION_RENAME_METHOD, sessionRenameParamsParser, (ctx) => getAgent(ctx.params).sessionIndex.rename(ctx.params))
.onRequest(SESSION_BATCH_GET_METHOD, sessionBatchGetParamsParser, (ctx) => getAgent().sessionIndex.batchGet(ctx.params))
Expand Down
70 changes: 70 additions & 0 deletions src/CodexAcpServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,20 @@ import {
type SessionSteeringResponse,
type SessionSteerRequest,
} from "./AcpExtensions";
import type {JsonValue} from "./app-server/serde_json/JsonValue";
import {
MCP_APPS_KEY,
mcpAppsCapability,
refuseCheckedCall,
toAppTools,
toCallToolResult,
type McpAppTool,
type McpToolsListRequest,
type McpCallToolResult,
type McpResourcesReadRequest,
type McpResourcesReadResponse,
type McpToolsCallRequest,
} from "./McpApps";
import {AcpToolCallRenderer} from "./tool-calls/AcpToolCallRenderer";
import {ClientCapabilities} from "./tool-calls/ClientCapabilities";
import {CommandReporter} from "./tool-calls/reporters/CommandReporter";
Expand Down Expand Up @@ -923,6 +937,8 @@ export class CodexAcpServer {
// Presence means "this agent pushes `_auth/status_update`". It
// never carries a payload, and the client never asks for one.
[AUTH_STATUS_META_KEY]: authStatusCapability(),
// `_session/mcp/resources/read` and `_session/mcp/tools/call`, see `docs/mcp-apps.md`.
[MCP_APPS_KEY]: mcpAppsCapability(),
},
},
authMethods: getCodexAuthMethods(_params.clientCapabilities),
Expand Down Expand Up @@ -982,6 +998,10 @@ export class CodexAcpServer {
title: {},
systemPrompt: {},
},
_meta: {
// `_session/mcp/resources/read` and `_session/mcp/tools/call`, see `docs/mcp-apps.md`.
[MCP_APPS_KEY]: mcpAppsCapability(),
},
},
authMethods: getCodexAuthMethodsV2(clientCapabilities),
_meta: this.initializeExtensionsMeta(2),
Expand Down Expand Up @@ -1050,6 +1070,56 @@ export class CodexAcpServer {
return {trusted: await this.runWithProcessCheck(() => trustCodexHooks(this.codexAcpClient.appServerClient, cwd, hooks))};
}

/** `_session/mcp/resources/read`: Codex reads the `ui://` resource from the server of the session's thread. */
async readMcpResource(params: McpResourcesReadRequest): Promise<McpResourcesReadResponse> {
const sessionState = await this.mcpAppsSession(params.sessionId);
const response = await this.runWithProcessCheck(() => this.codexAcpClient.appServerClient.mcpResourceRead({
threadId: sessionState.sessionId,
server: params.server,
uri: params.uri,
// Lets Codex pick the resource of the app that made the call.
...(params.toolCallId === undefined ? {} : {originCallId: params.toolCallId}),
}));
return {contents: response.contents};
}

/**
* `_session/mcp/tools/call`: the tool runs on the session's thread, outside a turn, and its
* result goes to the client only. Codex runs it without an approval, so `checkPermissions` is refused.
*/
async callMcpTool(params: McpToolsCallRequest): Promise<McpCallToolResult> {
refuseCheckedCall(params);
const sessionState = await this.mcpAppsSession(params.sessionId);
const response = await this.runWithProcessCheck(() => this.codexAcpClient.appServerClient.mcpServerToolCall({
threadId: sessionState.sessionId,
server: params.server,
tool: params.name,
arguments: (params.arguments ?? {}) as JsonValue,
}));
return toCallToolResult(response);
}

/** `_session/mcp/tools/list`: the tools of one server of the session's thread, with their annotations. */
async listMcpAppTools(params: McpToolsListRequest): Promise<{tools: McpAppTool[]}> {
const sessionState = await this.mcpAppsSession(params.sessionId);
const response = await this.runWithProcessCheck(() => this.codexAcpClient.appServerClient.listMcpServerStatus({
threadId: sessionState.sessionId,
serverName: params.server,
}));
const server = response.data.find(status => status.name === params.server);
if (!server) throw RequestError.invalidParams(undefined, `Unknown MCP server: ${params.server}`);
return {tools: toAppTools(server.tools)};
}

private async mcpAppsSession(sessionId: string): Promise<SessionState> {
const sessionState = this.sessions.get(sessionId);
if (!sessionState) throw RequestError.invalidParams(undefined, `Unknown session: ${sessionId}`);
if (this.providerUpdate !== null) await this.waitForProviderUpdate();
const sessionReady = this.ensureSessionReady(sessionState);
if (sessionReady) await sessionReady;
return sessionState;
}

async extMethod(method: string, params: Record<string, unknown>): Promise<Record<string, unknown>> {
const methodRequest = { method: method, params: params };
if (!isExtMethodRequest(methodRequest)) {
Expand Down
14 changes: 14 additions & 0 deletions src/CodexAppServerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ import type {
HooksListResponse,
ListMcpServerStatusParams,
ListMcpServerStatusResponse,
McpResourceReadParams,
McpResourceReadResponse,
McpServerToolCallParams,
McpServerToolCallResponse,
LoginAccountParams,
LoginAccountResponse,
LogoutAccountResponse,
Expand Down Expand Up @@ -886,6 +890,16 @@ export class CodexAppServerClient {
return await this.sendRequest({ method: "mcpServerStatus/list", params });
}

/** Reads a resource of an MCP server of a thread, such as the `ui://` resource of an MCP App. */
async mcpResourceRead(params: McpResourceReadParams): Promise<McpResourceReadResponse> {
return await this.sendRequest({ method: "mcpServer/resource/read", params });
}

/** Calls a tool of an MCP server of a thread, outside a turn: the model does not see the result. */
async mcpServerToolCall(params: McpServerToolCallParams): Promise<McpServerToolCallResponse> {
return await this.sendRequest({ method: "mcpServer/tool/call", params });
}

/** Whether this binary implements a feature, regardless of its default enablement. */
async hasExperimentalFeature(name: string): Promise<boolean> {
let cursor: string | null = null;
Expand Down
Loading