Skip to content

datarobot_genai.drmcp.test_utils.clients.anthropic

anthropic

Anthropic LLM MCP Client implementation (example).

This is an example implementation showing how easy it is to add a new LLM provider. Anthropic's API is OpenAI-compatible, so we can use the OpenAI SDK with their endpoint.

AnthropicMCPClient

Bases: BaseLLMMCPClient

Client for interacting with LLMs via MCP using Anthropic Claude.

Note: Elicitation is handled at the protocol level by FastMCP's ctx.elicit(). Tools using FastMCP's built-in elicitation will work automatically.

Example
config = {
    "anthropic_api_key": "sk-ant-...",
    "model": "claude-3-5-sonnet-20241022",
}
client = AnthropicMCPClient(str(config))
Source code in datarobot_genai/drmcp/test_utils/clients/anthropic.py
class AnthropicMCPClient(BaseLLMMCPClient):
    """
    Client for interacting with LLMs via MCP using Anthropic Claude.

    Note: Elicitation is handled at the protocol level by FastMCP's ctx.elicit().
    Tools using FastMCP's built-in elicitation will work automatically.

    Example:
        ```python
        config = {
            "anthropic_api_key": "sk-ant-...",
            "model": "claude-3-5-sonnet-20241022",
        }
        client = AnthropicMCPClient(str(config))
        ```
    """

    def __init__(
        self,
        config: str | dict,
    ):
        """
        Initialize the LLM MCP client.

        Args:
            config: Configuration string or dict with:
                - anthropic_api_key: Anthropic API key
                - model: Model name (**required**)
                - save_llm_responses: Whether to save responses (default: True)
        """
        super().__init__(config)

    def _create_llm_client(self, config_dict: dict) -> tuple[openai.OpenAI, str | None]:
        """Create the LLM client for Anthropic (OpenAI-compatible endpoint)."""
        anthropic_api_key = config_dict.get("anthropic_api_key")
        model = config_dict.get("model")

        # Anthropic provides an OpenAI-compatible endpoint
        client = openai.OpenAI(
            api_key=anthropic_api_key,
            base_url="https://api.anthropic.com/v1",
        )
        return client, model

__init__

__init__(config: str | dict)

Initialize the LLM MCP client.

Parameters:

Name Type Description Default
config str | dict

Configuration string or dict with: - anthropic_api_key: Anthropic API key - model: Model name (required) - save_llm_responses: Whether to save responses (default: True)

required
Source code in datarobot_genai/drmcp/test_utils/clients/anthropic.py
def __init__(
    self,
    config: str | dict,
):
    """
    Initialize the LLM MCP client.

    Args:
        config: Configuration string or dict with:
            - anthropic_api_key: Anthropic API key
            - model: Model name (**required**)
            - save_llm_responses: Whether to save responses (default: True)
    """
    super().__init__(config)