Skip to content

datarobot_genai.drmcpbase.dynamic_tools.external_tool

external_tool

ExternalToolRegistrationConfig

Bases: BaseModel

Configuration for registering an external HTTP API endpoint as an MCP tool.

This specification defines how to register a generic external HTTP API as a tool that can be called by LLM agents through the MCP (Model Context Protocol) server. The tool acts as a bridge between the LLM and any external HTTP API, automatically handling request construction, retry logic, and response formatting.

Source code in datarobot_genai/drmcpbase/dynamic_tools/external_tool.py
class ExternalToolRegistrationConfig(BaseModel):
    """Configuration for registering an external HTTP API endpoint as an MCP tool.

    This specification defines how to register a generic external HTTP API as a tool
    that can be called by LLM agents through the MCP (Model Context Protocol) server.
    The tool acts as a bridge between the LLM and any external HTTP API, automatically
    handling request construction, retry logic, and response formatting.
    """

    name: str = Field(..., description="Name of the tool.")
    title: str | None = Field(None, description="Title for LLMs and users.")
    description: str | None = Field(None, description="Description for LLMs and users.")
    method: Literal["GET", "POST", "PATCH", "PUT", "DELETE"] = Field(
        ..., description="HTTP method to use."
    )
    base_url: str = Field(..., description="Base URL of the external API.")
    endpoint: str = Field(
        ...,
        description="URL endpoint/route for the external API, may include path params.",
    )
    headers: dict[str, str] | None = Field(
        None, description="Optional static headers to include in requests."
    )
    input_schema: dict[str, Any] = Field(
        ..., description="Pydantic schema defining the tool's input schema."
    )
    tags: set[str] | None = Field(
        None, description="Optional tags for tool categorization and filtering."
    )

get_outbound_headers async

get_outbound_headers(spec: ExternalToolRegistrationConfig) -> dict[str, str]

Retrieve headers to send to the external tool.

Forwards whitelisted headers from the current FastMCP HTTP request, merged with tool-specific static headers. Spec headers always win on case-insensitive key collisions.

Source code in datarobot_genai/drmcpbase/dynamic_tools/external_tool.py
async def get_outbound_headers(spec: ExternalToolRegistrationConfig) -> dict[str, str]:
    """Retrieve headers to send to the external tool.

    Forwards whitelisted headers from the current FastMCP HTTP request,
    merged with tool-specific static headers. Spec headers always win
    on case-insensitive key collisions.
    """
    headers = get_http_headers()

    # Headers from the incoming request to be forwarded (case-insensitive match)
    forwarded_headers: dict[str, str] = {
        key: value for key, value in headers.items() if key.lower() in REQUEST_FORWARDED_HEADERS
    }

    spec_headers = spec.headers or {}

    # Spec headers take priority; forwarded headers fill in gaps (case-insensitive dedup)
    spec_lower = {k.lower() for k in spec_headers}
    out_headers: dict[str, str] = dict(spec_headers)
    for key, value in forwarded_headers.items():
        if key.lower() not in spec_lower:
            out_headers[key] = value

    return out_headers