JupyterPasswordAuth (jupyter_mcp_server/auth.py)

jupyter-mcp-server · jupyter_mcp_server/auth.py · python · BSD-3-Clause
auth

Handles password-based authentication for Jupyter servers, managing sessions and cookies for API access.

# Source: https://github.com/datalayer/jupyter-mcp-server | License: BSD-3-Clause | Copyright 2025, Datalayer
# Provided via justclaw.it.com; keep this notice with the code.
# Copyright (c) 2024- Datalayer, Inc.
#
# BSD 3-Clause License

"""Authentication utilities for Jupyter server password login."""

from typing import Optional

import requests

from jupyter_mcp_server.log import logger


_BODY_PREVIEW_CHARS = 200


def _truncate(text: str) -> str:
    """Trim a response body for inclusion in an error message."""
    if not text:
        return "<empty>"
    snippet = text.strip().replace("\n", " ")
    if len(snippet) <= _BODY_PREVIEW_CHARS:
        return repr(snippet)
    return repr(snippet[:_BODY_PREVIEW_CHARS] + "…")


class JupyterPasswordAuth:
    """Handles password-based authe

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key