返回市场
ifc身份验证服务

ifc身份验证服务

作者:vinnividivicci14 星标更新:2025-11-15

项目介绍

IDS MCP Server

基于AI创建完全符合规范的buildingSMART IDS文件

这是一个MCP(模型上下文协议)服务器,它使AI代理能够确定性地创建、验证和管理完全符合buildingSMART IDS 1.0标准的信息交付规范(IDS)文件。

License: MIT Python 3.8+ Code style: black

功能

  • 100% IDS 1.0 兼容 - 所有导出内容均通过官方XSD模式验证
  • IfcTester 集成 - 使用官方IfcOpenShell库
  • 基于FastMCP上下文的会话 - 自动会话管理
  • 测试驱动开发 - 超过95%的代码覆盖率,全面测试
  • 确定性输出 - 相同输入始终产生相同输出
  • 类型安全 - 完整类型提示,使用Pydantic进行验证

快速开始

安装

# 克隆仓库
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配置文件中添加(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工具

文档管理

  • create_ids - 创建新的IDS文档
  • load_ids - 从文件或XML字符串加载现有的IDS
  • export_ids - 导出IDS到XML并进行验证
  • get_ids_info - 获取文档结构和元数据

规范管理

  • add_specification - 添加具有IFC版本和基数的规范

方面管理

基本方面

  • add_entity_facet - 添加IFC实体类型过滤器(例如,IFCWALL)
  • add_property_facet - 添加属性要求
  • add_attribute_facet - 添加IFC属性要求

高级方面

  • add_classification_facet - 添加分类要求
  • add_material_facet - 添加材料要求
  • add_partof_facet - 添加空间关系要求

限制管理

  • add_enumeration_restriction - 约束到有效值列表
  • add_pattern_restriction - 使用正则表达式模式约束
  • add_bounds_restriction - 约束数值范围
  • add_length_restriction - 约束字符串长度

验证

  • validate_ids - 根据XSD模式验证IDS文档
  • validate_ifc_model - 根据IDS验证IFC模型(额外功能)

早期验证与约束检查

MCP服务器包括早期验证,可以在调用工具时立即捕获IDS 1.0模式违规,而不是等到导出时间。这为AI代理提供了清晰且可操作的错误消息。

IDS 1.0 模式约束

1. 每个适用性的单一实体方面

约束: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")

2. 属性集对于属性方面的必需

约束: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 - 自定义/通用属性

早期验证的好处

  1. 即时反馈 - 在工具调用时捕获错误,而非导出时
  2. 清晰的错误消息 - 包括解决方法和示例
  3. 防止无效状态 - IDS文档在整个创建过程中保持有效
  4. 更好的AI代理体验 - 代理获得可操作指导

详见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

TDD工作流程(红绿重构)

  1. - 编写失败的测试
  2. 绿 - 实现最小代码以通过测试
  3. 重构 - 提升代码质量

示例:

# 红:编写失败的测试
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项不可谈判的原则:

  1. 100% IDS模式兼容 - 所有导出内容均通过XSD验证
  2. 测试驱动开发 - 95%以上覆盖率,先测试后编码
  3. 优先集成IfcTester - 不自定义XML生成
  4. 确定性生成 - 相同输入=相同输出
  5. 基于FastMCP上下文的会话 - 自动会话管理
  6. Python最佳实践 - 类型提示,PEP 8,现代Python

详见constitution.md了解详情。

文档

依赖项

核心

  • fastmcp - MCP服务器框架
  • ifctester - IDS创作和验证(来自IfcOpenShell)
  • pydantic - 数据验证

开发

  • pytest - 测试框架
  • pytest-asyncio - 异步测试支持
  • pytest-cov - 覆盖率报告
  • black - 代码格式化
  • ruff - 代码检查

参考资料

许可

MIT许可 - 详情见LICENSE文件

贡献

  1. 阅读constitution.md了解项目原则
  2. 遵循TDD方法论(红绿重构)
  3. 确保95%以上的测试覆盖率
  4. 所有导出必须通过IDS 1.0 XSD验证
  5. 使用IfcTester进行所有IDS操作

支持


状态:✅ 实现完成 | 94%测试覆盖率 | 17个MCP工具 | 168个测试 | 早期验证

使用IfcOpenShellFastMCP构建,充满爱心