CAD生成与验证工具

一个提供CAD生成和验证工具的模型上下文协议(MCP)服务器,支持通过MCP工具进行对话式3D建模。

  • by rishigundakaram
  • Python
  • 本地部署
  • 20 星标
  • 更新于
在 GitHub 查看 rishigundakaram/cadquery-mcp-server

使用说明

CAD查询MCP服务器

一种模型上下文协议(MCP)服务器,为克劳德代码提供CAD生成和验证工具。该服务器通过MCP工具公开CAD查询功能,实现对话式3D建模。

特性

  • verify_cad_query -根据条件验证CAD查询生成的模型
  • generate_cad_query - (Stub实施) 根据描述生成CAD查询Python脚本
  • CAD查询集成 -参数化三维建模的完整CAD查询支持
  • STL/STEP导出 -直接导出为3D打印和CAD格式
  • 视觉反馈 -用于模型检查的SVG生成

安装

# Install dependencies
uv sync

# For development with CAD verification capabilities
uv sync --extra cad

# Test the server
uv run python tests/test_server.py

# Run with MCP Inspector (interactive testing)
uv run mcp dev server.py

Claude桌面配置

将此添加到您的Claude Desktop配置文件中:

macOS

地点: ~/Library/Application Support/Claude/claude_desktop_config.json

视窗

地点: %APPDATA%/Claude/claude_desktop_config.json

配置

{
  "mcpServers": {
    "cadquery-server": {
      "command": "python",
      "args": ["/path/to/cadquery-mcp-server/server.py"],
      "env": {}
    }
  }
}

MCP工具

verify_cad_query

根据指定条件验证CAD查询生成的模型。

参数:

  • file_path (string):CAD查询Python文件的路径
  • verification_criteria (string):验证内容的描述

例子:

{
  "file_path": "models/coffee_mug.py",
  "verification_criteria": "coffee mug with handle, 10cm height, 8cm diameter"
}

退货:

{
  "status": "PASS" | "FAIL",
  "message": "Description of result",
  "file_path": "Path to verified file",
  "criteria": "Verification criteria used",
  "details": "Additional verification details"
}

generate_cad_query (Stub实施)

从自然语言描述生成CAD查询Python脚本。

备注:当前返回一个存根响应,表示该功能尚未实现。

参数:

  • description (string):所需3D模型的自然语言描述
  • parameters (字符串,可选):特定尺寸或约束

例子:

{
  "description": "Create a coffee mug with a handle, 10cm tall and 8cm diameter",
  "parameters": "height=100mm, diameter=80mm, handle_width=15mm"
}

退货:

{
  "status": "NOT_IMPLEMENTED",
  "message": "CAD code generation is not yet implemented",
  "description": "Input description",
  "parameters": "Input parameters",
  "details": "Additional information"
}

CAD查询脚本要求

所有CAD查询脚本必须以结尾 show_object(result):

import cadquery as cq
result = cq.Workplane("XY").box(10, 10, 10)
show_object(result)  # Required for processing

发展

测试

# Test server functionality
uv run python tests/test_server.py

# Interactive testing with MCP Inspector
uv run mcp dev server.py

# Run evaluations
uv run python evaluations/evaluate_verify.py

扩展服务器

电流 verify_cad_query 实现是一个基本的验证器。您可以将其增强为:

  • 解析和验证CAD查询语法
  • 执行模型生成并捕获错误
  • 分析生成的几何尺寸
  • 检查特定功能和约束
  • 生成详细的验证报告

开发工具

# formatting
uvx rff format

# running the MCP server
npx @modelcontextprotocol/inspector \
  uv \
  --directory $(pwd) \
  run \
  server.py