refactor: cad_mcp_aec 工具改按仓库既有格式描述,并合入 mcp_config.json
现象:上一版自己发明的描述文件 cad-mcp-aec.json 与仓库既有工具(add_line /
query_entities / get_entity_detail)的风格不一致——工具名前缀不同、
点用 {x,y,z} 对象而不是 [x,y] 数组、颜色叫 color_index 而不是 color。
另外 cad_mcp_frame 的运行期配置文件名是 mcp_config.json(找不到才回落
cad-mcp-frame.json),单个 cad-mcp-aec.json 还得手工合并。
改动:
1. 工具改名,与既有工具同一套动词_名词风格:
list_aec_entities -> query_aec_entities
get_aec_entity -> get_aec_entity_detail
create_aec_pipe|wall|slab|column|beam -> add_aec_*
2. 参数约定对齐既有工具:
- 点改用 [x,y] / [x,y,z] 数组(对象写法仍兼容,后端不变);
- 颜色用 color(ACI,256=ByLayer),并兼容旧写法 color_index;
- add_* 支持 space(Model 或布局名),缺省模型空间;
- get_aec_entity_detail 的输出也从 color_index 改成 color,和入参对称。
3. 删掉自定义的 cad-mcp-aec.json,把 12 个工具按标准 MCP 字段 + backend
(type/dll_name/factory_function)写进 cad_mcp_aec/mcp_config.json,
与既有 28 个工具同一份文件;inputSchema 写全,带每个参数的 description。
4. 插件里的 private_name()/private_input_schema() 同步成同一套名字与 schema,
保证配置里没写 schema 时回落也一致。
验证:
- R230 Debug / Z2026 Debug 均编译通过并部署。
- AutoCAD 2020 实测(部署目录放这份 mcp_config.json,cad_mcp_frame 优先读它):
tools/list = 30(既有 18 + 本插件 12),12 个 add_aec_*/update_aec_* 工厂全部加载成功;
query 列出 20 根管道;add_aec_pipe 用 [0,0,0]->[2000,0,0] + color=1 建成功,
detail 读回 dn_mm=100/od_mm=114/wall_thickness_mm=4/color=1;
只给 end 的 update 后端点变 2500、壁厚与颜色不变;
add_aec_wall/slab/column/beam 各建一次并读回参数一致。
已知(与本次改动无关):mcp_config.json 里有 10 个工具在仓库当前的
cad_mcp_plugins.dll 里没有对应工厂函数(AddText/AddMText/AddLine/AddPolyline/
AddLeaderAnnotation/DeleteEntities/SetEntityProperties/DrawRevisionCloud/
FindCollisions/SetDrawingArea),会被静默丢掉,补齐需要先把那些工具的实现
补进 cad_mcp_plugins。
This commit is contained in:
1 parent
c85b1b645e
commit
4f1ea72e4e
4 files changed
+1769
-139
No files matched your search
@@ -43,7 +43,7 @@ bool applyPipe(AecDbEwPipe* p, const nlohmann::json& a, bool bCreate, std::wstri
|
||||
|
||||
if (bCreate && (!bHasS || !bHasE))
|
||||
{
|
||||
err = L"create_aec_pipe 需要 start / end({\"x\",\"y\",\"z\"} 或 [x,y,z])";
|
||||
err = L"add_aec_pipe 需要 start / end({\"x\",\"y\",\"z\"} 或 [x,y,z])";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ bool applyPipe(AecDbEwPipe* p, const nlohmann::json& a, bool bCreate, std::wstri
|
||||
{
|
||||
if (dDn <= 0.0)
|
||||
{
|
||||
err = L"create_aec_pipe 需要 dn_mm(公称直径,mm)";
|
||||
err = L"add_aec_pipe 需要 dn_mm(公称直径,mm)";
|
||||
return false;
|
||||
}
|
||||
// 与 BZGDDlg 一致:截面圆用 DN(米制)
|
||||
@@ -109,8 +109,12 @@ bool applyPipe(AecDbEwPipe* p, const nlohmann::json& a, bool bCreate, std::wstri
|
||||
pX->SetAt(PIPE_SYS, wstrOr(a, "system", L"").c_str());
|
||||
if (hasKey(a, "material"))
|
||||
pX->SetAt(PIPE_MATERIAL, wstrOr(a, "material", L"").c_str());
|
||||
if (hasKey(a, "color_index"))
|
||||
pX->SetAt(_T("COLOR"), intOr(a, "color_index", 0));
|
||||
// 颜色:与 cad_mcp_plugins 的既有工具统一用 color(ACI,256=ByLayer),
|
||||
// 同时兼容旧写法 color_index
|
||||
if (hasKey(a, "color"))
|
||||
pX->SetAt(_T("COLOR"), intOr(a, "color", 256));
|
||||
else if (hasKey(a, "color_index"))
|
||||
pX->SetAt(_T("COLOR"), intOr(a, "color_index", 256));
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -124,7 +128,7 @@ bool applyWall(AecDbXWall* p, const nlohmann::json& a, bool bCreate, std::wstrin
|
||||
|
||||
if (bCreate && (!bHasS || !bHasE))
|
||||
{
|
||||
err = L"create_aec_wall 需要 start / end";
|
||||
err = L"add_aec_wall 需要 start / end";
|
||||
return false;
|
||||
}
|
||||
if (bHasS && bHasE)
|
||||
@@ -176,7 +180,7 @@ bool applySlab(AecDbXSlab* p, const nlohmann::json& a, bool bCreate, std::wstrin
|
||||
|
||||
if (bCreate && !bHasPts)
|
||||
{
|
||||
err = L"create_aec_slab 需要 points:[[x,y],...](至少 3 个点,可不闭合)";
|
||||
err = L"add_aec_slab 需要 points:[[x,y],...](至少 3 个点,可不闭合)";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -196,7 +200,7 @@ bool applySlab(AecDbXSlab* p, const nlohmann::json& a, bool bCreate, std::wstrin
|
||||
const double dElev = numOr(a, "bottom_elevation", 0.0);
|
||||
if (bCreate && dThick <= 0.0)
|
||||
{
|
||||
err = L"create_aec_slab 需要 thickness(板厚)> 0";
|
||||
err = L"add_aec_slab 需要 thickness(板厚)> 0";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -275,7 +279,7 @@ bool applyColumn(AecDbColumn* p, const nlohmann::json& a, bool bCreate, std::wst
|
||||
|| hasKey(a, "width") || hasKey(a, "rotation_deg");
|
||||
if (bCreate && !bHasPos)
|
||||
{
|
||||
err = L"create_aec_column 需要 position(柱底中心点)";
|
||||
err = L"add_aec_column 需要 position(柱底中心点)";
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -314,7 +318,7 @@ bool applyBeam(AecDbBeam* p, const nlohmann::json& a, bool bCreate, std::wstring
|
||||
|
||||
if (bCreate && (!bHasS || !bHasE))
|
||||
{
|
||||
err = L"create_aec_beam 需要 start / end";
|
||||
err = L"add_aec_beam 需要 start / end";
|
||||
return false;
|
||||
}
|
||||
if (bHasS && bHasE)
|
||||
@@ -365,8 +369,13 @@ nlohmann::json finishCreate(AcDbEntity* pEnt, const nlohmann::json& a, const cha
|
||||
}
|
||||
}
|
||||
|
||||
// space:与 cad_mcp_plugins 的 add_* 工具一致,缺省模型空间
|
||||
std::wstring sSpace;
|
||||
if (hasKey(a, "space"))
|
||||
sSpace = wstrOr(a, "space", L"");
|
||||
|
||||
AcDbObjectId idNew;
|
||||
Acad::ErrorStatus es = addToSpace(pEnt, &idNew);
|
||||
Acad::ErrorStatus es = addToSpace(pEnt, &idNew, sSpace);
|
||||
|
||||
// 句柄要**入图之后**才有值:append 之前 pEnt 还没 handle,取出来是 "0"
|
||||
const std::string sHandle = (es == Acad::eOk) ? handleOf(pEnt) : std::string();
|
||||
@@ -436,7 +445,7 @@ nlohmann::json finishUpdate(AcDbObject* pObj, const std::string& sHandle, const
|
||||
class ToolCreatePipe : public mcp_Tool
|
||||
{
|
||||
public:
|
||||
std::string private_name() const override { return "create_aec_pipe"; }
|
||||
std::string private_name() const override { return "add_aec_pipe"; }
|
||||
|
||||
std::string private_description() const override
|
||||
{
|
||||
@@ -457,7 +466,7 @@ public:
|
||||
"wall_thickness_mm": { "type": "number", "description": "壁厚,毫米(缺省不改)" },
|
||||
"system": { "type": "string", "description": "管道系统名,如 给水/排水" },
|
||||
"material": { "type": "string", "description": "材质名" },
|
||||
"color_index": { "type": "integer", "description": "颜色索引(AutoCAD 颜色号)" },
|
||||
"color": { "type": "integer", "description": "ACI 颜色号,256=ByLayer" },
|
||||
"layer": { "type": "string", "description": "图层名,留空用当前图层" }
|
||||
},
|
||||
"required": [ "start", "end", "dn_mm" ]
|
||||
@@ -506,7 +515,7 @@ public:
|
||||
"wall_thickness_mm": { "type": "number", "description": "新壁厚,毫米(可选)" },
|
||||
"system": { "type": "string", "description": "管道系统名(可选)" },
|
||||
"material": { "type": "string", "description": "材质(可选)" },
|
||||
"color_index": { "type": "integer", "description": "颜色索引(可选)" }
|
||||
"color": { "type": "integer", "description": "ACI 颜色号,256=ByLayer(可选)" }
|
||||
},
|
||||
"required": [ "handle" ]
|
||||
})");
|
||||
@@ -539,7 +548,7 @@ EXPORT_MCP_TOOL(ToolUpdatePipe, UpdateAecPipeTool)
|
||||
class ToolCreateWall : public mcp_Tool
|
||||
{
|
||||
public:
|
||||
std::string private_name() const override { return "create_aec_wall"; }
|
||||
std::string private_name() const override { return "add_aec_wall"; }
|
||||
|
||||
std::string private_description() const override
|
||||
{
|
||||
@@ -638,7 +647,7 @@ EXPORT_MCP_TOOL(ToolUpdateWall, UpdateAecWallTool)
|
||||
class ToolCreateSlab : public mcp_Tool
|
||||
{
|
||||
public:
|
||||
std::string private_name() const override { return "create_aec_slab"; }
|
||||
std::string private_name() const override { return "add_aec_slab"; }
|
||||
|
||||
std::string private_description() const override
|
||||
{
|
||||
@@ -736,7 +745,7 @@ EXPORT_MCP_TOOL(ToolUpdateSlab, UpdateAecSlabTool)
|
||||
class ToolCreateColumn : public mcp_Tool
|
||||
{
|
||||
public:
|
||||
std::string private_name() const override { return "create_aec_column"; }
|
||||
std::string private_name() const override { return "add_aec_column"; }
|
||||
|
||||
std::string private_description() const override
|
||||
{
|
||||
@@ -833,7 +842,7 @@ EXPORT_MCP_TOOL(ToolUpdateColumn, UpdateAecColumnTool)
|
||||
class ToolCreateBeam : public mcp_Tool
|
||||
{
|
||||
public:
|
||||
std::string private_name() const override { return "create_aec_beam"; }
|
||||
std::string private_name() const override { return "add_aec_beam"; }
|
||||
|
||||
std::string private_description() const override
|
||||
{
|
||||
|
||||
@@ -91,8 +91,9 @@ nlohmann::json paramsOf(AcDbEntity* pEnt, const std::string& sType)
|
||||
if (pX->GetAt(PIPE_SYS, s)) p["system"] = acharToUtf8(s);
|
||||
if (pX->GetAt(PIPE_MATERIAL, s)) p["material"] = acharToUtf8(s);
|
||||
|
||||
// 与入参统一用 color(ACI);老字段名 color_index 不再输出
|
||||
int nClr = 0;
|
||||
if (pX->GetAt(_T("COLOR"), nClr)) p["color_index"] = nClr;
|
||||
if (pX->GetAt(_T("COLOR"), nClr)) p["color"] = nClr;
|
||||
}
|
||||
}
|
||||
else if (sType == kTypeWall)
|
||||
@@ -188,7 +189,7 @@ nlohmann::json summaryOf(AcDbEntity* pEnt)
|
||||
class ToolListAecEntities : public mcp_Tool
|
||||
{
|
||||
public:
|
||||
std::string private_name() const override { return "list_aec_entities"; }
|
||||
std::string private_name() const override { return "query_aec_entities"; }
|
||||
|
||||
std::string private_description() const override
|
||||
{
|
||||
@@ -286,7 +287,7 @@ EXPORT_MCP_TOOL(ToolListAecEntities, ListAecEntitiesTool)
|
||||
class ToolGetAecEntity : public mcp_Tool
|
||||
{
|
||||
public:
|
||||
std::string private_name() const override { return "get_aec_entity"; }
|
||||
std::string private_name() const override { return "get_aec_entity_detail"; }
|
||||
|
||||
std::string private_description() const override
|
||||
{
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
{
|
||||
"_comment": [
|
||||
"cad_mcp_aec 的工具描述。合到部署目录的 cad-mcp-frame.json 的 tools 数组里即可用(append)。",
|
||||
"没有写 inputSchema:插件里的 mcp_Tool::private_input_schema() 已经带了完整 schema,",
|
||||
"配置里留空时框架会自动回落到它(见 inc/mcp_plugin_api.h 的 ToLLM())。",
|
||||
"dll_name 与 cad_mcp_frame.arx 同目录(plugin_directory = \".\")。"
|
||||
],
|
||||
"version": "1.0.0",
|
||||
"tools": [
|
||||
{
|
||||
"name": "list_aec_entities",
|
||||
"description": "列出当前图纸里本插件支持的 Envi3D 自定义实体(管道/墙/板/柱/梁),返回 handle、类型、图层、起终点、包围盒。改图之前先用它拿 handle。type 可选 all/pipe/wall/slab/column/beam,limit/offset 分页。",
|
||||
"backend": {
|
||||
"type": "c++_dll",
|
||||
"dll_name": "cad_mcp_aec.dll",
|
||||
"factory_function": "ListAecEntitiesTool"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "get_aec_entity",
|
||||
"description": "按 handle 取单个 Envi3D 实体的详细参数:类型、图层、起终点、包围盒,以及该类型的关键尺寸(管道 DN/外径/壁厚;墙 厚/高/底标高/对齐;板 厚/底标高;柱 高/截面/转角;梁 截面)。",
|
||||
"backend": {
|
||||
"type": "c++_dll",
|
||||
"dll_name": "cad_mcp_aec.dll",
|
||||
"factory_function": "GetAecEntityTool"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "create_aec_pipe",
|
||||
"description": "新建 Envi3D 管道(AecDbEwPipe):给起点、终点和公称直径,可选外径/壁厚/系统/材质/颜色/图层。坐标用图纸单位,dn_mm/od_mm/wall_thickness_mm 用毫米。返回新实体的 handle。",
|
||||
"backend": {
|
||||
"type": "c++_dll",
|
||||
"dll_name": "cad_mcp_aec.dll",
|
||||
"factory_function": "CreateAecPipeTool"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "update_aec_pipe",
|
||||
"description": "修改已有管道:只传要改的字段(起终点、DN、外径、壁厚、系统、材质、颜色),未传的保持原值。改 DN 会重建截面,改起终点会重算几何。",
|
||||
"backend": {
|
||||
"type": "c++_dll",
|
||||
"dll_name": "cad_mcp_aec.dll",
|
||||
"factory_function": "UpdateAecPipeTool"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "create_aec_wall",
|
||||
"description": "新建 Envi3D 墙体(AecDbXWall):沿 start→end 建墙,给墙厚、墙高、墙底标高,align 控制墙厚在基线哪一侧(left/center/right)。尺寸用图纸单位。返回 handle。",
|
||||
"backend": {
|
||||
"type": "c++_dll",
|
||||
"dll_name": "cad_mcp_aec.dll",
|
||||
"factory_function": "CreateAecWallTool"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "update_aec_wall",
|
||||
"description": "修改已有墙体:只传要改的字段(起终点、墙厚、墙高、底标高、对齐、材质)。",
|
||||
"backend": {
|
||||
"type": "c++_dll",
|
||||
"dll_name": "cad_mcp_aec.dll",
|
||||
"factory_function": "UpdateAecWallTool"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "create_aec_slab",
|
||||
"description": "新建 Envi3D 板/底板(AecDbXSlab):points 是水平轮廓点串 [[x,y],...](至少 3 点,可不闭合),给板厚与板底标高(图纸单位),center 可指定位置参考点。返回 handle。",
|
||||
"backend": {
|
||||
"type": "c++_dll",
|
||||
"dll_name": "cad_mcp_aec.dll",
|
||||
"factory_function": "CreateAecSlabTool"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "update_aec_slab",
|
||||
"description": "修改已有板:传 points 会重做轮廓,否则只改板厚/板底标高/材质。",
|
||||
"backend": {
|
||||
"type": "c++_dll",
|
||||
"dll_name": "cad_mcp_aec.dll",
|
||||
"factory_function": "UpdateAecSlabTool"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "create_aec_column",
|
||||
"description": "新建矩形柱(AecDbColumn):position 是柱底中心点,给柱高、截面长、截面宽,可选绕 Z 轴转角(度)。尺寸用图纸单位。返回 handle。",
|
||||
"backend": {
|
||||
"type": "c++_dll",
|
||||
"dll_name": "cad_mcp_aec.dll",
|
||||
"factory_function": "CreateAecColumnTool"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "update_aec_column",
|
||||
"description": "修改已有柱:只传要改的字段(位置、柱高、截面长宽、转角、材质)。",
|
||||
"backend": {
|
||||
"type": "c++_dll",
|
||||
"dll_name": "cad_mcp_aec.dll",
|
||||
"factory_function": "UpdateAecColumnTool"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "create_aec_beam",
|
||||
"description": "新建梁(AecDbBeam):沿 start→end 建梁,给截面宽与高(图纸单位)。返回 handle。",
|
||||
"backend": {
|
||||
"type": "c++_dll",
|
||||
"dll_name": "cad_mcp_aec.dll",
|
||||
"factory_function": "CreateAecBeamTool"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "update_aec_beam",
|
||||
"description": "修改已有梁:只传要改的字段(起终点、截面宽高、材质)。",
|
||||
"backend": {
|
||||
"type": "c++_dll",
|
||||
"dll_name": "cad_mcp_aec.dll",
|
||||
"factory_function": "UpdateAecBeamTool"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user