Skip to content

Commit e770c4b

Browse files
Vijay IyengarVijay Iyengar
authored andcommitted
fix: Resolve multiple handler implementation issues
- Fix gitlab_get_snippet TypeError by correcting _snippet_to_dict method signature * Remove @staticmethod decorator and add self parameter * Method was incorrectly defined as static but called as instance method - Fix gitlab_batch_operations validation and error handling * Add proper validation for operation structure (must be dict with 'type' field) * Improve error messages for malformed operations * Fix indentation in operation type checks * Better debugging for 'Unknown operation type: None' errors These fixes address TypeError and validation issues that were preventing proper tool functionality. The methods now handle edge cases and provide clearer error messages for debugging.
1 parent 329c139 commit e770c4b

File tree

1 file changed

+28
-23
lines changed

1 file changed

+28
-23
lines changed

src/mcp_gitlab/gitlab_client.py

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,8 +1201,7 @@ def list_group_projects(
12011201
"group_id": group_id,
12021202
}
12031203

1204-
@staticmethod
1205-
def _snippet_to_dict(snippet: Any) -> Dict[str, Any]:
1204+
def _snippet_to_dict(self, snippet: Any) -> Dict[str, Any]:
12061205
"""Convert snippet object to dictionary"""
12071206
return {
12081207
"id": getattr(snippet, "id", None),
@@ -3378,28 +3377,34 @@ def batch_operations(self, project_id: str, operations: List[Dict[str, Any]],
33783377

33793378
for i, operation in enumerate(operations):
33803379
try:
3381-
op_type = operation.get("type")
3382-
op_params = operation.get("params", {})
3383-
3384-
# Add project_id to params if not present
3385-
if "project_id" not in op_params:
3386-
op_params["project_id"] = project_id
3387-
3388-
# Execute operation based on type
3389-
if op_type == "get_issue":
3390-
result = self.get_issue(**op_params)
3391-
elif op_type == "get_merge_request":
3392-
result = self.get_merge_request(**op_params)
3393-
elif op_type == "list_issues":
3394-
result = self.list_issues(**op_params)
3395-
elif op_type == "list_merge_requests":
3396-
result = self.list_merge_requests(**op_params)
3397-
elif op_type == "get_file_content":
3398-
result = self.get_file_content(**op_params)
3399-
elif op_type == "get_commits":
3400-
result = self.get_commits(**op_params)
3380+
# Validate operation structure
3381+
if not isinstance(operation, dict):
3382+
result = {"error": f"Operation at index {i} must be a dictionary, got {type(operation).__name__}"}
3383+
elif "type" not in operation:
3384+
result = {"error": f"Operation at index {i} missing required 'type' field"}
34013385
else:
3402-
result = {"error": f"Unknown operation type: {op_type}"}
3386+
op_type = operation.get("type")
3387+
op_params = operation.get("params", {})
3388+
3389+
# Add project_id to params if not present
3390+
if "project_id" not in op_params:
3391+
op_params["project_id"] = project_id
3392+
3393+
# Execute operation based on type
3394+
if op_type == "get_issue":
3395+
result = self.get_issue(**op_params)
3396+
elif op_type == "get_merge_request":
3397+
result = self.get_merge_request(**op_params)
3398+
elif op_type == "list_issues":
3399+
result = self.list_issues(**op_params)
3400+
elif op_type == "list_merge_requests":
3401+
result = self.list_merge_requests(**op_params)
3402+
elif op_type == "get_file_content":
3403+
result = self.get_file_content(**op_params)
3404+
elif op_type == "get_commits":
3405+
result = self.get_commits(**op_params)
3406+
else:
3407+
result = {"error": f"Unknown operation type: {op_type}"}
34033408

34043409
results.append({
34053410
"index": i,

0 commit comments

Comments
 (0)