Skip to content

datarobot_genai.drmcpbase.fastmcp_transforms.utils

utils

get_header_value

get_header_value(headers: Mapping[str, str], name: str) -> str | None

Read a header by lowercase name (FastMCP normalizes keys; scan only as fallback).

Source code in datarobot_genai/drmcpbase/fastmcp_transforms/utils.py
def get_header_value(headers: Mapping[str, str], name: str) -> str | None:
    """Read a header by lowercase name (FastMCP normalizes keys; scan only as fallback)."""
    value = headers.get(name)
    if value is not None:
        return value
    target = name.casefold()
    for key, header_value in headers.items():
        if key.casefold() == target:
            return header_value
    return None

parse_bool_header

parse_bool_header(raw: str | None, *, default: bool = True) -> bool

Parse an optional boolean header; unrecognized values fall back to default.

Source code in datarobot_genai/drmcpbase/fastmcp_transforms/utils.py
def parse_bool_header(raw: str | None, *, default: bool = True) -> bool:
    """Parse an optional boolean header; unrecognized values fall back to *default*."""
    if raw is None:
        return default
    token = raw.strip().casefold()
    if token in _TRUE_HEADER_VALUES:
        return True
    if token in _FALSE_HEADER_VALUES:
        return False
    return default

parse_disabled_categories

parse_disabled_categories(headers: Mapping[str, str]) -> frozenset[str]

Resolve the category-gate headers to the set of disabled category names.

Every gate defaults to enabled; only an explicit false disables its category for this request.

Source code in datarobot_genai/drmcpbase/fastmcp_transforms/utils.py
def parse_disabled_categories(headers: Mapping[str, str]) -> frozenset[str]:
    """Resolve the category-gate headers to the set of disabled category names.

    Every gate defaults to enabled; only an explicit ``false`` disables its
    category for this request.
    """
    disabled: set[str] = set()
    for header_name, category_names in CATEGORY_GATE_HEADERS.items():
        if not parse_bool_header(get_header_value(headers, header_name)):
            disabled.update(category_names)
    return frozenset(disabled)

get_tool_category

get_tool_category(tool: Tool) -> str | None

Category name stamped by the providers, or None for untagged (built-in) tools.

Source code in datarobot_genai/drmcpbase/fastmcp_transforms/utils.py
def get_tool_category(tool: Tool) -> str | None:
    """Category name stamped by the providers, or None for untagged (built-in) tools."""
    category = (tool.meta or {}).get("tool_category")
    return category if isinstance(category, str) else None

is_category_disabled_for_request

is_category_disabled_for_request(category_name: str) -> bool

Return True when a category gate disables category_name for the current request.

Safe to call from providers, including outside an HTTP request (startup retrospection, in-process clients): any failure to read the request context means "no gates", preserving the default-enabled behavior.

Source code in datarobot_genai/drmcpbase/fastmcp_transforms/utils.py
def is_category_disabled_for_request(category_name: str) -> bool:
    """Return True when a category gate disables *category_name* for the current request.

    Safe to call from providers, including outside an HTTP request (startup
    retrospection, in-process clients): any failure to read the request context
    means "no gates", preserving the default-enabled behavior.
    """
    try:
        return category_name in get_request_context().disabled_categories
    except Exception:  # noqa: BLE001 — gates must never break the provider path
        return False