Fix codex mcp tool call mapping
This commit is contained in:
@@ -221,6 +221,73 @@ function normalizePatchFilesFromChanges(changes: unknown): PatchFileChange[] {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function extractMcpToolIdentifiers(
|
||||||
|
item: Record<string, unknown>
|
||||||
|
): { server?: string; tool?: string } {
|
||||||
|
const toolRecord =
|
||||||
|
item.tool && typeof item.tool === "object"
|
||||||
|
? (item.tool as Record<string, unknown>)
|
||||||
|
: undefined;
|
||||||
|
const serverRecord =
|
||||||
|
item.server && typeof item.server === "object"
|
||||||
|
? (item.server as Record<string, unknown>)
|
||||||
|
: undefined;
|
||||||
|
const server =
|
||||||
|
asString(item.server) ??
|
||||||
|
asString(serverRecord?.name) ??
|
||||||
|
asString(serverRecord?.id) ??
|
||||||
|
asString(item.server_name) ??
|
||||||
|
asString(item.serverId) ??
|
||||||
|
asString(item.server_id) ??
|
||||||
|
asString(item.mcp_server);
|
||||||
|
const tool =
|
||||||
|
asString(item.tool) ??
|
||||||
|
asString(toolRecord?.name) ??
|
||||||
|
asString(toolRecord?.tool) ??
|
||||||
|
asString(item.tool_name) ??
|
||||||
|
asString(item.toolId) ??
|
||||||
|
asString(item.tool_id) ??
|
||||||
|
asString(item.name);
|
||||||
|
if (!server && tool && tool.includes(".")) {
|
||||||
|
const [serverName, ...toolParts] = tool.split(".");
|
||||||
|
const toolName = toolParts.join(".");
|
||||||
|
return {
|
||||||
|
server: serverName || undefined,
|
||||||
|
tool: toolName || tool,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return { server: server ?? undefined, tool: tool ?? undefined };
|
||||||
|
}
|
||||||
|
|
||||||
|
function extractMcpToolPayload(
|
||||||
|
item: Record<string, unknown>
|
||||||
|
): { input?: unknown; output?: unknown; status?: string } {
|
||||||
|
const input =
|
||||||
|
item.input ??
|
||||||
|
item.arguments ??
|
||||||
|
item.args ??
|
||||||
|
item.params ??
|
||||||
|
item.request ??
|
||||||
|
(item.tool && typeof item.tool === "object"
|
||||||
|
? (item.tool as Record<string, unknown>).input
|
||||||
|
: undefined);
|
||||||
|
const output =
|
||||||
|
item.output ??
|
||||||
|
item.result ??
|
||||||
|
item.response ??
|
||||||
|
item.return ??
|
||||||
|
item.returns ??
|
||||||
|
item.result_content ??
|
||||||
|
item.content ??
|
||||||
|
item.structuredContent ??
|
||||||
|
item.structured_content;
|
||||||
|
const status =
|
||||||
|
asString(item.status) ??
|
||||||
|
asString(item.state) ??
|
||||||
|
asString(item.outcome);
|
||||||
|
return { input, output, status };
|
||||||
|
}
|
||||||
|
|
||||||
function normalizePatchFilesFromFiles(files: unknown): PatchFileChange[] {
|
function normalizePatchFilesFromFiles(files: unknown): PatchFileChange[] {
|
||||||
if (!Array.isArray(files)) {
|
if (!Array.isArray(files)) {
|
||||||
return [];
|
return [];
|
||||||
@@ -1651,17 +1718,20 @@ class CodexMcpAgentSession implements AgentSession {
|
|||||||
output: content ?? output ?? outputValue,
|
output: content ?? output ?? outputValue,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
case "mcp_tool_call":
|
case "mcp_tool_call": {
|
||||||
|
const { server, tool } = extractMcpToolIdentifiers(item);
|
||||||
|
const { input, output, status } = extractMcpToolPayload(item);
|
||||||
return createToolCallTimelineItem({
|
return createToolCallTimelineItem({
|
||||||
server: item.server as string,
|
server: server ?? "mcp",
|
||||||
tool: item.tool as string,
|
tool: tool ?? "tool",
|
||||||
status: item.status as string | undefined,
|
status: status ?? (item.status as string | undefined),
|
||||||
callId,
|
callId,
|
||||||
displayName: `${item.server}.${item.tool}`,
|
displayName: `${server ?? "mcp"}.${tool ?? "tool"}`,
|
||||||
kind: "tool",
|
kind: "tool",
|
||||||
input: item.input,
|
input,
|
||||||
output: item.output,
|
output,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
case "web_search":
|
case "web_search":
|
||||||
return createToolCallTimelineItem({
|
return createToolCallTimelineItem({
|
||||||
server: "web_search",
|
server: "web_search",
|
||||||
|
|||||||
@@ -414,9 +414,10 @@ Build a new Codex MCP provider side‑by‑side with the existing Codex SDK prov
|
|||||||
- Ensure the E2E coverage test can find `tool: "read_file"` with content.
|
- Ensure the E2E coverage test can find `tool: "read_file"` with content.
|
||||||
- **Done (2025-12-24 23:52)**: WHAT: normalized top-level `read_file`/`file_read` events into thread items and mapped read file tool calls with path/content input/output in `packages/server/src/server/agent/providers/codex-mcp-agent.ts:1139` and `packages/server/src/server/agent/providers/codex-mcp-agent.ts:1618`. RESULT: read_file tool calls now emit timeline items with tool name, file path input, and content output for Codex MCP. EVIDENCE: Not run (not requested).
|
- **Done (2025-12-24 23:52)**: WHAT: normalized top-level `read_file`/`file_read` events into thread items and mapped read file tool calls with path/content input/output in `packages/server/src/server/agent/providers/codex-mcp-agent.ts:1139` and `packages/server/src/server/agent/providers/codex-mcp-agent.ts:1618`. RESULT: read_file tool calls now emit timeline items with tool name, file path input, and content output for Codex MCP. EVIDENCE: Not run (not requested).
|
||||||
|
|
||||||
- [ ] **Fix**: Codex MCP should emit external MCP tool calls (mcp_tool_call) with input/output in timeline items.
|
- [x] **Fix**: Codex MCP should emit external MCP tool calls (mcp_tool_call) with input/output in timeline items.
|
||||||
|
|
||||||
- Ensure MCP server tool calls surface `server`, `tool`, `input`, and `output` fields.
|
- Ensure MCP server tool calls surface `server`, `tool`, `input`, and `output` fields.
|
||||||
|
- **Done (2025-12-25 00:00)**: WHAT: added MCP tool identifier/payload extraction helpers and used them for `mcp_tool_call` timeline mapping in `packages/server/src/server/agent/providers/codex-mcp-agent.ts:224` and `packages/server/src/server/agent/providers/codex-mcp-agent.ts:1721`. RESULT: MCP tool call timeline items now normalize server/tool/input/output fields from multiple event shapes. EVIDENCE: Not run (not requested).
|
||||||
|
|
||||||
- [ ] **Fix**: Codex MCP web_search timeline items should include query input and results output.
|
- [ ] **Fix**: Codex MCP web_search timeline items should include query input and results output.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user