{"record":{"id":"8a3cf4f8863fdb39","repo":"PrefectHQ/fastmcp","slug":"passing-an-httpx-asyncclient-to-openapiprovider-is","errorCode":null,"errorMessage":"Passing an httpx.AsyncClient to OpenAPIProvider is deprecated and will be removed in a future release. Pass an httpx2.AsyncClient instead.","messagePattern":"Passing an httpx\\.AsyncClient to OpenAPIProvider is deprecated and will be removed in a future release\\. Pass an httpx2\\.AsyncClient instead\\.","errorType":"console","errorClass":"FastMCPDeprecationWarning","httpStatus":null,"severity":"warning","filePath":"fastmcp_slim/fastmcp/server/providers/openapi/provider.py","lineNumber":119,"sourceCode":"                Legacy httpx clients are temporarily accepted with a deprecation\n                warning.\n            route_maps: Optional list of RouteMap objects defining route mappings\n            route_map_fn: Optional callable for advanced route type mapping\n            mcp_component_fn: Optional callable for component customization\n            mcp_names: Optional dictionary mapping operationId to component names\n            tags: Optional set of tags to add to all components\n            validate_output: If True (default), tools use the output schema\n                extracted from the OpenAPI spec for response validation. If\n                False, a permissive schema is used instead, allowing any\n                response structure while still returning structured JSON.\n        \"\"\"\n        super().__init__()\n\n        self._owns_client = client is None\n        if client is None:\n            client = self._create_default_client(openapi_spec)\n        elif _is_legacy_httpx_client(client):\n            warnings.warn(\n                \"Passing an httpx.AsyncClient to OpenAPIProvider is deprecated \"\n                \"and will be removed in a future release. Pass an \"\n                \"httpx2.AsyncClient instead.\",\n                FastMCPDeprecationWarning,\n                stacklevel=2,\n            )\n        self._client = client\n        self._mcp_component_fn = mcp_component_fn\n        self._validate_output = validate_output\n\n        # Keep track of names to detect collisions\n        self._used_names: dict[str, Counter[str]] = {\n            \"tool\": Counter(),\n            \"resource\": Counter(),\n            \"resource_template\": Counter(),\n            \"prompt\": Counter(),\n        }\n","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/server/providers/openapi/provider.py#L101-L137","documentation":"OpenAPIProvider now expects an `httpx2.AsyncClient`. Passing the legacy `httpx.AsyncClient` still works but is deprecated and will be removed, so FastMCP emits a `FastMCPDeprecationWarning` when it detects a legacy client instance.","triggerScenarios":"`OpenAPIProvider(openapi_spec=spec, client=httpx.AsyncClient(...))` — any legacy httpx client passed explicitly (passing `client=None` builds the default and is fine).","commonSituations":"Code written before the httpx2 migration; shared HTTP client pools still typed as `httpx.AsyncClient`; dependency-injection containers that construct httpx clients generically.","solutions":["Construct the client from `httpx2` instead: `client = httpx2.AsyncClient(base_url=...)` and pass that.","If you manage a shared client, register it as `httpx2.AsyncClient` at the injection site.","Check `_is_legacy_httpx_client` conditions and update all call paths constructing the client.","Pin/monitor the FastMCP changelog to finish the migration before the removal release."],"exampleFix":"// before\nclient = httpx.AsyncClient(base_url=\"https://api.example.com\")\nprovider = OpenAPIProvider(openapi_spec=spec, client=client)\n// after\nimport httpx2\nclient = httpx2.AsyncClient(base_url=\"https://api.example.com\")\nprovider = OpenAPIProvider(openapi_spec=spec, client=client)","handlingStrategy":"type-guard","validationCode":"import httpx, httpx2\nassert isinstance(client, httpx2.AsyncClient) and not isinstance(client, httpx.AsyncClient), \"pass an httpx2.AsyncClient to OpenAPIProvider\"\n","typeGuard":"import httpx\ndef is_legacy_httpx_client(client) -> bool:\n    return isinstance(client, httpx.AsyncClient)  # mirror of _is_legacy_httpx_client\n","tryCatchPattern":"import warnings\nfrom fastmcp.exceptions import FastMCPDeprecationWarning\nwith warnings.catch_warnings(record=True) as caught:\n    warnings.simplefilter(\"always\", FastMCPDeprecationWarning)\n    provider = OpenAPIProvider(openapi_spec=spec, client=client)\nif any(\"httpx2.AsyncClient\" in str(w.message) for w in caught):\n    raise TypeError(\"OpenAPIProvider requires an httpx2.AsyncClient\")","preventionTips":["Type-hint client parameters as httpx2.AsyncClient everywhere","Audit DI containers for legacy httpx.AsyncClient construction","Track the FastMCP changelog for the removal release"],"tags":["python","deprecation","openapi","httpx"],"backgroundTag":"deprecated-client-class","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}