프로젝트명: Minecraft MCP Client 목표: Fabric 1.21.4 기반 클라이언트 모드로 MCP 서버를 구현하여 LLM이 마인크래프트 명령어를 실행할 수 있도록 함 버전: Fabric 0.16.14, Minecraft 1.21.4
[Claude/LLM] ←HTTP/JSON→ [MCP Server] ←→ [Fabric Mod] ←→ [Minecraft Client]
↑ ↑ ↑
HTTP 8080 Mod Events Game World
- MCP HTTP Server: HTTP 서버로 LLM과 통신
- Command Executor: 마인크래프트 명령어 실행 엔진
- Safety Manager: 안전성 검증 시스템
- Response Handler: 실행 결과 피드백 시스템
- Java: OpenJDK 21+
- Fabric: 0.16.14
- Minecraft: 1.21.4
- Fabric API: 0.110.5+1.21.4
- HTTP Server: Java NIO (내장)
- JSON 처리: Gson (Minecraft 내장)
- 비동기 처리: CompletableFuture
- 로깅: SLF4J (Fabric 제공)
minecraft-mcp-client/
├── src/main/java/com/mcpmods/client/
│ ├── MinecraftMCPClient.java # 메인 모드 클래스
│ ├── server/
│ │ ├── MCPServer.java # HTTP MCP 서버
│ │ ├── MCPRequestHandler.java # MCP 요청 처리
│ │ └── MCPProtocol.java # MCP 프로토콜 구현
│ ├── command/
│ │ ├── CommandExecutor.java # 명령어 실행기
│ │ ├── SafetyValidator.java # 안전성 검증
│ │ └── CommandResult.java # 실행 결과 모델
│ ├── utils/
│ │ ├── CoordinateUtils.java # 좌표 유틸리티
│ │ └── CommandParser.java # 명령어 파싱
│ └── config/
│ └── MCPConfig.java # 설정 관리
├── src/main/resources/
│ ├── fabric.mod.json # 모드 메타데이터
│ └── mcp_client.mixins.json # Mixin 설정
└── build.gradle # 빌드 설정
초기화
initialize- MCP 세션 초기화ping- 연결 상태 확인
도구 관리
tools/list- 사용 가능한 도구 목록 반환tools/call- 도구 실행
서버 정보
server/info- 서버 메타데이터 반환
Tool 스펙:
{
"name": "execute_commands",
"description": "Execute one or more Minecraft commands sequentially",
"inputSchema": {
"type": "object",
"properties": {
"commands": {
"type": "array",
"items": {
"type": "string"
},
"description": "Array of Minecraft commands to execute (without leading slash)",
"minItems": 1
},
"validate_safety": {
"type": "boolean",
"description": "Whether to validate command safety (default: true)",
"default": true
}
},
"required": ["commands"]
}
}사용 예시:
{
"method": "tools/call",
"params": {
"name": "execute_commands",
"arguments": {
"commands": [
"fill ~ ~ ~ ~10 ~5 ~8 oak_planks",
"setblock ~5 ~6 ~4 oak_door",
"summon villager ~5 ~1 ~4"
],
"validate_safety": true
}
}
}{
"isError": false,
"content": [
{
"type": "text",
"text": "{\"totalCommands\":2,\"acceptedCount\":2,\"appliedCount\":1,\"failedCount\":1,\"results\":[{\"index\":0,\"command\":\"fill 0 64 0 1 64 1 stone\",\"status\":\"applied\",\"accepted\":true,\"applied\":true,\"summary\":\"Successfully filled 4 block(s)\",\"chatMessages\":[\"Successfully filled 4 block(s)\"]},{\"index\":1,\"command\":\"enchant @s minecraft:unbreaking 1\",\"status\":\"rejected_by_game\",\"accepted\":true,\"applied\":false,\"summary\":\"Carrot cannot support that enchantment\",\"chatMessages\":[\"Carrot cannot support that enchantment\"]}],\"chatMessages\":[\"Successfully filled 4 block(s)\",\"Carrot cannot support that enchantment\"]}"
}
]
}{
"isError": true,
"content": [
{
"type": "text",
"text": "Command execution failed at command 2: Invalid block type 'invalid_block' in command 'setblock ~ ~ ~ invalid_block'"
}
],
"_meta": {
"failed_command_index": 1,
"failed_command": "setblock ~ ~ ~ invalid_block",
"total_commands": 3,
"executed_commands": 1
}
}{
"isError": true,
"content": [
{
"type": "text",
"text": "Command rejected by safety validator at command 3: Potentially destructive pattern detected in 'kill @a'"
}
],
"_meta": {
"failed_command_index": 2,
"failed_command": "kill @a",
"total_commands": 5,
"executed_commands": 0
}
}fill- 블록 채우기clone- 구조물 복사setblock- 단일 블록 설정summon- 엔티티 소환tp/teleport- 텔레포트give- 아이템 지급gamemode- 게임모드 변경effect- 효과 부여enchant- 인챈트 부여weather- 날씨 변경time- 시간 설정say/tell/title- 메시지 출력
/kill @a또는/kill @e- 대량 엔티티 제거- 50x50x50 블록을 초과하는
fill영역 {Count:100}이상의 대량 아이템/엔티티 생성@a를 대상으로 하는gamemode creative명령
- 클라이언트 명령어: 클라이언트에서 직접 실행 (
/gamemode,/effect @s등) - 서버 명령어: 서버로 패킷 전송하여 실행 (
/fill,/clone등) - 채팅 명령어: 채팅으로 전송하여 실행 (일반적인 방식)
- 명령어 실행 성공/실패 여부
- 영향받은 블록 수 (해당하는 경우)
- 생성/제거된 엔티티 수 (해당하는 경우)
- 게임에서 출력된 피드백 메시지
- 실행 시간 (성능 모니터링용)
- 모든 명령어 실행은 비동기로 처리
- 메인 스레드 블로킹 방지
- 긴 작업의 경우 진행 상황 피드백
- 포트: 8080 (설정 가능)
- 프로토콜: HTTP/1.1
- Content-Type: application/json
- 인코딩: UTF-8
POST /mcp/initialize
- MCP 세션 초기화
- 서버 정보 및 capabilities 반환
POST /mcp/ping
- 연결 상태 확인
- 빠른 응답으로 연결 유지
POST /mcp/tools/list
- 사용 가능한 도구 목록 반환
- execute_commands 도구 정보 포함
POST /mcp/tools/call
- 도구 실행 요청 처리
- 명령어 검증 및 실행
Content-Type: application/json
Accept: application/json
User-Agent: MCP-Client/1.0
{
"server": {
"port": 8080,
"host": "localhost",
"enable_safety": true,
"max_area_size": 50,
"allowed_commands": ["fill", "clone", "setblock", "summon", "tp", "give"],
"request_timeout_ms": 30000
},
"client": {
"auto_start": true,
"show_notifications": true,
"log_level": "INFO",
"log_commands": false
},
"safety": {
"max_entities_per_command": 10,
"max_blocks_per_command": 125000,
"block_creative_for_all": true,
"require_op_for_admin_commands": true
}
}