diff options
| author | Dawid Rycerz <dawid@rycerz.xyz> | 2025-07-15 17:43:07 +0300 |
|---|---|---|
| committer | Dawid Rycerz <dawid@rycerz.xyz> | 2025-07-15 17:43:07 +0300 |
| commit | 9fbb9b43fa81ce04665fddbaaa64ab455158a44e (patch) | |
| tree | ed69c6257b590acd6942d34eccc6e75231f92b02 /servers/gitlab_python/src | |
| parent | ea094d5731ae36db599b9a9803c41db303fc685a (diff) | |
feat: Add listing and adding comments
Diffstat (limited to 'servers/gitlab_python/src')
| -rw-r--r-- | servers/gitlab_python/src/mcp_server_gitlab_python/server.py | 200 |
1 files changed, 200 insertions, 0 deletions
diff --git a/servers/gitlab_python/src/mcp_server_gitlab_python/server.py b/servers/gitlab_python/src/mcp_server_gitlab_python/server.py index c176832..6688a1a 100644 --- a/servers/gitlab_python/src/mcp_server_gitlab_python/server.py +++ b/servers/gitlab_python/src/mcp_server_gitlab_python/server.py @@ -389,6 +389,126 @@ class GitLabPythonServer: logger.error(f"Failed to update epic {group}#{epic_iid}: {e}") return {"error": str(e)} + def list_issue_comments( + self, project: str, issue_iid: int + ) -> dict[str, Any]: + """List all comments (notes) for a given issue. + + Args: + project (str): The project full path or ID. + issue_iid (int): The internal ID of the issue. + + Returns: + dict[str, Any]: Dictionary with a list of comments or error message. + """ + try: + proj = self.gl.projects.get(project) + issue = proj.issues.get(issue_iid) + notes = issue.notes.list(all=True) + return { + "comments": [ + { + "id": n.id, + "body": n.body, + "author": getattr(n, "author", None), + "created_at": n.created_at, + "updated_at": n.updated_at, + "system": getattr(n, "system", False), + } + for n in notes + ] + } + except Exception as e: + return {"error": str(e)} + + def create_issue_comment( + self, project: str, issue_iid: int, body: str + ) -> dict[str, Any]: + """Create a comment (note) on a given issue. + + Args: + project (str): The project full path or ID. + issue_iid (int): The internal ID of the issue. + body (str): The comment text. + + Returns: + dict[str, Any]: Dictionary with the comment info or error message. + """ + try: + proj = self.gl.projects.get(project) + issue = proj.issues.get(issue_iid) + note = issue.notes.create({"body": body}) + return { + "id": note.id, + "body": note.body, + "author": getattr(note, "author", None), + "created_at": note.created_at, + "updated_at": note.updated_at, + "system": getattr(note, "system", False), + } + except Exception as e: + return {"error": str(e)} + + def list_epic_comments( + self, group: str, epic_iid: int + ) -> dict[str, Any]: + """List all comments (notes) for a given epic. + + Args: + group (str): The group full path or ID. + epic_iid (int): The internal ID of the epic. + + Returns: + dict[str, Any]: Dictionary with a list of comments or error message. + """ + try: + grp = self.gl.groups.get(group) + epic = grp.epics.get(epic_iid) + notes = epic.notes.list(all=True) + return { + "comments": [ + { + "id": n.id, + "body": n.body, + "author": getattr(n, "author", None), + "created_at": n.created_at, + "updated_at": n.updated_at, + "system": getattr(n, "system", False), + } + for n in notes + ] + } + except Exception as e: + return {"error": str(e)} + + def create_epic_comment( + self, group: str, epic_iid: int, body: str + ) -> dict[str, Any]: + """Create a comment (note) on a given epic. + + Args: + group (str): The group full path or ID. + epic_iid (int): The internal ID of the epic. + body (str): The comment text. + + Returns: + dict[str, Any]: Dictionary with the comment info or error message. + """ + try: + grp = self.gl.groups.get(group) + epic = grp.epics.get(epic_iid) + note = epic.notes.create({"body": body}) + return { + "id": note.id, + "body": note.body, + "author": getattr(note, "author", None), + "created_at": note.created_at, + "updated_at": note.updated_at, + "system": getattr(note, "system", False), + } + except Exception as e: + return {"error": str(e)} + def create_server(host: str = "127.0.0.1", port: int = 8080) -> FastMCP: mcp = FastMCP("GitLab Python", host=host, port=port) @@ -616,6 +736,86 @@ def create_server(host: str = "127.0.0.1", port: int = 8080) -> FastMCP: data.update(kwargs) return server.update_epic(group, epic_iid, **data) + @mcp.tool() + def list_issue_comments( + project: str, + issue_iid: int, + working_directory: str, + ) -> dict[str, Any]: + """List all comments (notes) for a given issue. + + Args: + project (str): The project full path or ID. + issue_iid (int): The internal ID of the issue. + working_directory (str): The working directory for context. + + Returns: + dict[str, Any]: Dictionary with a list of comments or error message. + """ + server = GitLabPythonServer(working_directory) + return server.list_issue_comments(project, issue_iid) + + @mcp.tool() + def create_issue_comment( + project: str, + issue_iid: int, + body: str, + working_directory: str, + ) -> dict[str, Any]: + """Create a comment (note) on a given issue. + + Args: + project (str): The project full path or ID. + issue_iid (int): The internal ID of the issue. + body (str): The comment text. + working_directory (str): The working directory for context. + + Returns: + dict[str, Any]: Dictionary with the comment info or error message. + """ + server = GitLabPythonServer(working_directory) + return server.create_issue_comment(project, issue_iid, body) + + @mcp.tool() + def list_epic_comments( + group: str, + epic_iid: int, + working_directory: str, + ) -> dict[str, Any]: + """List all comments (notes) for a given epic. + + Args: + group (str): The group full path or ID. + epic_iid (int): The internal ID of the epic. + working_directory (str): The working directory for context. + + Returns: + dict[str, Any]: Dictionary with a list of comments or error message. + """ + server = GitLabPythonServer(working_directory) + return server.list_epic_comments(group, epic_iid) + + @mcp.tool() + def create_epic_comment( + group: str, + epic_iid: int, + body: str, + working_directory: str, + ) -> dict[str, Any]: + """Create a comment (note) on a given epic. + + Args: + group (str): The group full path or ID. + epic_iid (int): The internal ID of the epic. + body (str): The comment text. + working_directory (str): The working directory for context. + + Returns: + dict[str, Any]: Dictionary with the comment info or error message. + """ + server = GitLabPythonServer(working_directory) + return server.create_epic_comment(group, epic_iid, body) + return mcp async def main(transport_type: str, host: str, port: int) -> None: |
