leejunyoung5819 gitgit-mcp
공개gitgit.kr MCP 도구
| 1 | #!/usr/bin/env node |
| 2 | // GitGit MCP 서버 (stdio). Codex, Claude 데스크탑 앱, Claude Code 가 하위 프로세스로 실행함 |
| 3 | // stdout 은 MCP 메시지 전용이므로 로그는 모두 stderr 로 씀 |
| 4 | import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; |
| 5 | import { loadConfig, version } from "./config.ts"; |
| 6 | import { createServer } from "./server.ts"; |
| 7 | |
| 8 | const args = process.argv.slice(2); |
| 9 | if (args.includes("--version") || args.includes("-v")) { |
| 10 | process.stdout.write(`gitgit-mcp ${version}\n`); |
| 11 | process.exit(0); |
| 12 | } |
| 13 | if (args.includes("--help") || args.includes("-h")) { |
| 14 | process.stdout.write(`gitgit-mcp ${version} — GitGit REST API 용 MCP 서버 (stdio) |
| 15 | |
| 16 | 환경 변수 |
| 17 | GITGIT_API_URL API 서버 주소 (기본 https://api.gitgit.kr, 개발: http://localhost:8080) |
| 18 | GITGIT_TOKEN ggp_ 또는 ggb_ 로 시작하는 액세스 토큰 (없으면 공개 저장소 읽기만) |
| 19 | GITGIT_TOKEN_FILE 토큰을 담은 파일 경로 (GITGIT_TOKEN 대신) |
| 20 | GITGIT_READ_ONLY 1 이면 읽기 도구만 등록 |
| 21 | GITGIT_TIMEOUT_MS API 요청 제한 시간 (기본 30000) |
| 22 | GITGIT_UPLOAD_TIMEOUT_MS Asset 업로드 제한 시간 (기본 600000) |
| 23 | GITGIT_MAX_OUTPUT_CHARS 도구 응답 최대 글자 수 (기본 100000) |
| 24 | `); |
| 25 | process.exit(0); |
| 26 | } |
| 27 | |
| 28 | let config; |
| 29 | try { |
| 30 | config = loadConfig(); |
| 31 | } catch (error) { |
| 32 | process.stderr.write(`[gitgit-mcp] 설정 오류: ${error instanceof Error ? error.message : String(error)}\n`); |
| 33 | process.exit(1); |
| 34 | } |
| 35 | |
| 36 | const { server, skipped } = createServer(config); |
| 37 | await server.connect(new StdioServerTransport()); |
| 38 | process.stderr.write(`[gitgit-mcp] ${version} 시작: ${config.apiBase} (${config.token ? "토큰 인증" : "익명"}` + |
| 39 | `${config.readOnly ? `, 읽기 전용: 쓰기 도구 ${skipped.length}개 제외` : ""})\n`); |
| 40 | for (const warning of config.warnings) process.stderr.write(`[gitgit-mcp] 경고: ${warning}\n`); |
| 41 | |
| 42 | const shutdown = () => { |
| 43 | void server.close().finally(() => process.exit(0)); |
| 44 | }; |
| 45 | process.on("SIGINT", shutdown); |
| 46 | process.on("SIGTERM", shutdown); |