get_current_session
Retrieve current session details including authentication status and user information to verify login state on USCardForum.
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 MCP tool handler for 'get_current_session'. Decorated with @mcp.tool(), it has no input parameters and returns a Session object by delegating to the client.@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/models/auth.py:46-64 (schema)Pydantic model defining the output schema for get_current_session, including is_authenticated and current_user fields.class Session(BaseModel): """Current session information.""" current_user: CurrentUser | None = Field(None, description="Logged-in user") is_authenticated: bool = Field(False, description="Whether authenticated") class Config: extra = "ignore" @classmethod def from_api_response(cls, data: dict[str, Any]) -> "Session": """Parse from raw API response.""" user_data = data.get("current_user") or data.get("user") current_user = CurrentUser(**user_data) if user_data else None return cls( current_user=current_user, is_authenticated=current_user is not None, )
- src/uscardforum/api/auth.py:97-111 (helper)Client-side helper method in AuthAPI that implements the actual API call to retrieve the current session information.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
- src/uscardforum/server_tools/__init__.py:52-58 (registration)Import of get_current_session from auth.py into the server_tools package __init__.py, exposing it as part of the MCP tools.from .auth import ( login, get_current_session, get_notifications, bookmark_post, subscribe_topic, )
- __all__ export in auth.py including get_current_session, making it available for import.__all__ = [ "login", "get_current_session", "get_notifications", "bookmark_post", "subscribe_topic", ]