Skip to main content
Glama
agtmwebtoon

autocad-mcp

by agtmwebtoon
README.md
# autocad-mcp

AutoCAD / AutoCAD LT 자동화를 위한 MCP 서버.

Claude 같은 LLM이 자연어로 AutoCAD 도면을 생성·편집할 수 있도록 MCP 프로토콜로 연결합니다.

## 특징

- **AutoCAD LT 지원** — COM/ActiveX 없이 LISP + 파일 IPC 방식으로 LT에서도 동작
- **헤드리스 모드** — ezdxf 백엔드로 AutoCAD 없이 DXF 파일 직접 생성
- **Validation Layer** — 도면 실행 전 기하·의존성·간섭 검증 (AssemblyValidator로 shape 간 충돌 사전 차단)
- **P&ID 지원** — 공정 배관 계장도 심볼·라인 삽입

## 아키텍처

```
LLM (Claude)
    │  MCP tool call
    ▼
MCP Server (server.py)          ← 8개 툴 + validate
    │
    ├─ Validation Layer          ← 실행 전 검증 (geometry / dependency / assembly)
    │
    ├─ File IPC Backend          ← AutoCAD LT: JSON 파일 → LISP dispatch → 결과 파일
    └─ ezdxf Backend             ← 헤드리스: Python에서 DXF 직접 생성
```

## MCP 툴 목록

| 툴 | 설명 |
|---|---|
| `drawing` | 파일 생성·열기·저장·PDF 출력 |
| `layer` | 레이어 생성·속성·잠금·동결 |
| `entity` | 도형 생성 (선·원·호·사각형·폴리라인 등) 및 수정 |
| `block` | 블록 삽입·속성 조회·수정 |
| `annotation` | 치수·지시선 |
| `pid` | P&ID 심볼·배관 라인 |
| `view` | 줌·화면 제어 |
| `system` | 핑·백엔드 전환·스크린샷 |
| `validate` | 실행 전 Validation (geometry / dependency / assembly) — **개발 중** |

## 설치

```bash
# 의존성 설치
uv sync

# AutoCAD LT 연결 시 LISP 로드 (AutoCAD 명령창에서)
(load "C:/path/to/lisp-code/mcp_dispatch.lsp")
```

## 실행

```bash
# MCP 서버 시작
uv run python -m autocad_mcp

# 백엔드 선택 (환경변수)
AUTOCAD_MCP_BACKEND=ezdxf   uv run python -m autocad_mcp  # 헤드리스
AUTOCAD_MCP_BACKEND=file_ipc uv run python -m autocad_mcp  # AutoCAD LT
```

## Claude Desktop 연결

`claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "autocad-mcp": {
      "command": "...python.exe",
      "args": ["-m", "autocad_mcp"],
      "env": {
        "AUTOCAD_MCP_BACKEND": "file_ipc"
      }
    }
  }
}
```

## AutoCAD LT IPC 동작 방식

AutoCAD LT는 COM 자동화를 지원하지 않으므로 파일 기반 IPC를 사용합니다.

```
Python → C:/temp/autocad_mcp_cmd_{id}.json 작성
       → "(c:mcp-dispatch)" 입력 전송
       → AutoCAD LISP이 명령 실행
       → C:/temp/autocad_mcp_result_{id}.json 작성
       → Python이 결과 파일 폴링
```

## Validation Layer

> **현재 개발 중입니다.** API와 동작 방식은 변경될 수 있습니다.

```
validate(operation="pipeline", data={"intents": [...]})
    │
    ├─ Phase 1: shape별 개별 검증
    │   ├─ GeometryValidator  — 치수 범위, 최소 반지름
    │   └─ DependencyValidator — layer → entity 순서 (DFA)
    │
    └─ Phase 2: 전체 교차 간섭 검증
        └─ AssemblyValidator  — shape 간 겹침·여유 거리
```

## 테스트

```bash
uv run pytest
```

TDQS

A3.6/5.0

Scored across 9 tools

Disambiguation4/5

The top-level tools (layer, drawing, entity, block, annotation, pid, view, system, validate) are clearly distinct by domain. However, there is some overlap between entity.create_mtext and annotation.create_text, and between block.insert and pid.insert_symbol, but these are minor and descriptions clarify the context.

Naming Consistency3/5

The tool names are single nouns, while operations inside them use a mix of simple verbs (list, create) and compound verbs with underscores (save_as_dxf, get_variables, insert_with_attributes). Naming is not consistently verb_noun across all tools, and read operations use inconsistent verbs (list, get, info).

Tool Count5/5

The server has 9 top-level tools, well within the ideal 3-15 range. Each tool represents a clear domain, and the number of tools is proportionate to the wide scope of AutoCAD functionality covered.

Completeness4/5

The tool surface is extensive, covering drawing file management, layers, entity CRUD, blocks, annotations, P&ID, view control, and system operations. Minor gaps exist, such as no direct editing of annotations or renaming layers, but these can be worked around with existing tools.

Maintenance

ActivityInactive
ResponsivenessNo issues