stop_sim_log_cap
Stop an active simulator log capture session and retrieve the collected logs for analysis.
Instructions
Stops an active simulator log capture session and returns the captured logs.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| logSessionId | Yes | The session ID returned by start_sim_log_cap. |
Implementation Reference
- src/tools/log.ts:83-104 (handler)Handler function for the 'stop_sim_log_cap' tool. Validates input, calls stopLogCapture utility, and formats the response with captured logs or error.
async function handler(params: { logSessionId: string }): Promise<ToolResponse> { const validationResult = validateRequiredParam('logSessionId', params.logSessionId); if (!validationResult.isValid) { return validationResult.errorResponse!; } const { logContent, error } = await stopLogCapture(params.logSessionId); if (error) { return { content: [ createTextContent(`Error stopping log capture session ${params.logSessionId}: ${error}`), ], isError: true, }; } return { content: [ createTextContent( `Log capture session ${params.logSessionId} stopped successfully. Log content follows:\n\n${logContent}`, ), ], }; } - src/tools/log.ts:79-81 (schema)Input schema for the 'stop_sim_log_cap' tool using Zod, requiring logSessionId.
const schema = { logSessionId: z.string().describe('The session ID returned by start_sim_log_cap.'), }; - src/tools/log.ts:106-112 (registration)Registration of the 'stop_sim_log_cap' tool using registerTool on the MCP server.
registerTool( server, 'stop_sim_log_cap', 'Stops an active simulator log capture session and returns the captured logs.', schema, handler, ); - src/utils/log_capture.ts:102-133 (helper)Core utility function stopLogCapture that terminates log capture processes, reads the log file content, and cleans up the session from activeLogSessions map.
export async function stopLogCapture( logSessionId: string, ): Promise<{ logContent: string; error?: string }> { const session = activeLogSessions.get(logSessionId); if (!session) { log('warning', `Log session not found: ${logSessionId}`); return { logContent: '', error: `Log capture session not found: ${logSessionId}` }; } try { log('info', `Attempting to stop log capture session: ${logSessionId}`); const logFilePath = session.logFilePath; for (const process of session.processes) { if (!process.killed && process.exitCode === null) { process.kill('SIGTERM'); } } activeLogSessions.delete(logSessionId); log( 'info', `Log capture session ${logSessionId} stopped. Log file retained at: ${logFilePath}`, ); await fs.promises.access(logFilePath, fs.constants.R_OK); const fileContent = await fs.promises.readFile(logFilePath, 'utf-8'); log('info', `Successfully read log content from ${logFilePath}`); return { logContent: fileContent }; } catch (error) { const message = error instanceof Error ? error.message : String(error); log('error', `Failed to stop log capture session ${logSessionId}: ${message}`); return { logContent: '', error: message }; } }