Skip to main content
Glama
flydev-fr
by flydev-fr

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
NameRequiredDescriptionDefault
sourceYesPath to a Pascal program (.lpr/.pas) or unit to compile with FPC
outputNoOptional output binary path/name
definesNoConditional defines, e.g. FOO=1
unitPathsNoAdditional unit search paths (-Fu)
includePathsNoAdditional include search paths (-Fi)
cpuNoTarget CPU, e.g. x86_64, i386, aarch64
osNoTarget OS, e.g. win64, win32, linux
fpcPathNoPath to fpc compiler (defaults to "fpc")

Implementation Reference

  • 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 }; });
  • 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) => {
  • 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) }); }
  • 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'; }

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/flydev-fr/mcp-delphi'

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