forked from modelcontextprotocol/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_httpx.py
More file actions
37 lines (27 loc) · 1.08 KB
/
Copy path_httpx.py
File metadata and controls
37 lines (27 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""Compatibility shim: prefer `httpx2`, fall back to `httpx` with a deprecation warning.
Mirrors the pattern from
[Kludex/starlette@508023b](https://github.com/Kludex/starlette/commit/508023b488b649d97c091eb60da1d8ef3636ee06)
and [pydantic/pydantic-ai#5664](https://github.com/pydantic/pydantic-ai/pull/5664).
`mcp` declares `httpx` (not `httpx2`) as a dependency, so unless the user installs `httpx2`
explicitly the fallback path is exercised. The MCP v2 cut will drop the fallback and bump the
dependency to `httpx2`.
The warning is emitted at module-import time and fires at most once per process via Python's
module cache.
"""
from __future__ import annotations
import warnings
from typing import TYPE_CHECKING
from mcp.shared.exceptions import MCPDeprecationWarning
__all__ = ["httpx"]
if TYPE_CHECKING:
import httpx as httpx
else:
try:
import httpx2 as httpx
except ImportError:
import httpx
warnings.warn(
"Using `httpx` with `mcp` is deprecated; install `httpx2` instead.",
MCPDeprecationWarning,
stacklevel=2,
)