Skip to main content
Glama

swift_package_clean

Removes Swift Package build artifacts and derived data to free disk space and resolve build issues by specifying the package path.

Instructions

Cleans Swift Package build artifacts and derived data

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
packagePathYesPath to the Swift package root (Required)

Implementation Reference

  • The main handler function that performs input validation, executes the 'swift package clean' command, handles output, and returns appropriate MCP tool responses.
      const pkgValidation = validateRequiredParam('packagePath', params.packagePath);
      if (!pkgValidation.isValid) return pkgValidation.errorResponse!;
    
      const resolvedPath = path.resolve(params.packagePath);
      const args: string[] = ['package', '--package-path', resolvedPath, 'clean'];
    
      log('info', `Running swift ${args.join(' ')}`);
      try {
        const result = await executeCommand(['swift', ...args], 'Swift Package Clean');
        if (!result.success) {
          const errorMessage = result.error || result.output || 'Unknown error';
          return createErrorResponse('Swift package clean failed', errorMessage, 'CleanError');
        }
    
        return {
          content: [
            { type: 'text', text: '✅ Swift package cleaned successfully.' },
            {
              type: 'text',
              text: '💡 Build artifacts and derived data removed. Ready for fresh build.',
            },
            { type: 'text', text: result.output || '(clean completed silently)' },
          ],
        };
      } catch (error) {
        const message = error instanceof Error ? error.message : String(error);
        log('error', `Swift package clean failed: ${message}`);
        return createErrorResponse('Failed to execute swift package clean', message, 'SystemError');
      }
    },
  • Zod schema defining the input parameters for the tool (requires packagePath).
      packagePath: z.string().describe('Path to the Swift package root (Required)'),
    },
  • Local registration function that registers the tool with the MCP server, including name, description, schema, and handler.
      registerTool(
        server,
        'swift_package_clean',
        'Cleans Swift Package build artifacts and derived data',
        {
          packagePath: z.string().describe('Path to the Swift package root (Required)'),
        },
        async (params: { packagePath: string }): Promise<ToolResponse> => {
          const pkgValidation = validateRequiredParam('packagePath', params.packagePath);
          if (!pkgValidation.isValid) return pkgValidation.errorResponse!;
    
          const resolvedPath = path.resolve(params.packagePath);
          const args: string[] = ['package', '--package-path', resolvedPath, 'clean'];
    
          log('info', `Running swift ${args.join(' ')}`);
          try {
            const result = await executeCommand(['swift', ...args], 'Swift Package Clean');
            if (!result.success) {
              const errorMessage = result.error || result.output || 'Unknown error';
              return createErrorResponse('Swift package clean failed', errorMessage, 'CleanError');
            }
    
            return {
              content: [
                { type: 'text', text: '✅ Swift package cleaned successfully.' },
                {
                  type: 'text',
                  text: '💡 Build artifacts and derived data removed. Ready for fresh build.',
                },
                { type: 'text', text: result.output || '(clean completed silently)' },
              ],
            };
          } catch (error) {
            const message = error instanceof Error ? error.message : String(error);
            log('error', `Swift package clean failed: ${message}`);
            return createErrorResponse('Failed to execute swift package clean', message, 'SystemError');
          }
        },
      );
    }
  • Top-level registration configuration that conditionally enables the tool based on the environment variable XCODEBUILDMCP_TOOL_SWIFT_PACKAGE_CLEAN.
      register: registerCleanSwiftPackageTool,
      groups: [ToolGroup.SWIFT_PACKAGE_WORKFLOW],
      envVar: 'XCODEBUILDMCP_TOOL_SWIFT_PACKAGE_CLEAN',
    },
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool performs cleanup (a destructive operation) but doesn't specify what exactly gets deleted, whether the operation is reversible, potential side effects, or permission requirements. For a destructive tool with zero annotation coverage, 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, efficient sentence that immediately conveys the core function without unnecessary words. It's perfectly front-loaded with the essential information and contains no redundant or verbose elements.

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

Completeness2/5

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

For a destructive cleanup tool with no annotations and no output schema, the description is insufficient. It doesn't explain what 'build artifacts and derived data' specifically includes, what the tool returns (success/failure indicators), or important behavioral aspects like whether it requires the package to be in a particular state. The context demands more comprehensive documentation.

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 schema has 100% description coverage, with the single parameter 'packagePath' well-documented in the schema itself. The description doesn't add any parameter-specific information beyond what the schema already provides, so it meets the baseline of 3 for high schema coverage without adding extra value.

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

Purpose5/5

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

The description clearly states the specific action ('Cleans') and target resources ('Swift Package build artifacts and derived data'), distinguishing it from sibling tools like clean_proj and clean_ws which target different resources. It uses precise technical terminology that accurately conveys the tool's function.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives like clean_proj or clean_ws, nor does it mention prerequisites or typical use cases. While the name implies it's for Swift packages specifically, there's no explicit comparison to sibling tools that handle similar cleanup for different project types.

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

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/SampsonKY/XcodeBuildMCP'

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