새로운 createNote 함수 추가: 이슈 또는 병합 요청에 노트(댓글)를 추가하는 기능 구현 및 관련 스키마 정의
버전 1.0.4로 업데이트
This commit is contained in:
@ -5,7 +5,7 @@ import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextpro
|
||||
import fetch from "node-fetch";
|
||||
import { z } from "zod";
|
||||
import { zodToJsonSchema } from "zod-to-json-schema";
|
||||
import { GitLabForkSchema, GitLabReferenceSchema, GitLabRepositorySchema, GitLabIssueSchema, GitLabMergeRequestSchema, GitLabContentSchema, GitLabCreateUpdateFileResponseSchema, GitLabSearchResponseSchema, GitLabTreeSchema, GitLabCommitSchema, CreateOrUpdateFileSchema, SearchRepositoriesSchema, CreateRepositorySchema, GetFileContentsSchema, PushFilesSchema, CreateIssueSchema, CreateMergeRequestSchema, ForkRepositorySchema, CreateBranchSchema, GitLabMergeRequestDiffSchema, GetMergeRequestSchema, GetMergeRequestDiffsSchema, UpdateMergeRequestSchema, } from "./schemas.js";
|
||||
import { GitLabForkSchema, GitLabReferenceSchema, GitLabRepositorySchema, GitLabIssueSchema, GitLabMergeRequestSchema, GitLabContentSchema, GitLabCreateUpdateFileResponseSchema, GitLabSearchResponseSchema, GitLabTreeSchema, GitLabCommitSchema, CreateOrUpdateFileSchema, SearchRepositoriesSchema, CreateRepositorySchema, GetFileContentsSchema, PushFilesSchema, CreateIssueSchema, CreateMergeRequestSchema, ForkRepositorySchema, CreateBranchSchema, GitLabMergeRequestDiffSchema, GetMergeRequestSchema, GetMergeRequestDiffsSchema, UpdateMergeRequestSchema, CreateNoteSchema, } from "./schemas.js";
|
||||
const server = new Server({
|
||||
name: "gitlab-mcp-server",
|
||||
version: "0.0.1",
|
||||
@ -341,6 +341,19 @@ async function updateMergeRequest(projectId, mergeRequestIid, options) {
|
||||
await handleGitLabError(response);
|
||||
return GitLabMergeRequestSchema.parse(await response.json());
|
||||
}
|
||||
// 📦 새로운 함수: createNote - 이슈 또는 병합 요청에 노트(댓글)를 추가하는 함수
|
||||
async function createNote(projectId, noteableType, // 'issue' 또는 'merge_request' 타입 명시
|
||||
noteableIid, body) {
|
||||
// ⚙️ 응답 타입은 GitLab API 문서에 따라 조정 가능
|
||||
const url = new URL(`${GITLAB_API_URL}/projects/${encodeURIComponent(projectId)}/${noteableType}/${noteableIid}/notes`);
|
||||
const response = await fetch(url.toString(), {
|
||||
method: "POST",
|
||||
headers: DEFAULT_HEADERS,
|
||||
body: JSON.stringify({ body }),
|
||||
});
|
||||
await handleGitLabError(response);
|
||||
return await response.json(); // ⚙️ 응답 타입은 GitLab API 문서에 따라 조정 가능, 필요하면 스키마 정의
|
||||
}
|
||||
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
||||
return {
|
||||
tools: [
|
||||
@ -404,6 +417,11 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
|
||||
description: "Update a merge request",
|
||||
inputSchema: zodToJsonSchema(UpdateMergeRequestSchema),
|
||||
},
|
||||
{
|
||||
name: "create_note",
|
||||
description: "Create a new note (comment) to an issue or merge request",
|
||||
inputSchema: zodToJsonSchema(CreateNoteSchema),
|
||||
},
|
||||
],
|
||||
};
|
||||
});
|
||||
@ -515,6 +533,24 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
||||
],
|
||||
};
|
||||
}
|
||||
case "create_note": {
|
||||
try {
|
||||
const args = CreateNoteSchema.parse(request.params.arguments);
|
||||
const { project_id, noteable_type, noteable_iid, body } = args;
|
||||
const note = await createNote(project_id, noteable_type, noteable_iid, body);
|
||||
return {
|
||||
content: [{ type: "text", text: JSON.stringify(note, null, 2) }],
|
||||
};
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof z.ZodError) {
|
||||
throw new Error(`Invalid arguments: ${error.errors
|
||||
.map((e) => `${e.path.join(".")}: ${e.message}`)
|
||||
.join(", ")}`);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
default:
|
||||
throw new Error(`Unknown tool: ${request.params.name}`);
|
||||
}
|
||||
|
@ -346,3 +346,11 @@ export const UpdateMergeRequestSchema = GetMergeRequestSchema.extend({
|
||||
export const GetMergeRequestDiffsSchema = GetMergeRequestSchema.extend({
|
||||
view: z.enum(["inline", "parallel"]).optional().describe("Diff view type"),
|
||||
});
|
||||
export const CreateNoteSchema = z.object({
|
||||
project_id: z.string().describe("Project ID or namespace/project_path"),
|
||||
noteable_type: z
|
||||
.enum(["issue", "merge_request"])
|
||||
.describe("Type of noteable (issue or merge_request)"),
|
||||
noteable_iid: z.number().describe("IID of the issue or merge request"),
|
||||
body: z.string().describe("Note content"),
|
||||
});
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@zereight/mcp-gitlab",
|
||||
"version": "1.0.3",
|
||||
"version": "1.0.4",
|
||||
"description": "MCP server for using the GitLab API",
|
||||
"license": "MIT",
|
||||
"author": "zereight",
|
||||
|
Reference in New Issue
Block a user