MCPcopy Create free account
hub / github.com/getsentry/XcodeBuildMCP / buildMcpLifecycleSnapshot

Function buildMcpLifecycleSnapshot

src/server/mcp-lifecycle.ts:274–316  ·  view source on GitHub ↗
(options: {
  phase: McpStartupPhase;
  shutdownReason: McpShutdownReason | null;
  startedAtMs: number;
  commandExecutor?: CommandExecutor;
})

Source from the content-addressed store, hash-verified

272}
273
274export async function buildMcpLifecycleSnapshot(options: {
275 phase: McpStartupPhase;
276 shutdownReason: McpShutdownReason | null;
277 startedAtMs: number;
278 commandExecutor?: CommandExecutor;
279}): Promise<McpLifecycleSnapshot> {
280 const memoryUsage = process.memoryUsage();
281 const activitySnapshot = getDaemonActivitySnapshot();
282 const peerSample = await sampleMcpPeerProcesses(
283 options.commandExecutor ?? getDefaultCommandExecutor(),
284 process.pid,
285 );
286 const simulatorLaunchOsLogSessions = await listActiveSimulatorLaunchOsLogSessions();
287
288 const snapshotWithoutAnomalies = {
289 pid: process.pid,
290 ppid: process.ppid,
291 orphaned: process.ppid === 1,
292 phase: options.phase,
293 shutdownReason: options.shutdownReason,
294 uptimeMs: Math.max(0, Date.now() - options.startedAtMs),
295 rssBytes: memoryUsage.rss,
296 heapUsedBytes: memoryUsage.heapUsed,
297 watcherRunning: isWatcherRunning(),
298 watchedPath: getWatchedPath(),
299 activeOperationCount: activitySnapshot.activeOperationCount,
300 activeOperationByCategory: activitySnapshot.byCategory,
301 debuggerSessionCount: getDefaultDebuggerManager().listSessions().length,
302 simulatorLaunchOsLogSessionCount: simulatorLaunchOsLogSessions.length,
303 ownedSimulatorLaunchOsLogSessionCount: simulatorLaunchOsLogSessions.filter(
304 (session) => session.ownedByCurrentProcess,
305 ).length,
306 videoCaptureSessionCount: listActiveVideoCaptureSessionIds().length,
307 swiftPackageProcessCount: activeProcesses.size,
308 matchingMcpProcessCount: peerSample.count,
309 matchingMcpPeerSummary: peerSample.peers,
310 };
311
312 return {
313 ...snapshotWithoutAnomalies,
314 anomalies: classifyMcpLifecycleAnomalies(snapshotWithoutAnomalies),
315 };
316}
317
318export function createMcpLifecycleCoordinator(
319 options: McpLifecycleCoordinatorOptions,

Callers 3

getSnapshotFunction · 0.85
shutdownFunction · 0.85

Calls 10

isWatcherRunningFunction · 0.90
getWatchedPathFunction · 0.90
sampleMcpPeerProcessesFunction · 0.85
listSessionsMethod · 0.80

Tested by

no test coverage detected