Skip to main content
Glama
raidenrock

USCardForum MCP Server

by raidenrock

get_current_session

Check authentication status and retrieve current 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
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • MCP tool handler implementation for 'get_current_session'. This is the core FastMCP tool function decorated with @mcp.tool(), which delegates 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()
  • Pydantic BaseModel defining the Session output schema for the tool, including current_user and is_authenticated 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,
            )
  • Shared get_client() helper function that initializes and returns the global DiscourseClient instance, handling 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"))
    
            username = os.environ.get("NITAN_USERNAME")
            password = os.environ.get("NITAN_PASSWORD")
            user_api_key = os.environ.get("NITAN_API_KEY")
            user_api_client_id = os.environ.get("NITAN_API_CLIENT_ID")
    
            _client = DiscourseClient(
                base_url=base_url,
                timeout_seconds=timeout,
                user_api_key=user_api_key if not (username and password) else None,
                user_api_client_id=(
                    user_api_client_id if not (username and password) else None
                ),
            )
    
            if _client.is_authenticated:
                print("[uscardforum] Using User API Key authentication")
            elif not _login_attempted:
                _login_attempted = True
    
                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
  • AuthAPI.get_current_session() implementation: fetches /session/current.json from Discourse API and parses response into Session model.
    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
  • DiscourseClient.get_current_session() convenience wrapper that delegates to the internal AuthAPI instance.
    def get_current_session(self) -> Session:
        """Get current session info.
    
        Returns:
            Session data including user info
        """
        return self._auth.get_current_session()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/raidenrock/uscardforum-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server