delphi.clean
Clean Delphi project files (.dproj/.groupproj) using MSBuild with RAD Studio environment to remove intermediate build artifacts and prepare for fresh compilation.
Instructions
Clean a Delphi .dproj or .groupproj using MSBuild with RAD Studio environment
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project | Yes | Path to a Delphi .dproj or .groupproj file | |
| configuration | No | ||
| platform | No | Win64 | |
| msbuildPath | No | ||
| rsvarsPath | No |
Implementation Reference
- src/server.ts:115-145 (handler)The main handler function that performs the Delphi clean operation using MSBuild, including project validation, argument construction, and execution with optional RAD Studio environment setup via rsvars.bat.
async function cleanWithMSBuild({ project, configuration, platform, msbuildPath, rsvarsPath }: { project: string; configuration?: string; platform?: string; msbuildPath?: string; rsvarsPath?: string; }) { const projPath = resolve(project); if (!existsSync(projPath)) { throw new Error(`Project not found: ${projPath}`); } if (!isDelphiProject(projPath)) { throw new Error('Unsupported project type. Provide a .dproj or .groupproj file'); } const { rsvars, msbuild } = resolveDefaults(); const rsvarsFinal = rsvarsPath || rsvars; const msbuildFinal = msbuildPath || msbuild || 'msbuild'; const args = [ '"' + projPath + '"', '/t:Clean', configuration ? `/p:Config=${configuration}` : '', platform ? `/p:Platform=${platform}` : '' ].filter(Boolean); if (rsvarsFinal && existsSync(rsvarsFinal)) { const cmd = 'cmd'; const composite = [ '/s', '/c', `"@echo off && call \"${rsvarsFinal}\" && ${msbuildFinal} ${args.join(' ')}"` ]; return await runCommand(cmd, composite); } return await runCommand(msbuildFinal, args); } - src/server.ts:35-41 (schema)Zod-based input schema defining parameters for the delphi.clean tool: required project path and optional configuration, platform, msbuild path, and rsvars path.
const CleanInput = { project: z.string().describe('Path to a Delphi .dproj or .groupproj file'), configuration: z.string().optional(), platform: z.string().optional().default(process.env.DELPHI_PLATFORM || 'Win32'), msbuildPath: z.string().optional(), rsvarsPath: z.string().optional() }; - src/server.ts:233-248 (registration)Registers the delphi.clean tool with the MCP server, linking the schema and execution handler that formats the command output.
mcpServer.registerTool('delphi.clean', { description: 'Clean a Delphi .dproj or .groupproj using MSBuild with RAD Studio environment', inputSchema: CleanInput, }, async (req: any) => { const { code, stdout, stderr } = await cleanWithMSBuild(req); const ok = code === 0; return { content: [ { type: 'text', text: ok ? `Clean succeeded for ${basename(req.project)}` : `Clean failed for ${basename(req.project)}` }, { type: 'text', text: `Exit code: ${code}` }, { type: 'text', text: '--- STDOUT ---\n' + stdout }, { type: 'text', text: '--- STDERR ---\n' + stderr } ], isError: !ok }; }); - src/server.ts:75-78 (helper)Helper function used to validate if the provided project file is a Delphi project by checking extension.
function isDelphiProject(file: string) { const ext = extname(file).toLowerCase(); return ext === '.dproj' || ext === '.groupproj'; } - src/server.ts:69-73 (helper)Helper function to load default paths for rsvars.bat and MSBuild from environment variables.
function resolveDefaults() { const rsvars = process.env.RSVARS_BAT || process.env.RSVARS_PATH; const msbuild = process.env.MSBUILD_PATH; return { rsvars, msbuild }; }