get_current_session
Check authentication status and retrieve current user information on USCardForum to verify login state before performing actions.
Instructions
Get information about the current session.
Returns a Session object with:
- is_authenticated: Whether logged in
- current_user: CurrentUser object with user info (if authenticated)
Use to verify authentication status.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- The main MCP tool handler for 'get_current_session'. Decorated with @mcp.tool(), it retrieves the current session information by calling get_client().get_current_session() and returns a Session object.@mcp.tool() def get_current_session() -> Session: """ Get information about the current session. Returns a Session object with: - is_authenticated: Whether logged in - current_user: CurrentUser object with user info (if authenticated) Use to verify authentication status. """ return get_client().get_current_session()
- src/uscardforum/client.py:482-488 (handler)DiscourseClient method that delegates get_current_session to its _auth (AuthAPI) instance.def get_current_session(self) -> Session: """Get current session info. Returns: Session data including user info """ return self._auth.get_current_session()
- src/uscardforum/api/auth.py:97-111 (handler)Core AuthAPI implementation that fetches /session/current.json from Discourse API or returns unauthenticated Session on 404.def get_current_session(self) -> Session: """Get current session info. Returns: Session data including user info (unauthenticated if no session) """ try: payload = self._get("/session/current.json") return Session.from_api_response(payload) except requests.exceptions.HTTPError as e: # 404 means no session - return unauthenticated session if e.response is not None and e.response.status_code == 404: return Session(is_authenticated=False, current_user=None) raise
- Global helper function get_client() that provides the singleton DiscourseClient instance, used by the tool handler. Handles auto-login from env vars.def get_client() -> DiscourseClient: """Get or create the Discourse client instance.""" global _client, _login_attempted if _client is None: base_url = os.environ.get("USCARDFORUM_URL", "https://www.uscardforum.com") timeout = float(os.environ.get("USCARDFORUM_TIMEOUT", "15.0")) _client = DiscourseClient(base_url=base_url, timeout_seconds=timeout) # Auto-login if credentials are provided if not _login_attempted: _login_attempted = True username = os.environ.get("NITAN_USERNAME") password = os.environ.get("NITAN_PASSWORD") if username and password: try: result = _client.login(username, password) if result.success: print(f"[uscardforum] Auto-login successful as '{result.username}'") elif result.requires_2fa: print( "[uscardforum] Auto-login failed: 2FA required. Use login() tool with second_factor_token." ) else: print( f"[uscardforum] Auto-login failed: {result.error or 'Unknown error'}" ) except Exception as e: # pragma: no cover - logging side effect print(f"[uscardforum] Auto-login error: {e}") return _client
- src/uscardforum/server_tools/__init__.py:52-58 (registration)Re-export of get_current_session from auth.py in server_tools package __init__, making it available for import in server.py.from .auth import ( login, get_current_session, get_notifications, bookmark_post, subscribe_topic, )