diff --git a/src/CodexElicitationHandler.ts b/src/CodexElicitationHandler.ts index abbbb70b..1f84f853 100644 --- a/src/CodexElicitationHandler.ts +++ b/src/CodexElicitationHandler.ts @@ -217,11 +217,29 @@ export class CodexElicitationHandler implements ElicitationHandler { context.isToolApproval, context.persistOptions, ); - if (correlatedCallId !== undefined && result.action === "accept") { - await this.connection.notify(acp.methods.client.session.update, { - sessionId: params.threadId, - update: { sessionUpdate: "tool_call_update", toolCallId: correlatedCallId, status: "in_progress" }, - }); + if (correlatedCallId !== undefined) { + if (result.action === "accept") { + await this.connection.notify(acp.methods.client.session.update, { + sessionId: params.threadId, + update: { sessionUpdate: "tool_call_update", toolCallId: correlatedCallId, status: "in_progress" }, + }); + } + } else { + try { + await this.connection.notify(acp.methods.client.session.update, { + sessionId: params.threadId, + update: { + sessionUpdate: "tool_call_update", + toolCallId: request.toolCall.toolCallId, + status: "completed", + title: request.toolCall.title, + content: request.toolCall.content, + rawOutput: { action: result.action }, + }, + }); + } catch (error) { + logger.error("Failed to finalize standalone MCP elicitation tool call", error); + } } return result; } catch (error) { diff --git a/src/__tests__/CodexACPAgent/data/elicitation-tool-approval-all-persist.json b/src/__tests__/CodexACPAgent/data/elicitation-tool-approval-all-persist.json index 93bf950e..30dffbb8 100644 --- a/src/__tests__/CodexACPAgent/data/elicitation-tool-approval-all-persist.json +++ b/src/__tests__/CodexACPAgent/data/elicitation-tool-approval-all-persist.json @@ -7,6 +7,7 @@ "toolCallId": "elicitation:test-session-id:tool-server:1", "kind": "execute", "status": "pending", + "title": "MCP tool call approval", "content": [ { "type": "content", @@ -18,6 +19,7 @@ ], "rawInput": { "serverName": "tool-server", + "description": "Allow tool call?", "schema": { "type": "object", "properties": {} @@ -53,4 +55,30 @@ ] } ] +} +{ + "method": "sessionUpdate", + "args": [ + { + "sessionId": "test-session-id", + "update": { + "sessionUpdate": "tool_call_update", + "toolCallId": "elicitation:test-session-id:tool-server:1", + "status": "completed", + "title": "MCP tool call approval", + "content": [ + { + "type": "content", + "content": { + "type": "text", + "text": "Allow tool call?" + } + } + ], + "rawOutput": { + "action": "accept" + } + } + } + ] } \ No newline at end of file diff --git a/src/__tests__/CodexACPAgent/data/elicitation-tool-approval-no-persist.json b/src/__tests__/CodexACPAgent/data/elicitation-tool-approval-no-persist.json index d55ed702..9cb4e04a 100644 --- a/src/__tests__/CodexACPAgent/data/elicitation-tool-approval-no-persist.json +++ b/src/__tests__/CodexACPAgent/data/elicitation-tool-approval-no-persist.json @@ -7,6 +7,7 @@ "toolCallId": "elicitation:test-session-id:tool-server:1", "kind": "execute", "status": "pending", + "title": "MCP tool call approval", "content": [ { "type": "content", @@ -18,6 +19,7 @@ ], "rawInput": { "serverName": "tool-server", + "description": "Allow tool call?", "schema": { "type": "object", "properties": {} @@ -41,4 +43,30 @@ ] } ] +} +{ + "method": "sessionUpdate", + "args": [ + { + "sessionId": "test-session-id", + "update": { + "sessionUpdate": "tool_call_update", + "toolCallId": "elicitation:test-session-id:tool-server:1", + "status": "completed", + "title": "MCP tool call approval", + "content": [ + { + "type": "content", + "content": { + "type": "text", + "text": "Allow tool call?" + } + } + ], + "rawOutput": { + "action": "accept" + } + } + } + ] } \ No newline at end of file diff --git a/src/__tests__/CodexACPAgent/data/elicitation-tool-approval-session-only.json b/src/__tests__/CodexACPAgent/data/elicitation-tool-approval-session-only.json index db5ce031..3f509e7f 100644 --- a/src/__tests__/CodexACPAgent/data/elicitation-tool-approval-session-only.json +++ b/src/__tests__/CodexACPAgent/data/elicitation-tool-approval-session-only.json @@ -7,6 +7,7 @@ "toolCallId": "elicitation:test-session-id:tool-server:1", "kind": "execute", "status": "pending", + "title": "MCP tool call approval", "content": [ { "type": "content", @@ -18,6 +19,7 @@ ], "rawInput": { "serverName": "tool-server", + "description": "Allow tool call?", "schema": { "type": "object", "properties": {} @@ -47,4 +49,30 @@ ] } ] +} +{ + "method": "sessionUpdate", + "args": [ + { + "sessionId": "test-session-id", + "update": { + "sessionUpdate": "tool_call_update", + "toolCallId": "elicitation:test-session-id:tool-server:1", + "status": "completed", + "title": "MCP tool call approval", + "content": [ + { + "type": "content", + "content": { + "type": "text", + "text": "Allow tool call?" + } + } + ], + "rawOutput": { + "action": "accept" + } + } + } + ] } \ No newline at end of file diff --git a/src/__tests__/CodexACPAgent/data/elicitation-url-accept.json b/src/__tests__/CodexACPAgent/data/elicitation-url-accept.json index c9c4de0a..195f44d9 100644 --- a/src/__tests__/CodexACPAgent/data/elicitation-url-accept.json +++ b/src/__tests__/CodexACPAgent/data/elicitation-url-accept.json @@ -7,6 +7,7 @@ "toolCallId": "elicitation-elicit-789", "kind": "fetch", "status": "pending", + "title": "MCP server requests to open a URL", "content": [ { "type": "content", @@ -18,6 +19,7 @@ ], "rawInput": { "serverName": "auth-server", + "description": "Please authorize access to your GitHub account", "url": "https://example.com/authorize?id=elicit-789" } }, @@ -43,4 +45,30 @@ ] } ] +} +{ + "method": "sessionUpdate", + "args": [ + { + "sessionId": "test-session-id", + "update": { + "sessionUpdate": "tool_call_update", + "toolCallId": "elicitation-elicit-789", + "status": "completed", + "title": "MCP server requests to open a URL", + "content": [ + { + "type": "content", + "content": { + "type": "text", + "text": "Please authorize access to your GitHub account" + } + } + ], + "rawOutput": { + "action": "accept" + } + } + } + ] } \ No newline at end of file diff --git a/src/__tests__/CodexACPAgent/elicitation-events.test.ts b/src/__tests__/CodexACPAgent/elicitation-events.test.ts index 7a9521db..3c899fa3 100644 --- a/src/__tests__/CodexACPAgent/elicitation-events.test.ts +++ b/src/__tests__/CodexACPAgent/elicitation-events.test.ts @@ -227,7 +227,12 @@ describe('Elicitation Events', () => { }; expect(await fixture.sendServerRequest('mcpServer/elicitation/request', params)) .toEqual({ action: 'cancel', content: null, _meta: null }); - expect(fixture.getAcpConnectionEvents([]).filter(event => event.method === 'sessionUpdate')).toEqual([]); + const sessionUpdates = fixture.getAcpConnectionEvents([]) + .filter(event => event.method === 'sessionUpdate') + .map(event => event.args[0].update); + expect(sessionUpdates).toEqual([ + expect.objectContaining({ sessionUpdate: 'tool_call_update', status: 'completed', rawOutput: { action: 'cancel' } }), + ]); completeTurn(); await promptPromise; }); @@ -453,7 +458,10 @@ describe('Elicitation Events', () => { }; expect(await fixture.sendServerRequest('mcpServer/elicitation/request', params)) .toEqual({ action: 'cancel', content: null, _meta: null }); - expect(fixture.getAcpConnectionEvents([]).filter(event => event.method === 'sessionUpdate')).toEqual([]); + const toolStatuses = fixture.getAcpConnectionEvents([]) + .filter(event => event.method === 'sessionUpdate') + .map(event => event.args[0].update.status); + expect(toolStatuses).not.toContain('in_progress'); completeTurn(); await promptPromise; }); @@ -526,7 +534,10 @@ describe('Elicitation Events', () => { }; expect(await fixture.sendServerRequest('mcpServer/elicitation/request', params)) .toEqual({ action: 'cancel', content: null, _meta: null }); - expect(fixture.getAcpConnectionEvents([]).filter(event => event.method === 'sessionUpdate')).toEqual([]); + const toolStatuses = fixture.getAcpConnectionEvents([]) + .filter(event => event.method === 'sessionUpdate') + .map(event => event.args[0].update.status); + expect(toolStatuses).not.toContain('in_progress'); completeTurn(); await promptPromise; }); diff --git a/src/permissions/mcp.ts b/src/permissions/mcp.ts index c0f5c3b4..f3d44056 100644 --- a/src/permissions/mcp.ts +++ b/src/permissions/mcp.ts @@ -118,8 +118,9 @@ export function buildMcpPermissionRequest( toolCallId: nextStandaloneToolCallId(), kind: context.isToolApproval ? "execute" : "other", status: "pending", + title: context.isToolApproval ? "MCP tool call approval" : "Question from MCP server", content: [messageContent], - rawInput: {serverName: params.serverName, schema: params.requestedSchema}, + rawInput: {serverName: params.serverName, description: params.message, schema: params.requestedSchema}, }, ...(context.isToolApproval ? {_meta: {is_mcp_tool_approval: true}} : {}), options, @@ -137,8 +138,9 @@ export function buildMcpPermissionRequest( toolCallId: `elicitation-${params.elicitationId}`, kind: "fetch", status: "pending", + title: "MCP server requests to open a URL", content: [messageContent], - rawInput: {serverName: params.serverName, url: params.url}, + rawInput: {serverName: params.serverName, description: params.message, url: params.url}, }, options, },