Official
codex
Codex agent provider: runs the Codex CLI's app-server for each account.
The app opens the listing; nothing installs until an agent in your Plugins workspace has read the files and you enable the plugin. In a terminal: dvg install divergence/codex@0.2.4
Permissions in 0.2.4
Files
mcp.ts2.4 KB
import * as Effect from "effect/Effect";
import type { McpCallToolParams, McpReadResourceParams, ToolContent } from "divergence/protocol";
import { ProviderError } from "../sdk/errors.ts";
import type { CodexAgent } from "./agent.ts";
import type { Item, McpServers } from "./wire.ts";
/// Codex captures the invoked descriptor's UI resource in the item itself.
export function appContent(item: Item, enabled: boolean): ToolContent[] {
const resourceUri = item.mcpAppUi?.resourceUri ?? item.mcpAppResourceUri ?? item.appContext?.resourceUri;
if (!enabled || !resourceUri?.startsWith("ui://")) return [];
return [
{
type: "mcp_app",
server: item.server ?? "",
tool: item.tool ?? "",
resourceUri,
...(item.result != null ? { result: item.result } : {}),
},
];
}
export const readResource = Effect.fn("Codex.readResource")(function* (
agent: CodexAgent,
params: McpReadResourceParams,
) {
const connection = yield* agent.loadedConnection(params.sessionId);
return yield* agent.request(connection, "mcpServer/resource/read", {
threadId: params.sessionId,
server: params.server,
uri: params.uri,
...(params.toolCallId ? { originCallId: params.toolCallId } : {}),
});
});
export const callTool = Effect.fn("Codex.callMcpTool")(function* (agent: CodexAgent, params: McpCallToolParams) {
const connection = yield* agent.loadedConnection(params.sessionId);
let cursor: string | null = null;
do {
const page: McpServers = yield* agent.request(connection, "mcpServerStatus/list", {
threadId: params.sessionId,
serverName: params.server,
cursor,
});
const server = page.data.find((server) => server.name === params.server);
if (server?.toolsError) return yield* Effect.fail(new ProviderError({ message: server.toolsError }));
const tool = Object.values(server?.tools ?? {}).find((tool) => tool.name === params.name);
const visibility = tool?._meta?.ui?.visibility;
if (visibility && !visibility.includes("app"))
return yield* Effect.fail(
new ProviderError({ message: `MCP tool ${params.server}.${params.name} does not allow calls from apps` }),
);
cursor = page.nextCursor ?? null;
} while (cursor);
return yield* agent.request(
connection,
"mcpServer/tool/call",
{
threadId: params.sessionId,
server: params.server,
tool: params.name,
arguments: params.arguments,
},
{ timeout: null },
);
});
No comments yet.