fpc.build
Compile Pascal source files (.lpr/.pas) using the Free Pascal Compiler to generate executable binaries with configurable CPU/OS targets and search paths.
Instructions
Build with Free Pascal Compiler (fpc) for a Pascal program or project file
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| source | Yes | Path to a Pascal program (.lpr/.pas) or unit to compile with FPC | |
| output | No | Optional output binary path/name | |
| defines | No | Conditional defines, e.g. FOO=1 | |
| unitPaths | No | Additional unit search paths (-Fu) | |
| includePaths | No | Additional include search paths (-Fi) | |
| cpu | No | Target CPU, e.g. x86_64, i386, aarch64 | |
| os | No | Target OS, e.g. win64, win32, linux | |
| fpcPath | No | Path to fpc compiler (defaults to "fpc") |
Implementation Reference
- src/server.ts:254-266 (handler)Inline asynchronous handler function for the 'fpc.build' tool. It invokes buildWithFpc with the request parameters, checks the exit code, and returns a structured response with stdout/stderr content blocks.}, async (req: any) => { const { code, stdout, stderr } = await buildWithFpc(req); const ok = code === 0; return { content: [ { type: 'text', text: ok ? `FPC build succeeded for ${basename(req.source)}` : `FPC build failed for ${basename(req.source)}` }, { type: 'text', text: `Exit code: ${code}` }, { type: 'text', text: '--- STDOUT ---\n' + stdout }, { type: 'text', text: '--- STDERR ---\n' + stderr } ], isError: !ok }; });
- src/server.ts:44-53 (schema)Zod-based input schema definition for the 'fpc.build' tool, specifying parameters such as source file, output, defines, paths, target CPU/OS, and fpc path.const FpcBuildInput = { source: z.string().describe('Path to a Pascal program (.lpr/.pas) or unit to compile with FPC'), output: z.string().optional().describe('Optional output binary path/name'), defines: z.array(z.string()).optional().describe('Conditional defines, e.g. FOO=1'), unitPaths: z.array(z.string()).optional().describe('Additional unit search paths (-Fu)'), includePaths: z.array(z.string()).optional().describe('Additional include search paths (-Fi)'), cpu: z.string().optional().describe('Target CPU, e.g. x86_64, i386, aarch64'), os: z.string().optional().describe('Target OS, e.g. win64, win32, linux'), fpcPath: z.string().optional().describe('Path to fpc compiler (defaults to "fpc")') };
- src/server.ts:251-254 (registration)Registration of the 'fpc.build' MCP tool, specifying its name, description, and input schema, with the handler function provided next.mcpServer.registerTool('fpc.build', { description: 'Build with Free Pascal Compiler (fpc) for a Pascal program or project file', inputSchema: FpcBuildInput, }, async (req: any) => {
- src/server.ts:153-172 (helper)Core helper function that constructs FPC compiler arguments based on input parameters, validates the source file, and spawns the fpc process using runCommand.async function buildWithFpc({ source, output, defines, unitPaths, includePaths, cpu, os, fpcPath }: { source: string; output?: string; defines?: string[]; unitPaths?: string[]; includePaths?: string[]; cpu?: string; os?: string; fpcPath?: string; }) { const srcPath = resolve(source); if (!existsSync(srcPath)) { throw new Error(`Source not found: ${srcPath}`); } if (!isFpcSource(srcPath)) { throw new Error('Unsupported source type. Provide a .lpr/.pas/.pp'); } const args: string[] = []; if (cpu) args.push(`-P${cpu}`); if (os) args.push(`-T${os}`); if (output) args.push(`-o${resolve(output)}`); (defines || []).forEach(d => args.push(`-d${d}`)); (unitPaths || []).forEach(p => args.push(`-Fu${resolve(p)}`)); (includePaths || []).forEach(p => args.push(`-Fi${resolve(p)}`)); args.push('"' + srcPath + '"'); const compiler = fpcPath || 'fpc'; // Use the source directory as CWD so relative includes work return await runCommand(compiler, args, { cwd: dirname(srcPath) }); }
- src/server.ts:148-151 (helper)Helper function to check if a file is a valid Free Pascal source file based on extension.function isFpcSource(file: string) { const ext = extname(file).toLowerCase(); return ext === '.pas' || ext === '.pp' || ext === '.p' || ext === '.lpr'; }