leejunyoung5819 gitgit-mcp
공개gitgit.kr MCP 도구
| 1 | import { z } from "zod"; |
| 2 | import { repositoryPath } from "../client.ts"; |
| 3 | import { before, cursor, defined, limit, number, owner, repo, type Registrar } from "../tooling.ts"; |
| 4 | |
| 5 | const title = z.string().min(1).max(200); |
| 6 | const body = z.string().max(8000); |
| 7 | const comment = z.string().min(1).max(8000).describe("Markdown 본문"); |
| 8 | const issuePath = (o: string, r: string, n: number, suffix = "") => repositoryPath(o, r, `/issues/${n}${suffix}`); |
| 9 | |
| 10 | export function registerIssueTools(register: Registrar) { |
| 11 | register("list_issues", { |
| 12 | title: "Issue 목록", |
| 13 | description: "저장소의 Issue 를 번호 역순으로 봅니다. 다음 쪽은 응답의 nextCursor 를 before 에 넣어 받습니다.", |
| 14 | kind: "read", |
| 15 | input: { owner, repo, state: z.enum(["open", "closed", "all"]).default("open"), limit, before }, |
| 16 | run: ({ owner: o, repo: r, ...query }, { client }) => client.get(repositoryPath(o, r, "/issues"), query), |
| 17 | }); |
| 18 | |
| 19 | register("get_issue", { |
| 20 | title: "Issue 상세", |
| 21 | description: "Issue 의 제목, 본문, 상태, 담당자, Label 과 (기본으로) 첫 쪽 댓글을 함께 봅니다.", |
| 22 | kind: "read", |
| 23 | input: { |
| 24 | owner, repo, number, |
| 25 | includeComments: z.boolean().default(true).describe("댓글 첫 쪽을 함께 받을지"), |
| 26 | commentLimit: limit.describe("함께 받을 댓글 수 (1~100, 기본 30)"), |
| 27 | }, |
| 28 | run: async ({ owner: o, repo: r, number: n, includeComments, commentLimit }, { client }) => { |
| 29 | const detail = await client.get<Record<string, unknown>>(issuePath(o, r, n)); |
| 30 | if (!includeComments) return detail; |
| 31 | const comments = await client.get(issuePath(o, r, n, "/comments"), { limit: commentLimit }); |
| 32 | return { ...detail, comments }; |
| 33 | }, |
| 34 | }); |
| 35 | |
| 36 | register("list_issue_comments", { |
| 37 | title: "Issue 댓글 목록", |
| 38 | description: "Issue 댓글을 쪽 단위로 봅니다. 다음 쪽은 nextCursor 를 before 에 넣습니다.", |
| 39 | kind: "read", |
| 40 | input: { owner, repo, number, limit, before: z.string().max(8192).optional().describe("이전 응답의 nextCursor") }, |
| 41 | run: ({ owner: o, repo: r, number: n, ...page }, { client }) => client.get(issuePath(o, r, n, "/comments"), page), |
| 42 | }); |
| 43 | |
| 44 | register("list_labels", { |
| 45 | title: "Label 목록", |
| 46 | description: "저장소에 정의된 Label(id, 이름, 색)을 봅니다. update_issue 의 labelIds 에 이 id 를 씁니다.", |
| 47 | kind: "read", |
| 48 | input: { owner, repo, limit, cursor }, |
| 49 | run: ({ owner: o, repo: r, ...page }, { client }) => client.get(repositoryPath(o, r, "/labels"), page), |
| 50 | }); |
| 51 | |
| 52 | register("create_issue", { |
| 53 | title: "Issue 만들기", |
| 54 | description: "새 Issue 를 엽니다. issues:write 범위가 필요합니다.", |
| 55 | kind: "write", |
| 56 | input: { owner, repo, title, body: body.optional().describe("Markdown 본문") }, |
| 57 | run: ({ owner: o, repo: r, ...fields }, { client }) => |
| 58 | client.request("POST", repositoryPath(o, r, "/issues"), { body: defined(fields) }), |
| 59 | }); |
| 60 | |
| 61 | register("update_issue", { |
| 62 | title: "Issue 수정, 닫기, 다시 열기", |
| 63 | description: "Issue 의 제목, 본문, 상태(open/closed), 담당자, Label 을 바꿉니다. 준 필드만 바뀝니다. labelIds 는 전체 목록으로 교체됩니다. 담당자를 빼려면 assignee 에 null 을 주세요.", |
| 64 | kind: "write", |
| 65 | idempotent: true, |
| 66 | input: { |
| 67 | owner, repo, number, |
| 68 | title: title.optional(), |
| 69 | body: body.optional(), |
| 70 | state: z.enum(["open", "closed"]).optional(), |
| 71 | assignee: z.string().min(1).max(100).nullable().optional().describe("담당자 사용자명. null 이면 해제"), |
| 72 | labelIds: z.array(z.uuid()).max(100).optional().describe("붙일 Label id 전체 목록 (list_labels 참고)"), |
| 73 | }, |
| 74 | run: ({ owner: o, repo: r, number: n, ...fields }, { client }) => |
| 75 | client.request("PATCH", issuePath(o, r, n), { body: defined(fields) }), |
| 76 | }); |
| 77 | |
| 78 | register("create_issue_comment", { |
| 79 | title: "Issue 댓글 달기", |
| 80 | description: "Issue 에 댓글을 남깁니다. issues:write 범위가 필요합니다.", |
| 81 | kind: "write", |
| 82 | input: { owner, repo, number, body: comment }, |
| 83 | run: ({ owner: o, repo: r, number: n, body: text }, { client }) => |
| 84 | client.request("POST", issuePath(o, r, n, "/comments"), { body: { body: text } }), |
| 85 | }); |
| 86 | } |