MCP Delphi构建服务器
一个MCP(模型上下文协议)服务器,它公开了使用MSBuild在Windows上构建和清理Delphi项目(.dproj/.groupproj)的工具,通过rsvars.bat初始化RAD Studio环境。
先决条件
- 视窗
- Node.js>=18
- 安装了Embarcadero RAD Studio(用于rsvars.bat和Delphi工具链)
- MSBuild可用(Visual Studio生成工具或RAD Studio工具链)
安装
pnpm install
pnpm run build或者使用npm:
npm install
npm run build配置
您可以通过环境变量配置默认值(如果需要,可以使用此目录中的.env文件):
- RSVARS_BAT:RSVARS.BAT的完整路径(例如,C:\\程序文件(x86)\\Embarcadero\\Studio \\23.0\\bin\\RSVARS.cat)
- MSBUILD_PATH:如果不在PATH中,则为MSBUILD.exe的完整路径
- DELPHI_CONFIG:默认配置(调试/发布)。默认值:释放
- DELPHI_PLATFORM:默认平台(Win32/Win64)。默认值:Win32
创建一个.env文件,如下所示:
RSVARS_BAT=C:\Program Files (x86)\Embarcadero\Studio\23.0\bin\rsvars.bat
MSBUILD_PATH=C:\Program Files\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\MSBuild.exe
DELPHI_CONFIG=Release
DELPHI_PLATFORM=Win32跑步
此服务器通过stdio与MCP通信。从以下内容开始:
node --env-file=.env dist/server.js或者,在全局安装(或作为依赖项安装)后,运行bin:
mcp-delphi-server在开发过程中:
pnpm run dev工具
- 德尔福大厦
- params:项目(字符串,.dproj/.groupproj的路径),配置?(字符串),平台?(string),msbuildPath?(字符串),rsvarsPath?(字符串) - 使用MSBuild生成项目。如果提供了rsvarsPath(或RSVARS_BAT env),则将在单个shell中在MSBuild之前调用它。
- delphi.clean
- params:与delphi.build相同 - 清理项目。
- fpc.build
- params:源(字符串,.lpr/.pas的路径),输出?(string),定义?(string\[\]),unitPaths?(string\[\]),包括路径吗?(string\[\]),cpu?(字符串),os?(字符串),fpcPath?(字符串) - 使用Free Pascal编译器编译Pascal程序。您可以传递显式fpcPath或依赖PATH。
- 拉扎勒斯建筑
- params:项目(字符串,到.lpi的路径),buildMode?(字符串),cpu?(字符串),os?(字符串),lazbuildPath?(字符串) - 使用lazbuild构建Lazarus项目。可选择设置CPU/OS或构建模式。
- 拉扎鲁清洁
- params:项目(字符串,到.lpi的路径),lazbuildPath?(字符串) - 清洁拉撒路通过lazbuild建造人工制品——清洁。
测试项目和脚本
此仓库包括以下小型Delphi测试项目 test/projects,以及拉撒路的样本 test/projects/lazarus.Helper脚本已上线 scripts/.
- 构建所有发布目标:
- pnpm run test:build:all
- 单独构建(示例):
- pnpm run test:build:console:win32 - pnpm run test:build:console:win64 - pnpm run test:build:vcl:win32 - pnpm run test:build:vcl:win64 - pnpm run test:build:group:win32 - pnpm run test:build:group:win64
- 清洁变体也存在于
test:clean:*.
调用示例
- Delphi通过MSBuild
{
"name": "delphi.build",
"arguments": {
"project": "C:/path/to/MyApp.dproj",
"configuration": "Release",
"platform": "Win64"
}
}- Windows上的FPC(使用显式编译器路径)
{
"name": "fpc.build",
"arguments": {
"source": "C:/path/to/lazarus/project1.lpr",
"cpu": "x86_64",
"os": "win64",
"fpcPath": "C:/path/to/fpc.exe"
}
}- Lazarus通过Windows上的lazbuild
{
"name": "lazarus.build",
"arguments": {
"project": "C:/path/to/lazarus/project1.lpi",
"cpu": "x86_64",
"os": "win64",
"lazbuildPath": "C:/path/to/lazbuild.exe"
}
}备注
- Windows优先。Delphi集成需要RAD Studio工具链和MSBuild。
- 对于RAD Studio,rsvars.bat设置所需的环境变量(如BDS、FrameworkDir、库路径)。建议设置RSVARS_BAT以确保Delphi工具链可用于MSBuild。
- 支持团体项目(.groupproj);MSBuild将遍历包含的项目。
- FPC/Lazarus支持通过FPC和lazbuild提供。如果路径不在PATH中,请在Windows上提供显式路径。
发布
- 确保
dist已建成:pnpm run build - 可选择通过以下方式进行本地测试:
pnpm run test:build:all - 发布到npm:
- npm publish (或 pnpm publish)
如果在某个范围内发布,请相应地设置包名,并确保您以正确的访问权限登录。
