Skip to main content
Glama

stop_device_log_cap

Terminates an active Apple device log capture session and retrieves the collected logs using the specified session ID in XcodeBuildMCP.

Instructions

Stops an active Apple device log capture session and returns the captured logs.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
logSessionIdYesThe session ID returned by start_device_log_cap.

Implementation Reference

  • MCP tool registration object exported as default, including name, description, schema, and handler that delegates to the main logic function.
    export default {
      name: 'stop_device_log_cap',
      description: 'Stops an active Apple device log capture session and returns the captured logs.',
      schema: stopDeviceLogCapSchema.shape, // MCP SDK compatibility
      handler: createTypedTool(
        stopDeviceLogCapSchema,
        (params: StopDeviceLogCapParams) => {
          return stop_device_log_capLogic(params, getDefaultFileSystemExecutor());
        },
        getDefaultCommandExecutor,
      ),
    };
  • Zod schema for the tool input parameters, requiring logSessionId.
    const stopDeviceLogCapSchema = z.object({
      logSessionId: z.string().describe('The session ID returned by start_device_log_cap.'),
    });
  • Core handler function that stops the log capture process, reads the log file, removes the session, and returns the captured logs or error.
    export async function stop_device_log_capLogic(
      params: StopDeviceLogCapParams,
      fileSystemExecutor: FileSystemExecutor,
    ): Promise<ToolResponse> {
      const { logSessionId } = params;
    
      const session = activeDeviceLogSessions.get(logSessionId);
      if (!session) {
        log('warning', `Device log session not found: ${logSessionId}`);
        return {
          content: [
            {
              type: 'text',
              text: `Failed to stop device log capture session ${logSessionId}: Device log capture session not found: ${logSessionId}`,
            },
          ],
          isError: true,
        };
      }
    
      try {
        log('info', `Attempting to stop device log capture session: ${logSessionId}`);
    
        const shouldSignalStop =
          !(session.hasEnded ?? false) &&
          session.process.killed !== true &&
          session.process.exitCode == null;
    
        if (shouldSignalStop) {
          session.process.kill?.('SIGTERM');
        }
    
        await waitForSessionToFinish(session);
    
        if (session.logStream) {
          await ensureStreamClosed(session.logStream);
        }
    
        const logFilePath = session.logFilePath;
        activeDeviceLogSessions.delete(logSessionId);
    
        // Check file access
        if (!fileSystemExecutor.existsSync(logFilePath)) {
          throw new Error(`Log file not found: ${logFilePath}`);
        }
    
        const fileContent = await fileSystemExecutor.readFile(logFilePath, 'utf-8');
        log('info', `Successfully read device log content from ${logFilePath}`);
    
        log(
          'info',
          `Device log capture session ${logSessionId} stopped. Log file retained at: ${logFilePath}`,
        );
    
        return {
          content: [
            {
              type: 'text',
              text: `✅ Device log capture session stopped successfully\n\nSession ID: ${logSessionId}\n\n--- Captured Logs ---\n${fileContent}`,
            },
          ],
        };
      } catch (error) {
        const message = error instanceof Error ? error.message : String(error);
        log('error', `Failed to stop device log capture session ${logSessionId}: ${message}`);
        return {
          content: [
            {
              type: 'text',
              text: `Failed to stop device log capture session ${logSessionId}: ${message}`,
            },
          ],
          isError: true,
        };
      }
    }
  • Helper function to wait for the log capture process to finish, using event listeners or polling.
    async function waitForSessionToFinish(session: DeviceLogSession): Promise<void> {
      if (session.hasEnded) {
        return;
      }
    
      if (session.process.exitCode != null) {
        session.hasEnded = true;
        return;
      }
    
      if (typeof session.process.once === 'function') {
        await new Promise<void>((resolve) => {
          const onClose = (): void => {
            clearTimeout(timeout);
            session.hasEnded = true;
            resolve();
          };
    
          const timeout = setTimeout(() => {
            session.process.removeListener?.('close', onClose);
            session.hasEnded = true;
            resolve();
          }, 1000);
    
          session.process.once('close', onClose);
    
          if (session.hasEnded || session.process.exitCode != null) {
            session.process.removeListener?.('close', onClose);
            onClose();
          }
        });
        return;
      }
    
      // Fallback polling for minimal mock processes (primarily in tests)
      for (let i = 0; i < 20; i += 1) {
        if (session.hasEnded || session.process.exitCode != null) {
          session.hasEnded = true;
          break;
        }
        await new Promise((resolve) => setTimeout(resolve, 50));
      }
    }
  • Re-export of the main tool implementation from logging directory for device tools organization.
    // Re-export from logging to complete workflow
    export { default } from '../logging/stop_device_log_cap.ts';
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It states the tool stops a session and returns logs, which implies a read operation with potential side effects (ending the session). However, it lacks details on permissions required, whether the operation is reversible, error handling, or what format/logs are returned. For a tool with no annotations, this leaves significant behavioral gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence that efficiently conveys the core action and outcome. It's front-loaded with the main purpose and has no redundant or unnecessary information, making it highly concise and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (stops a session and returns data), lack of annotations, and no output schema, the description is minimally adequate. It covers the basic purpose but misses details on return values, error conditions, and behavioral nuances. It relies on the schema for parameter info, leaving gaps in overall context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, with the parameter 'logSessionId' documented as 'The session ID returned by start_device_log_cap.' The description doesn't add any additional parameter semantics beyond what the schema provides, such as format examples or constraints. With high schema coverage, the baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Stops an active Apple device log capture session and returns the captured logs.' It specifies the verb ('stops'), resource ('Apple device log capture session'), and outcome ('returns the captured logs'). However, it doesn't explicitly differentiate from its sibling 'stop_sim_log_cap', which appears to be a similar tool for simulators rather than physical devices.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context by mentioning 'active Apple device log capture session' and referencing 'start_device_log_cap' in the parameter description, suggesting this tool should be used after starting a session. However, it doesn't provide explicit guidance on when to use this vs. alternatives like 'stop_sim_log_cap' or other logging-related tools, nor does it mention prerequisites or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/getsentry/XcodeBuildMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server