MCPcopy Create free account
hub / github.com/SkyworkAI/DeepResearchAgent / __call__

Method __call__

src/tool/default_tools/leetcode.py:33–90  ·  view source on GitHub ↗

Fetch LeetCode problem information by slug or problem ID. Args: slug (str, optional): The problem slug (e.g., 'two-sum'). Defaults to None. problem_id (int, optional): The problem ID (e.g., 1). Defaults to None. Returns: ToolResp

(self, slug: Optional[str] = None, problem_id: Optional[int] = None, **kwargs)

Source from the content-addressed store, hash-verified

31 super().__init__(require_grad=require_grad, **kwargs)
32
33 async def __call__(self, slug: Optional[str] = None, problem_id: Optional[int] = None, **kwargs) -> ToolResponse:
34 """
35 Fetch LeetCode problem information by slug or problem ID.
36
37 Args:
38 slug (str, optional): The problem slug (e.g., 'two-sum'). Defaults to None.
39 problem_id (int, optional): The problem ID (e.g., 1). Defaults to None.
40
41 Returns:
42 ToolResponse: The response containing problem information.
43 """
44 try:
45 if not slug and not problem_id:
46 return ToolResponse(
47 success=False,
48 message="Either 'slug' or 'problem_id' must be provided",
49 )
50
51 # If only problem_id is provided, we need to get the slug first
52 if problem_id and not slug:
53 slug = await self._get_slug_by_id(problem_id)
54 if not slug:
55 return ToolResponse(
56 success=False,
57 message=f"Problem with ID {problem_id} not found"
58 )
59
60 # Fetch problem details using GraphQL
61 problem_data = await self._fetch_problem_details(slug)
62
63 if not problem_data:
64 return ToolResponse(
65 success=False,
66 message=f"Failed to fetch problem details for slug: {slug}"
67 )
68
69 # Format the response
70 formatted_response = self._format_problem_response(problem_data)
71
72 return ToolResponse(
73 success=True,
74 message=formatted_response,
75 extra=ToolExtra(
76 file_path=None,
77 data={
78 "slug": slug,
79 "problem_id": problem_id,
80 "problem_data": problem_data
81 }
82 )
83 )
84
85 except Exception as e:
86 logger.error(f"Error fetching LeetCode problem: {e}")
87 return ToolResponse(
88 success=False,
89 message=f"Error fetching LeetCode problem: {str(e)}"
90 )

Callers

nothing calls this directly

Calls 6

_get_slug_by_idMethod · 0.95
ToolResponseClass · 0.90
ToolExtraClass · 0.90
errorMethod · 0.45

Tested by

no test coverage detected