[App server] add mcp tool call item started/completed events (#6642)
this PR does two things:
1. refactor `apply_bespoke_event_handling` into a separate file as it's
getting kind of long;
2. add mcp tool call `item/started` and `item/completed` events. To roll
out app server events asap we didn't properly migrate mcp core events to
use TurnItem for mcp tool calls - this will be a follow-up PR.
real events generated in log:
```
{
"method": "codex/event/mcp_tool_call_end",
"params": {
"conversationId": "019a8021-26af-7c20-83db-21ca81e44d68",
"id": "0",
"msg": {
"call_id": "call_7EjRQkD9HnfyMWf7tGrT9FKA",
"duration": {
"nanos": 92708,
"secs": 0
},
"invocation": {
"arguments": {
"server": ""
},
"server": "codex",
"tool": "list_mcp_resources"
},
"result": {
"Ok": {
"content": [
{
"text": "{\"resources\":[]}",
"type": "text"
}
],
"isError": false
}
},
"type": "mcp_tool_call_end"
}
}
}
{
"method": "item/completed",
"params": {
"item": {
"arguments": {
"server": ""
},
"error": null,
"id": "call_7EjRQkD9HnfyMWf7tGrT9FKA",
"result": {
"content": [
{
"text": "{\"resources\":[]}",
"type": "text"
}
],
"structuredContent": null
},
"server": "codex",
"status": "completed",
"tool": "list_mcp_resources",
"type": "mcpToolCall"
}
}
}
```