List xctrace recording templates
listTraceTemplatesReturns parsed standard and custom xctrace templates for selecting a profile template, such as 'Time Profiler' or 'Allocations'.
Instructions
[mg.discover] Run xcrun xctrace list templates and return parsed standard + custom templates. Useful when picking a template name for recordTimeProfile (e.g. "Time Profiler", "Animation Hitches", "Allocations").
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/tools/listTraceTemplates.ts:42-54 (handler)The main handler function that executes the tool. It runs `xcrun xctrace list templates` via runCommand, checks exit code, and returns parsed templates.
export async function listTraceTemplates( _input: ListTraceTemplatesInput, ): Promise<ListTraceTemplatesResult> { const result = await runCommand("xcrun", ["xctrace", "list", "templates"], { timeoutMs: 15_000, }); if (result.code !== 0) { throw new Error( `xctrace list templates failed (code ${result.code}): ${result.stderr || result.stdout}`, ); } return { ok: true, templates: parseTemplateListing(result.stdout) }; } - Pure helper function `parseTemplateListing` that parses the 'xctrace list templates' output, extracting standard and custom template names.
export function parseTemplateListing(text: string): TraceTemplate[] { const lines = text.split(/\r?\n/); let category: TraceTemplate["category"] | null = null; const templates: TraceTemplate[] = []; for (const raw of lines) { const line = raw.trim(); if (!line) continue; if (line === "== Standard Templates ==") { category = "standard"; continue; } if (line === "== Custom Templates ==") { category = "custom"; continue; } if (!category) continue; if (line.startsWith("==")) continue; templates.push({ name: line, category }); } return templates; } - src/tools/listTraceTemplates.ts:1-17 (schema)Zod schema (empty object), TypeScript types, and interfaces for the tool's input/output. Defines the TraceTemplate and ListTraceTemplatesResult interfaces.
import { z } from "zod"; import { runCommand } from "../runtime/exec.js"; export const listTraceTemplatesSchema = z.object({}); export type ListTraceTemplatesInput = z.infer<typeof listTraceTemplatesSchema>; export interface TraceTemplate { name: string; /** "standard" for built-in templates, "custom" for user templates. */ category: "standard" | "custom"; } export interface ListTraceTemplatesResult { ok: boolean; templates: TraceTemplate[]; } - src/index.ts:265-279 (registration)Tool registration in the MCP server: registers 'listTraceTemplates' with title, description, inputSchema, and a handler that calls listTraceTemplates and returns JSON text content.
server.registerTool( "listTraceTemplates", { title: "List xctrace recording templates", description: "[mg.discover] Run `xcrun xctrace list templates` and return parsed standard + custom templates. Useful when picking a template name for `recordTimeProfile` (e.g. \"Time Profiler\", \"Animation Hitches\", \"Allocations\").", inputSchema: listTraceTemplatesSchema.shape, }, async (input) => { const result = await listTraceTemplates(input); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }], }; }, );