Skip to main content
Glama

get_api_token

Generate API tokens for authenticated access to ArchiveBox's web archiving features, enabling programmatic control over URL archiving and snapshot management.

Instructions

Generate an API token for a given username & password.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The primary MCP tool handler for 'get_api_token'. Decorated with @mcp.tool(), defines input schema via Pydantic Field descriptions, creates an ArchiveBox Api client instance, calls the client's get_api_token method to perform the actual API request, and returns the JSON response.
    @mcp.tool(
        exclude_args=[
            "archivebox_url",
            "username",
            "password",
            "token",
            "api_key",
            "verify",
        ],
        tags={"authentication"},
    )
    def get_api_token(
        username: Optional[str] = Field(
            description="The username for authentication",
        ),
        password: Optional[str] = Field(
            description="The password for authentication",
        ),
        archivebox_url: str = Field(
            default=os.environ.get("ARCHIVEBOX_URL", None),
            description="The URL of the ArchiveBox instance (e.g., https://yourinstance.archivebox.com)",
        ),
        token: Optional[str] = Field(
            default=os.environ.get("ARCHIVEBOX_TOKEN", None),
            description="Bearer token for authentication",
        ),
        api_key: Optional[str] = Field(
            default=os.environ.get("ARCHIVEBOX_API_KEY", None),
            description="API key for authentication",
        ),
        verify: Optional[bool] = Field(
            default=to_boolean(os.environ.get("ARCHIVEBOX_VERIFY", "True")),
            description="Whether to verify SSL certificates",
        ),
    ) -> dict:
        """
        Generate an API token for a given username & password.
        """
        client = Api(
            url=archivebox_url,
            username=username,
            password=password,
            token=token,
            api_key=api_key,
            verify=verify,
        )
        response = client.get_api_token(username=username, password=password)
        return response.json()
  • Supporting helper method in the Api class that executes the HTTP POST request to the ArchiveBox server's /api/v1/auth/get_api_token endpoint with the provided username and password to obtain the API token.
    def get_api_token(
        self, username: Optional[str] = None, password: Optional[str] = None
    ) -> requests.Response:
        """
        Generate an API token for a given username & password
    
        Args:
            username: The username for authentication.
            password: The password for authentication.
    
        Returns:
            Response: The response object from the POST request.
    
        Raises:
            ParameterError: If the provided parameters are invalid.
        """
        try:
            data = {}
            if username is not None:
                data["username"] = username
            if password is not None:
                data["password"] = password
            response = self._session.post(
                url=f"{self.url}/api/v1/auth/get_api_token",
                json=data,
                headers={"Content-Type": "application/json"},
                verify=self.verify,
            )
        except ValidationError as e:
            raise ParameterError(f"Invalid parameters: {e.errors()}")
        return response
  • Utility helper function used to convert the 'verify' parameter string from environment variable to boolean.
    def to_boolean(string: Union[str, bool] = None) -> bool:
        if isinstance(string, bool):
            return string
        if not string:
            return False
        normalized = str(string).strip().lower()
        true_values = {"t", "true", "y", "yes", "1"}
        false_values = {"f", "false", "n", "no", "0"}
        if normalized in true_values:
            return True
        elif normalized in false_values:
            return False
        else:
            raise ValueError(f"Cannot convert '{string}' to boolean")
  • Initialization of the FastMCP server instance where tools like get_api_token are registered via decorators.
    mcp = FastMCP("ArchiveBox")

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/Knuckles-Team/archivebox-api'

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