list_problems
Retrieve available coding challenges from the Orange Juice Online Judge to browse and select problems for solving.
Instructions
Fetch the list of problems from the Online Judge. Returns a JSON string containing total count and results.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| offset | No | ||
| limit | No |
Output Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- src/oj_mcp_server/server.py:30-41 (handler)The list_problems tool handler function that fetches problem list from the Online Judge. It accepts offset and limit parameters, uses get_authenticated_client() to ensure authentication, calls client.get_problems(), and returns the JSON result as a string.
@mcp.tool() def list_problems(offset: int = 0, limit: int = 50) -> str: """ Fetch the list of problems from the Online Judge. Returns a JSON string containing total count and results. """ c = get_authenticated_client() try: data = c.get_problems(offset=offset, limit=limit) return str(data) except Exception as e: return f"Error: {e}" - src/oj_mcp_server/server.py:21-28 (helper)Helper function get_authenticated_client() used by list_problems to ensure the user is logged in before making API calls. Handles lazy initialization of authentication using environment variables.
def get_authenticated_client(): global is_logged_in if not is_logged_in: if not OJ_USERNAME or not OJ_PASSWORD: raise ValueError("OJ_USERNAME and OJ_PASSWORD environment variables are required.") client.login(OJ_USERNAME, OJ_PASSWORD) is_logged_in = True return client - src/oj_mcp_server/oj_client.py:42-46 (helper)The get_problems() method in OJClient that makes the actual HTTP GET request to /api/problem endpoint with pagination parameters (offset, limit) and returns the JSON response.
def get_problems(self, offset=0, limit=50): params = {'paging': 'true', 'offset': offset, 'limit': limit} resp = self.session.get(self._get_url("/api/problem"), params=params, timeout=20) resp.raise_for_status() return resp.json()