README.md 업데이트: 새로운 create_note 함수 추가 및 관련 스키마 정의
This commit is contained in:
14
README.md
14
README.md
@ -1,4 +1,6 @@
|
|||||||
# @zereight/mcp-gitlab
|
# Better GitLab MCP Server
|
||||||
|
|
||||||
|
## @zereight/mcp-gitlab
|
||||||
|
|
||||||
[](https://smithery.ai/server/@zereight/gitlab-mcp)
|
[](https://smithery.ai/server/@zereight/gitlab-mcp)
|
||||||
|
|
||||||
@ -126,6 +128,7 @@ GitLab MCP(Model Context Protocol) Server.
|
|||||||
- Returns: Array of merge request diff information
|
- Returns: Array of merge request diff information
|
||||||
|
|
||||||
12. `update_merge_request`
|
12. `update_merge_request`
|
||||||
|
|
||||||
- Update a merge request. 🔄
|
- Update a merge request. 🔄
|
||||||
- Inputs:
|
- Inputs:
|
||||||
- `project_id` (string): Project ID or namespace/project_path
|
- `project_id` (string): Project ID or namespace/project_path
|
||||||
@ -138,6 +141,15 @@ GitLab MCP(Model Context Protocol) Server.
|
|||||||
- `allow_collaboration` (optional boolean): Allow collaborators to push commits to the source branch
|
- `allow_collaboration` (optional boolean): Allow collaborators to push commits to the source branch
|
||||||
- Returns: Updated merge request details
|
- Returns: Updated merge request details
|
||||||
|
|
||||||
|
13. `create_note`
|
||||||
|
- Create a new note (comment) to an issue or merge request. 💬
|
||||||
|
- Inputs:
|
||||||
|
- `project_id` (string): Project ID or namespace/project_path
|
||||||
|
- `noteable_type` (string): Type of noteable ("issue" or "merge_request")
|
||||||
|
- `noteable_iid` (number): IID of the issue or merge request
|
||||||
|
- `body` (string): Note content
|
||||||
|
- Returns: Details of the created note
|
||||||
|
|
||||||
## Environment Variable Configuration
|
## Environment Variable Configuration
|
||||||
|
|
||||||
Before running the server, you need to set the following environment variables:
|
Before running the server, you need to set the following environment variables:
|
||||||
|
55
index.ts
55
index.ts
@ -51,6 +51,7 @@ import {
|
|||||||
type GitLabCommit,
|
type GitLabCommit,
|
||||||
type FileOperation,
|
type FileOperation,
|
||||||
type GitLabMergeRequestDiff,
|
type GitLabMergeRequestDiff,
|
||||||
|
CreateNoteSchema,
|
||||||
} from "./schemas.js";
|
} from "./schemas.js";
|
||||||
|
|
||||||
const server = new Server(
|
const server = new Server(
|
||||||
@ -573,6 +574,30 @@ async function updateMergeRequest(
|
|||||||
return GitLabMergeRequestSchema.parse(await response.json());
|
return GitLabMergeRequestSchema.parse(await response.json());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 📦 새로운 함수: createNote - 이슈 또는 병합 요청에 노트(댓글)를 추가하는 함수
|
||||||
|
async function createNote(
|
||||||
|
projectId: string,
|
||||||
|
noteableType: "issue" | "merge_request", // 'issue' 또는 'merge_request' 타입 명시
|
||||||
|
noteableIid: number,
|
||||||
|
body: string
|
||||||
|
): Promise<any> {
|
||||||
|
// ⚙️ 응답 타입은 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 () => {
|
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
||||||
return {
|
return {
|
||||||
tools: [
|
tools: [
|
||||||
@ -639,6 +664,11 @@ server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|||||||
description: "Update a merge request",
|
description: "Update a merge request",
|
||||||
inputSchema: zodToJsonSchema(UpdateMergeRequestSchema),
|
inputSchema: zodToJsonSchema(UpdateMergeRequestSchema),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "create_note",
|
||||||
|
description: "Create a new note (comment) to an issue or merge request",
|
||||||
|
inputSchema: zodToJsonSchema(CreateNoteSchema),
|
||||||
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
@ -797,6 +827,31 @@ 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:
|
default:
|
||||||
throw new Error(`Unknown tool: ${request.params.name}`);
|
throw new Error(`Unknown tool: ${request.params.name}`);
|
||||||
}
|
}
|
||||||
|
10
schemas.ts
10
schemas.ts
@ -388,6 +388,15 @@ export const GetMergeRequestDiffsSchema = GetMergeRequestSchema.extend({
|
|||||||
view: z.enum(["inline", "parallel"]).optional().describe("Diff view type"),
|
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"),
|
||||||
|
});
|
||||||
|
|
||||||
// Export types
|
// Export types
|
||||||
export type GitLabAuthor = z.infer<typeof GitLabAuthorSchema>;
|
export type GitLabAuthor = z.infer<typeof GitLabAuthorSchema>;
|
||||||
export type GitLabFork = z.infer<typeof GitLabForkSchema>;
|
export type GitLabFork = z.infer<typeof GitLabForkSchema>;
|
||||||
@ -418,3 +427,4 @@ export type GitLabSearchResponse = z.infer<typeof GitLabSearchResponseSchema>;
|
|||||||
export type GitLabMergeRequestDiff = z.infer<
|
export type GitLabMergeRequestDiff = z.infer<
|
||||||
typeof GitLabMergeRequestDiffSchema
|
typeof GitLabMergeRequestDiffSchema
|
||||||
>;
|
>;
|
||||||
|
export type CreateNoteOptions = z.infer<typeof CreateNoteSchema>;
|
||||||
|
Reference in New Issue
Block a user