summaryrefslogtreecommitdiff
path: root/servers/gitlab_glab/src/mcp_server_gitlab_glab
diff options
context:
space:
mode:
Diffstat (limited to 'servers/gitlab_glab/src/mcp_server_gitlab_glab')
-rw-r--r--servers/gitlab_glab/src/mcp_server_gitlab_glab/server.py97
1 files changed, 97 insertions, 0 deletions
diff --git a/servers/gitlab_glab/src/mcp_server_gitlab_glab/server.py b/servers/gitlab_glab/src/mcp_server_gitlab_glab/server.py
index e6c4d47..958e0a7 100644
--- a/servers/gitlab_glab/src/mcp_server_gitlab_glab/server.py
+++ b/servers/gitlab_glab/src/mcp_server_gitlab_glab/server.py
@@ -8,6 +8,7 @@ This module provides an MCP server that integrates with GitLab through the GitLa
import json
import logging
import os
+import re
import subprocess
import sys
from typing import Any
@@ -143,6 +144,64 @@ class GitLabServer:
else:
return {"error": f"Project '{project_name}' not found"}
+ def create_issue(
+ self,
+ title: str,
+ description: str,
+ working_directory: str,
+ labels: list[str] | None = None,
+ assignee: list[str] | None = None,
+ milestone: str | None = None,
+ epic_id: int | None = None,
+ project: str | None = None,
+ ) -> dict[str, Any]:
+ """Create a new GitLab issue.
+
+ Args:
+ title: The issue title.
+ description: The issue description.
+ labels: Optional list of labels to apply to the issue.
+ assignee: Optional list of usernames to assign the issue to.
+ milestone: Optional milestone title or ID.
+ epic_id: Optional ID of the epic to add the issue to.
+ project: Optional project name or path.
+ working_directory: The directory to execute the command in.
+
+ Returns:
+ A dictionary containing the issue URL or an error message.
+ """
+ # Build command arguments
+ args = ["issue", "create", "-y", "-t", title, "-d", description]
+
+ # Add optional arguments if provided
+ if labels:
+ args.extend(["-l", ",".join(labels)])
+ if assignee:
+ for user in assignee:
+ args.extend(["-a", user])
+ if milestone:
+ args.extend(["-m", milestone])
+ if epic_id:
+ args.extend(["--epic", str(epic_id)])
+ if project:
+ args.extend(["-R", project])
+
+ # Execute the command
+ success, result = self.execute_glab_command(args, working_directory)
+
+ if not success:
+ return result
+
+ # Parse the output to extract the issue URL
+ url_pattern = re.compile(r'https?://[^\s]+/issues/\d+')
+ match = url_pattern.search(result)
+ if match:
+ return {"url": match.group(0)}
+ else:
+ # Log the full output for debugging
+ logger.error(f"Failed to extract issue URL from output: {result}")
+ return {"error": "Failed to extract issue URL from command output"}
+
def create_server(host: str = "127.0.0.1", port: int = 8080) -> FastMCP:
"""Create and configure the FastMCP server.
@@ -190,6 +249,44 @@ def create_server(host: str = "127.0.0.1", port: int = 8080) -> FastMCP:
"""
return gitlab.find_project(project_name, working_directory)
+ # Add create_issue tool
+ @mcp.tool()
+ def create_issue(
+ title: str,
+ description: str,
+ working_directory: str,
+ labels: list[str] | None = None,
+ assignee: list[str] | None = None,
+ milestone: str | None = None,
+ epic_id: int | None = None,
+ project: str | None = None,
+ ) -> dict[str, Any]:
+ """Create a new GitLab issue.
+
+ Args:
+ title: The issue title.
+ description: The issue description.
+ labels: Optional list of labels to apply to the issue.
+ assignee: Optional list of usernames to assign the issue to.
+ milestone: Optional milestone title or ID.
+ epic_id: Optional ID of the epic to add the issue to.
+ project: Optional project name or path.
+ working_directory: The directory to execute the command in.
+
+ Returns:
+ A dictionary containing the issue URL or an error message.
+ """
+ return gitlab.create_issue(
+ title=title,
+ description=description,
+ working_directory=working_directory,
+ labels=labels,
+ assignee=assignee,
+ milestone=milestone,
+ epic_id=epic_id,
+ project=project,
+ )
+
return mcp