Xcode MCP Snippet
Overview
Run small Swift snippets through Xcode MCP with access to the selected source file's module context, including fileprivate declarations.
Tool Availability
Before calling MCP tools, confirm the mcp__xcode namespace is available. If it is not available, use tool_search to expose Xcode MCP tools; if the tools still are not available, tell the user Xcode MCP is not connected and stop rather than editing files to simulate snippet execution.
Workflow
- Confirm the snippet is small, deterministic, and safe to run in the target context.
- Discover Xcode tabs with
mcp__xcode.XcodeListWindows. - Select the
tabIdentifierfor the workspace/project containing the source file. - Choose a Swift
sourceFilePathin a target that builds an app, framework, library, or command-line executable. - Call
mcp__xcode.ExecuteSnippetwith a concisepurpose, thesourceFilePath, thecodeSnippet, and a timeout appropriate for the work. - Summarize printed output and any compile/runtime errors.
Snippet Guidelines
- Include explicit
printstatements for values the user needs to see. - Keep the
purposehuman-readable and avoid the word "test"; this tool is snippet execution, not XCTest. - Do not run snippets with filesystem writes, network requests, account, signing, destructive, or production-affecting side effects. If the user requests one of these, explain that
ExecuteSnippetis for deterministic in-target Swift evaluation and choose a safer workflow instead. - Prefer pure logic checks, type construction, formatting output, and local helper behavior.
Reporting
- Show the important printed output.
- State the file context and Xcode tab used.
- If the snippet cannot run because the file is not in a supported target, explain that precisely and choose a better source file if one is obvious.
Constraints
- Do not use snippets as a substitute for real unit tests when the user asks for test coverage.
- Do not leave temporary
printstatements or helper code in the repository; snippets run through MCP and should not require source edits.