MCPcopy
hub / github.com/callstack/agent-device / disconnectCommand

Function disconnectCommand

src/cli/commands/connection.ts:309–349  ·  view source on GitHub ↗
({ flags, client })

Source from the content-addressed store, hash-verified

307}
308
309export const disconnectCommand: ClientCommandHandler = async ({ flags, client }) => {
310 const { session, stateDir, state } = readRequestedConnectionState(flags);
311 if (!state) {
312 writeNoRemoteConnectionOutput(flags, session);
313 return true;
314 }
315 const connectedSession = state.session;
316
317 let providerData: CloudProviderSessionResult | undefined;
318 try {
319 providerData = (
320 await client.sessions.close({ session: connectedSession, shutdown: flags.shutdown })
321 ).provider;
322 } catch {
323 // Disconnect is idempotent; the session may already be closed.
324 }
325 await stopMetroCleanup(state.metro);
326 await stopReactDevtoolsCleanup({ stateDir, state });
327 let released = false;
328 if (state.leaseId) {
329 try {
330 const release = await releaseRemoteConnectionLease(client, state);
331 released = release.released;
332 providerData ??= release.provider;
333 } catch {
334 // Bridges may release on close or be unreachable; local state still needs cleanup.
335 }
336 }
337 removeRemoteConnectionState({ stateDir, session: connectedSession });
338 writeCommandOutput(
339 flags,
340 {
341 connected: false,
342 session: connectedSession,
343 released,
344 ...(providerData ? { provider: providerData } : {}),
345 },
346 () => renderDisconnectOutput(connectedSession, providerData),
347 );
348 return true;
349};
350
351export const connectionCommand: ClientCommandHandler = async ({ positionals, flags }) => {
352 if (positionals[0] !== 'status') {

Callers 1

Calls 9

stopMetroCleanupFunction · 0.90
stopReactDevtoolsCleanupFunction · 0.90
writeCommandOutputFunction · 0.90
renderDisconnectOutputFunction · 0.85
closeMethod · 0.45

Tested by

no test coverage detected