> ## Documentation Index
> Fetch the complete documentation index at: https://link.datarelay.run/llms.txt
> Use this file to discover all available pages before exploring further.

# 실습: AI Server 파일·Git·작업 제어

> Claude·ChatGPT로 파일 왕복·Git·stdin·출력 조회·중지 따라 하기.

# Claude·ChatGPT로 Server 파일·Git·비동기 작업 실행

**결과:** 전용 실습 디렉터리에서 파일 생성/읽기/삭제, 로컬 Git commit, stdin/EOF·출력·중지를 수행합니다. [MCP 연결](https://link.datarelay.run/ko/guides/mcp-clients.md)을 먼저 완료하세요. 이 실습은 **server:self**의 Server 관리 권한을 사용하며 일반 Agent 대상 작업과 구분됩니다.

## 1단계 — 제품 상태와 MCP 연결 확인

[서버 설치](https://link.datarelay.run/ko/getting-started/server-installation.md)와 [Claude·ChatGPT 연결](https://link.datarelay.run/ko/guides/mcp-clients.md)을 완료한 Server에서 시작합니다. Server 셸에서 다음 명령으로 현재 상태를 확인하세요.

```bash theme={null}
sudo drlink system status
sudo drlink system diagnostics mcp
sudo drlink show ai-identities
```

Claude 또는 ChatGPT에서 DataRelay Link를 선택하고 다음을 요청합니다.

```text theme={null}
DataRelay Link의 get_server로 연결된 Server를 확인해줘.
파일이나 설정은 바꾸지 말고 Server 이름과 접근 가능 여부만 알려줘.
```

이후 파일·Git·작업 실행은 제품에 설정된 OS 계정으로 수행됩니다. 예시 작업 디렉터리는 /tmp/drlink-mcp-tutorial입니다. 제품에 승인된 작업 경로가 따로 있다면 예제와 Rule의 경로를 함께 바꾸세요. command-exec는 해당 OS 계정의 명령 실행 권한이며 작업 디렉터리 밖 접근을 막는 샌드박스가 아닙니다.

## 2단계 — 별도 identity와 Rule을 검증

이미 OAuth로 연결한 전용 identity **mcp-lab**을 사용한다고 가정합니다. 실제 클라이언트 identity로 바꾸세요. **Server REPL**:

```text theme={null}
set permission-object mcp-lab-ops permissions host-info,process-read,file-read,file-write,command-exec
set ai-access mcp-lab-server mode whitelist source mcp-lab destination server:self permission mcp-lab-ops paths '/tmp/drlink-mcp-tutorial/**',/tmp enabled
set ai-access enabled
test ai-access source mcp-lab destination server:self permission command-exec path /tmp
test ai-access source mcp-lab destination server:self permission file-read path /tmp/drlink-mcp-tutorial/note.txt
test ai-access source mcp-lab destination server:self permission file-read path /etc/shadow
show ai-access
```

예상: 첫 두 정책 테스트 ALLOW, 마지막은 다른 Rule이 권한을 넓히지 않는 한 DENY. 파일이 실제 존재하는지는 별도입니다. 업로드/다운로드가 필요하면 file-upload/file-download를 추가 검토합니다. 그룹 전체에 grant하지 말고 실제 대상과 경로를 확인하세요.

## 3단계 — 파일 왕복 실습

Server에서 아직 사용하지 않는 실습 디렉터리인지 먼저 확인하세요. 아래는 일반 제품 MCP 도구 호출입니다. 다른 작업이 쓰는 디렉터리라면 고유한 이름으로 바꾸고 Rule의 경로도 함께 변경합니다.

```json theme={null}
{"tool":"server_exec","arguments":{"cwd":"/tmp","command":"mkdir -p /tmp/drlink-mcp-tutorial"}}
```

아래 JSON은 MCP 도구 **이름과 인자**이며 셸에 붙이는 명령이 아닙니다. Claude 또는 ChatGPT에 이 도구 호출을 요청합니다. 파일이 이미 있다면 다른 고유 이름을 사용하세요.

```text theme={null}
DRLink MCP의 get_server로 대상 Server를 먼저 확인해줘.
실습 디렉터리 /tmp/drlink-mcp-tutorial에 note.txt가 없는지 확인하고,
새 파일에 DRLink MCP tutorial을 저장한 뒤 읽어서 동일한지 확인해줘.
다른 파일은 바꾸지 마.
```

```json theme={null}
{"tool":"server_write_file","arguments":{"path":"/tmp/drlink-mcp-tutorial/note.txt","content":"DRLink MCP tutorial"}}
{"tool":"server_read_file","arguments":{"path":"/tmp/drlink-mcp-tutorial/note.txt"}}
```

결과가 base64를 포함하면 반환 스키마에 따라 디코딩하고 원문과 비교합니다. 실패한 도구 호출을 성공한 파일 작업으로 기록하지 마세요.

## 4단계 — 로컬 Git 예제

3단계에서 만든 note.txt만 있는 전용 디렉터리이며 **기존 Git 저장소가 아닌지** 확인합니다. 아래 init은 그 공간에만 실행하고 note.txt만 추가합니다. 실제 저장소·글로벌 Git 설정을 바꾸지 않습니다.

```json theme={null}
{"tool":"server_git","arguments":{"cwd":"/tmp/drlink-mcp-tutorial","argv":["git","init"]}}
{"tool":"server_git","arguments":{"cwd":"/tmp/drlink-mcp-tutorial","argv":["git","add","note.txt"]}}
{"tool":"server_git","arguments":{"cwd":"/tmp/drlink-mcp-tutorial","argv":["git","-c","user.name=DRLink Lab","-c","user.email=lab@example.net","commit","-m","Add MCP tutorial note"]}}
{"tool":"server_git","arguments":{"cwd":"/tmp/drlink-mcp-tutorial","argv":["git","log","-1","--oneline"]}}
```

각 작업의 완료 state와 exit\_status=0, 마지막 commit을 확인합니다. 원격 push는 실제 remote·네트워크·그 OS 계정의 Git 인증 및 사용자 승인이 추가로 필요합니다. MCP OAuth는 GitHub 자격 증명이 아닙니다. push 전에는 사용할 remote와 해당 저장소의 접근 권한을 확인하세요.

## 5단계 — 비동기 stdin·EOF와 커서 출력

```json theme={null}
{"tool":"server_run","arguments":{"cwd":"/tmp/drlink-mcp-tutorial","argv":["python3","-u","-c","import sys; print('READY', flush=True); line=sys.stdin.readline(); print('ECHO:'+line.strip(), flush=True)"],"timeout_seconds":60,"wait_ms":1000}}
```

**running**, READY와 **job\_id**를 확인하고 60초 안에 다음 호출을 합니다. 실제 반환 job\_id로 바꾸세요. READY를 받았을 때 반환된 stdout.next\_cursor를 다음 poll에 사용합니다(예제에서는 6). 시스템이 Python을 다른 경로로 설치했다면 해당 argv를 사용합니다.

```json theme={null}
{"tool":"server_job_input","arguments":{"job_id":"<returned-job-id>","data":"DRLink documentation sample\n","eof":true}}
{"tool":"server_job_poll","arguments":{"job_id":"<returned-job-id>","stdout_cursor":6,"stderr_cursor":0,"wait_ms":1000}}
```

예상: accepted\_bytes=28, input\_closed=true, ECHO:DRLink documentation sample, 최종 exit\_status=0. 아직 running이면 새 next\_cursor로 이어 읽습니다. 타임아웃이면 빠르게 새 전용 작업을 만들어 재시도하고 기존 작업의 실패 기록을 보존하세요.

## 6단계 — 본인이 만든 작업 중지·정리

```json theme={null}
{"tool":"server_exec","arguments":{"cwd":"/tmp/drlink-mcp-tutorial","command":"sleep 30","timeout_seconds":45,"wait_ms":0}}
{"tool":"server_job_stop","arguments":{"job_id":"<sleep-job-id>"}}
{"tool":"server_delete_file","arguments":{"path":"/tmp/drlink-mcp-tutorial/note.txt"}}
```

중지 후 completed와 종료 신호에 따른 음수 exit\_status가 나올 수 있습니다. exit 0 정상 완료와 구분하세요. **이 실습에서 반환된 job\_id만** 중지합니다. 실습 저장소 .git 정리는 소유 운영자가 경로를 확인한 뒤 처리하며 다른 저장소는 지우지 않습니다.

Server REPL의 `show ai-access-log identity mcp-lab`로 작업을 확인합니다. 끝난 뒤 Rule을 유지할 필요가 없으면 `unset ai-access mcp-lab-server`의 영향도를 검토하고 삭제합니다. 다른 사용자가 쓰는 전체 AI Access나 인증서를 초기화하지 마세요.

이 실습은 Server 자체를 대상으로 하므로 Agent 등록이나 SSH/RDP Remote Service가 필요하지 않습니다.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.