MCPcopy Index your code
hub / github.com/github/copilot-sdk / main

Function main

python/samples/manual_tool_resume.py:55–119  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

53
54
55async def main():
56 # 1. Create a session with a declaration-only tool, then stop after the permission prompt.
57 client1 = CopilotClient()
58 await client1.start()
59 session1 = await client1.create_session(tools=[tool])
60
61 # Subscribe before sending so the permission event cannot be missed.
62 permission_requested = watch_event(session1, PermissionRequestedData)
63 await session1.send(
64 "Use the manual_resume_status tool with id 'alpha', then tell me the status."
65 )
66
67 permission_event = await wait_for_event(permission_requested)
68 await client1.force_stop()
69 await pause()
70
71 # 2. Resume pending work and grant permission to invoke the tool.
72 client2 = CopilotClient()
73 await client2.start()
74 session2 = await client2.resume_session(
75 session1.session_id,
76 tools=[tool],
77 continue_pending_work=True,
78 )
79
80 # Subscribe before approving so the external tool request cannot be missed.
81 tool_requested = watch_event(
82 session2,
83 ExternalToolRequestedData,
84 lambda data: data.tool_name == "manual_resume_status",
85 )
86
87 await session2.rpc.permissions.handle_pending_permission_request(
88 PermissionDecisionRequest.from_dict(
89 {
90 "requestId": permission_event.data.request_id,
91 "result": {"kind": "approve-once"},
92 }
93 )
94 )
95
96 tool_event = await wait_for_event(tool_requested)
97 await client2.force_stop()
98 await pause()
99
100 # 3. Resume again and manually provide the pending tool result.
101 client3 = CopilotClient()
102 await client3.start()
103 session3 = await client3.resume_session(
104 session1.session_id,
105 tools=[tool],
106 continue_pending_work=True,
107 )
108
109 assistant_message = watch_event(session3, AssistantMessageData)
110 await session3.rpc.tools.handle_pending_tool_call(
111 HandlePendingToolCallRequest(
112 request_id=tool_event.data.request_id,

Callers 1

Calls 13

startMethod · 0.95
create_sessionMethod · 0.95
force_stopMethod · 0.95
resume_sessionMethod · 0.95
CopilotClientClass · 0.90
watch_eventFunction · 0.85
wait_for_eventFunction · 0.70
pauseFunction · 0.70
sendMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…