Forráskód Böngészése

add tools add_issue_relationship

Khanh Nguyen 2 hónapja
szülő
commit
9cfad871e7
3 módosított fájl, 28 hozzáadás és 2 törlés
  1. 2 0
      .cursor/rules/mantis.mdc
  2. 5 1
      mantis_mcp/mcp/resources.py
  3. 21 1
      mantis_mcp/mcp/tools.py

+ 2 - 0
.cursor/rules/mantis.mdc

@@ -25,6 +25,7 @@ Tu es un assistant LW Copilot pour MantisBT. Tu aides l'utilisateur à créer, m
 | `create_issue` | Créer un ticket |
 | `modify_issue` | Modifier un ticket existant |
 | `add_issue_note` | Ajouter un commentaire |
+| `add_issue_relationship` | Ajouter une relation |
 
 **Ressources autorisées** — lecture uniquement via `resources/read` :
 
@@ -37,6 +38,7 @@ Tu es un assistant LW Copilot pour MantisBT. Tu aides l'utilisateur à créer, m
 | `mantisbt://issues/{id}/history` | Historique d'un ticket |
 | `mantisbt://projects` | Lister les projets |
 | `mantisbt://projects/{id}` | Détail d'un projet |
+| `mantisbt://projects/{id}/issues` | Tickets d'un projet |
 | `mantisbt://projects/{id}/handlers` | Utilisateurs assignables |
 
 Toute action hors de cette liste est **interdite** (suppression, endpoints REST non exposés, contournement MCP).

+ 5 - 1
mantis_mcp/mcp/resources.py

@@ -29,7 +29,7 @@ def _read_resource(
 @mcp.resource("mantisbt://issues")
 def get_issues() -> str:
     """Retrieve all issues from MantisBT."""
-    return _read_resource(endpoint="/api/rest/issues")
+    return _read_resource(endpoint="/api/rest/issues?page_size=0")
 
 
 @mcp.resource("mantisbt://issues/assigned")
@@ -81,6 +81,10 @@ def get_project(project_id: str) -> str:
     """Retrieve project details by ID."""
     return _read_resource(endpoint=f"/api/rest/projects/{project_id}")
 
+@mcp.resource("mantisbt://projects/{project_id}/issues")
+def get_project_issues(project_id: str) -> str:
+    """Retrieve project details by ID."""
+    return _read_resource(endpoint=f"/api/rest/issues?project_id={project_id}&page_size=0")
 
 @mcp.resource("mantisbt://projects/{project_id}/handlers")
 def get_project_handlers(project_id: str) -> str:

+ 21 - 1
mantis_mcp/mcp/tools.py

@@ -25,7 +25,7 @@ def _parse_values(values: str) -> dict[str, Any]:
     return parsed
 
 
-def _build_enum_field(field_name: str, value: int) -> dict[str, int]:
+def _build_enum_field(field_name: str, value: int) -> dict[str, dict]:
     return {field_name: {"id": value}}
 
 
@@ -142,3 +142,23 @@ def add_issue_note(
         )
     except RestApiError as error:
         return _format_error(error)
+
+@mcp.tool()
+def add_issue_relationship(
+    id: int = Field(..., description="The ID of the issue") ,
+    related_id: int = Field(..., description="The ID of the issue related to this issue"),
+    relationship: str = Field(..., description="Type of the relationship")
+) -> str:
+    """Add a relation between two existing issues."""
+    client = ClientREST()
+    body:dict[str, Any] = {
+        "issue" : {"id" : related_id},
+        "type" : {"name" : relationship}
+    }
+
+    try:
+        return _format_result(
+            client.execute(HTTPMethod.POST, f"/api/rest/issues/{id}/relationships", params=body)
+        )
+    except RestApiError as error:
+        return _format_error(error)