Skip to content

datarobot_genai.drmcpbase.dynamic_tools.deployment.metadata

metadata

Pure metadata assembly for DataRobot deployment tools.

All functions in this module are pure: they take pre-fetched data as arguments and do not make any HTTP calls or access request context.

build_mcp_tool_metadata

build_mcp_tool_metadata(deployment: Deployment, info_payload: dict[str, Any] | None, supports_chat_api: bool) -> MetadataBase

Assemble a MetadataBase adapter from pre-fetched deployment data.

This is the pure counterpart to get_mcp_tool_metadata in drmcp. It takes data already fetched from the DR API and selects the appropriate adapter.

Parameters:

Name Type Description Default
deployment Deployment

The DataRobot deployment object.

required
info_payload dict[str, Any] | None

The normalised response from directAccess/info/, or None when the deployment is a native DataRobot structured prediction model that does not expose this endpoint.

required
supports_chat_api bool

Whether the deployment advertises chat completions support (from the capabilities endpoint). Ignored when info_payload is None.

required
Returns
MetadataBase adapter instance.
Raises
ValueError: If info_payload is required but not provided.
Source code in datarobot_genai/drmcpbase/dynamic_tools/deployment/metadata.py
def build_mcp_tool_metadata(
    deployment: dr.Deployment,
    info_payload: dict[str, Any] | None,
    supports_chat_api: bool,
) -> MetadataBase:
    """Assemble a MetadataBase adapter from pre-fetched deployment data.

    This is the pure counterpart to get_mcp_tool_metadata in drmcp. It takes
    data already fetched from the DR API and selects the appropriate adapter.

    Args:
        deployment: The DataRobot deployment object.
        info_payload: The normalised response from directAccess/info/, or None
            when the deployment is a native DataRobot structured prediction model
            that does not expose this endpoint.
        supports_chat_api: Whether the deployment advertises chat completions
            support (from the capabilities endpoint). Ignored when info_payload
            is None.

    Returns
    -------
        MetadataBase adapter instance.

    Raises
    ------
        ValueError: If info_payload is required but not provided.
    """
    target_type = _is_datarobot_structured_prediction(deployment)
    if target_type:
        return DrumMetadataAdapter.from_target_type(target_type)

    if info_payload is None:
        raise ValueError(
            f"info_payload is required for deployment {deployment.id} "
            "which is not a native DataRobot structured prediction model."
        )

    metadata = dict(info_payload)
    metadata["supports_chat_api"] = supports_chat_api

    if is_drum(metadata):
        return DrumMetadataAdapter.from_deployment_metadata(metadata)

    return Metadata(metadata)