基于AI创建完全符合规范的buildingSMART IDS文件
这是一个MCP(模型上下文协议)服务器,它使AI代理能够确定性地创建、验证和管理完全符合buildingSMART IDS 1.0标准的信息交付规范(IDS)文件。
# 克隆仓库
git clone https://github.com/Quasar-Consulting-Group/ifc-ids-mcp.git
cd ifc-ids-mcp
# 安装依赖
pip install -r requirements.txt
# 开发模式安装
pip install -e .
在你的Claude Desktop配置文件中添加(claude_desktop_config.json):
{
"mcpServers": {
"ids-mcp": {
"command": "python",
"args": ["-m", "ids_mcp_server"],
"env": {
"IDS_LOG_LEVEL": "INFO"
}
}
}
}
from ifctester import ids
# MCP服务器自动处理此操作
# 但你也可以直接使用IfcTester:
# 创建新的IDS
my_ids = ids.Ids(title="项目要求")
# 添加规范
spec = ids.Specification(name="墙体要求", ifcVersion=["IFC4"])
spec.applicability.append(ids.Entity(name="IFCWALL"))
requirement = ids.Property(
baseName="防火等级",
propertySet="Pset_WallCommon",
cardinality="required"
)
spec.requirements.append(requirement)
my_ids.specifications.append(spec)
# 导出到XML
my_ids.to_xml("requirements.ids")
MCP服务器包括早期验证,可以在调用工具时立即捕获IDS 1.0模式违规,而不是等到导出时间。这为AI代理提供了清晰且可操作的错误消息。
约束:IDS 1.0允许每个规范的适用性部分只有一个实体方面。
早期验证:add_entity_facet工具在添加方面之前验证此约束:
# ✅ 正确:第一个实体方面
add_entity_facet(spec_id="S1", location="applicability", entity_name="IFCWALL")
# ❌ 错误:第二个实体方面立即引发ToolError
add_entity_facet(spec_id="S1", location="applicability", entity_name="IFCDOOR")
# 错误:"IDS 1.0 XSD约束违反:仅允许一个实体方面..."
# 工作绕道:为每种实体类型创建单独的规范:
# 规范1:墙体
add_specification(name="墙体要求", ifc_versions=["IFC4"], identifier="S1")
add_entity_facet(spec_id="S1", location="applicability", entity_name="IFCWALL")
# 规范2:门
add_specification(name="门要求", ifc_versions=["IFC4"], identifier="S2")
add_entity_facet(spec_id="S2", location="applicability", entity_name="IFCDOOR")
约束:IfcTester需要property_set参数以进行有效的IDS导出。
早期验证:add_property_facet工具在添加方面之前验证此需求:
# ❌ 错误:缺少property_set立即引发ToolError
add_property_facet(
spec_id="S1",
location="requirements",
property_name="防火等级"
)
# 错误:"属性方面验证错误:需要'property_set'参数..."
# ✅ 正确:包含property_set参数
add_property_facet(
spec_id="S1",
location="requirements",
property_name="防火等级",
property_set="Pset_WallCommon"
)
常见属性集:
Pset_WallCommon - 墙体属性Pset_DoorCommon - 门属性Pset_WindowCommon - 窗户属性Pset_SpaceCommon - 空间属性Pset_Common - 自定义/通用属性详见CLAUDE.md关于IDS 1.0约束的详细文档。
┌─────────────────────────────────────────────┐
│ AI代理(Claude,GPT) │
└────────────────────┬────────────────────────┘
│ MCP协议
┌────────────────────▼────────────────────────┐
│ FastMCP服务器 │
│ ┌──────────────────────────────────────┐ │
│ │ MCP工具(超过15个工具) │ │
│ └───────────────┬──────────────────────┘ │
│ ┌───────────────▼──────────────────────┐ │
│ │ 会话管理器(上下文) │ │
│ └───────────────┬──────────────────────┘ │
│ ┌───────────────▼──────────────────────┐ │
│ │ IfcTester集成(IDS引擎) │ │
│ └──────────────────────────────────────┘ │
└─────────────────────────────────────────────┘
│
▼
IDS XML文件(100% XSD兼容)
该项目严格遵循TDD方法论:
# 运行所有测试
pytest tests/ -v
# 运行带有覆盖率报告
pytest tests/ --cov=src/ids_mcp_server --cov-report=html
# 运行特定测试类别
pytest tests/unit/ -v # 单元测试
pytest tests/integration/ -v # 集成测试
pytest tests/validation/ -v # XSD验证测试
# 必须维持95%以上的覆盖率
pytest tests/ --cov-fail-under=95
示例:
# 红:编写失败的测试
def test_create_specification():
result = add_specification(name="测试", ifc_versions=["IFC4"])
assert result["status"] == "success"
# 绿:实现
def add_specification(name, ifc_versions):
return {"status": "success"}
# 重构:改进(保持测试通过)
# 格式化代码
black src/ tests/
# 代码检查
ruff check src/ tests/
# 类型检查(可选)
mypy src/
ifc-ids-mcp/
├── src/
│ └── ids_mcp_server/
│ ├── __init__.py
│ ├── __main__.py
│ ├── server.py # FastMCP服务器
│ ├── config.py # 配置
│ ├── version.py # 版本管理
│ ├── session/ # 会话管理
│ │ ├── manager.py
│ │ ├── storage.py
│ │ ├── cleanup.py
│ │ └── models.py # 会话数据模型
│ └── tools/ # MCP工具(总计17个)
│ ├── document.py
│ ├── specification.py
│ ├── facets.py
│ ├── restrictions.py # 阶段007
│ ├── validation.py # 阶段0-8
│ └── validators.py # 早期验证助手
├── tests/ # 168个测试,94%覆盖率
│ ├── unit/ # 单元测试
│ ├── component/ # 组件测试
│ ├── integration/ # 集成测试
│ └── validation/ # XSD合规性测试
│ └── fixtures/ # 测试夹具
├── samples/ # 示例IDS/IFC文件
│ ├── wall_fire_rating.ids
│ └── walls-fire-rating.ifc
├── specs/ # 实施计划(PRD)
├── .mcp.json # MCP服务器配置
├── .coveragerc # 覆盖率配置
├── constitution.md # 项目原则
├── DESIGN_SPECIFICATION.md # 技术规范
├── CLAUDE.md # AI代理指南
├── pyproject.toml
├── pytest.ini
└── README.md
该项目遵循6项不可谈判的原则:
详见constitution.md了解详情。
MIT许可 - 详情见LICENSE文件
状态:✅ 实现完成 | 94%测试覆盖率 | 17个MCP工具 | 168个测试 | 早期验证
使用IfcOpenShell和FastMCP构建,充满爱心