Skip to content
Draft
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
28 changes: 23 additions & 5 deletions src/CodexElicitationHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"toolCallId": "elicitation:test-session-id:tool-server:1",
"kind": "execute",
"status": "pending",
"title": "MCP tool call approval",
"content": [
{
"type": "content",
Expand All @@ -18,6 +19,7 @@
],
"rawInput": {
"serverName": "tool-server",
"description": "Allow tool call?",
"schema": {
"type": "object",
"properties": {}
Expand Down Expand Up @@ -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"
}
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"toolCallId": "elicitation:test-session-id:tool-server:1",
"kind": "execute",
"status": "pending",
"title": "MCP tool call approval",
"content": [
{
"type": "content",
Expand All @@ -18,6 +19,7 @@
],
"rawInput": {
"serverName": "tool-server",
"description": "Allow tool call?",
"schema": {
"type": "object",
"properties": {}
Expand All @@ -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"
}
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"toolCallId": "elicitation:test-session-id:tool-server:1",
"kind": "execute",
"status": "pending",
"title": "MCP tool call approval",
"content": [
{
"type": "content",
Expand All @@ -18,6 +19,7 @@
],
"rawInput": {
"serverName": "tool-server",
"description": "Allow tool call?",
"schema": {
"type": "object",
"properties": {}
Expand Down Expand Up @@ -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"
}
}
}
]
}
28 changes: 28 additions & 0 deletions src/__tests__/CodexACPAgent/data/elicitation-url-accept.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"toolCallId": "elicitation-elicit-789",
"kind": "fetch",
"status": "pending",
"title": "MCP server requests to open a URL",
"content": [
{
"type": "content",
Expand All @@ -18,6 +19,7 @@
],
"rawInput": {
"serverName": "auth-server",
"description": "Please authorize access to your GitHub account",
"url": "https://example.com/authorize?id=elicit-789"
}
},
Expand All @@ -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"
}
}
}
]
}
17 changes: 14 additions & 3 deletions src/__tests__/CodexACPAgent/elicitation-events.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down Expand Up @@ -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;
});
Expand Down Expand Up @@ -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;
});
Expand Down
6 changes: 4 additions & 2 deletions src/permissions/mcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
},
Expand Down
Loading