{"record":{"id":"f28f15ea571590b5","repo":"PrefectHQ/fastmcp","slug":"the-anthropic-package-is-not-installed-install","errorCode":null,"errorMessage":"The `anthropic` package is not installed. Install it with `pip install 'fastmcp-slim[anthropic]'` or add `anthropic` to your dependencies.","messagePattern":"The `anthropic` package is not installed\\. Install it with `pip install 'fastmcp-slim\\[anthropic\\]'` or add `anthropic` to your dependencies\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/client/sampling/handlers/anthropic.py","lineNumber":42,"sourceCode":"    from anthropic import AsyncAnthropic\n    from anthropic.types import (\n        Base64ImageSourceParam,\n        ImageBlockParam,\n        Message,\n        MessageParam,\n        TextBlock,\n        TextBlockParam,\n        ToolParam,\n        ToolResultBlockParam,\n        ToolUseBlock,\n        ToolUseBlockParam,\n    )\n    from anthropic.types.model_param import ModelParam\n    from anthropic.types.tool_choice_any_param import ToolChoiceAnyParam\n    from anthropic.types.tool_choice_auto_param import ToolChoiceAutoParam\n    from anthropic.types.tool_choice_param import ToolChoiceParam\nexcept ImportError as e:\n    raise ImportError(\n        \"The `anthropic` package is not installed. \"\n        \"Install it with `pip install 'fastmcp-slim[anthropic]'` or add `anthropic` to your dependencies.\"\n    ) from e\n\n__all__ = [\"AnthropicSamplingHandler\"]\n\n# Anthropic supports these image MIME types\n_ANTHROPIC_IMAGE_MEDIA_TYPES = frozenset(\n    {\"image/jpeg\", \"image/png\", \"image/gif\", \"image/webp\"}\n)\n\n\ndef _image_content_to_anthropic_block(content: ImageContent) -> ImageBlockParam:\n    \"\"\"Convert MCP ImageContent to Anthropic ImageBlockParam.\"\"\"\n    if content.mime_type not in _ANTHROPIC_IMAGE_MEDIA_TYPES:\n        raise ValueError(\n            f\"Unsupported image MIME type for Anthropic: {content.mime_type!r}. \"\n            f\"Supported types: {', '.join(sorted(_ANTHROPIC_IMAGE_MEDIA_TYPES))}\"","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/client/sampling/handlers/anthropic.py#L24-L60","documentation":"ImportError raised at module import of the Anthropic sampling handler when the `anthropic` package is absent. The optional integration is guarded so FastMCP itself works without the SDK, failing fast with an actionable install hint instead of a cryptic ModuleNotFoundError.","triggerScenarios":"Importing `fastmcp.client.sampling.handlers.anthropic` or using `AnthropicSamplingHandler` without `anthropic` installed in the environment.","commonSituations":"Deployed environment missing optional extras; installed `fastmcp-slim` base package without `[anthropic]`; a fresh container/venv that didn't replicate dev dependencies.","solutions":["Install the extra: `pip install 'fastmcp-slim[anthropic]'`","Or `pip install anthropic` / add `anthropic` to your dependency manifest","If using uv: `uv add anthropic` or `uv sync --extra anthropic`","Verify with `python -c \"import anthropic\"` after install"],"exampleFix":"// before\npip install fastmcp-slim\nfrom fastmcp.client.sampling.handlers.anthropic import AnthropicSamplingHandler  # ImportError\n\n// after\npip install 'fastmcp-slim[anthropic]'\nfrom fastmcp.client.sampling.handlers.anthropic import AnthropicSamplingHandler  # ok","handlingStrategy":"fallback","validationCode":"try:\n    import anthropic  # noqa: F401\n    ANTHROPIC_AVAILABLE = True\nexcept ImportError:\n    ANTHROPIC_AVAILABLE = False","typeGuard":null,"tryCatchPattern":"try:\n    from fastmcp.client.sampling.handlers.anthropic import AnthropicSamplingHandler\nexcept ImportError:\n    AnthropicSamplingHandler = None\n\nhandler = AnthropicSamplingHandler(...) if AnthropicSamplingHandler else DefaultFallbackHandler()","preventionTips":["Install optional extras: pip install 'fastmcp-slim[anthropic]'","Pin the extra in your dependency manifest (pyproject/requirements)","Guard imports of optional handlers in shared library code","Smoke-test imports in CI for every deployment environment"],"tags":["dependency","optional-extra","anthropic","import"],"backgroundTag":"missing-optional-dependency","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}