Skip to content

Commit 240b701

Browse files
dsfacciniclaude
andcommitted
Move MCPDeprecationWarning to mcp.shared.exceptions per @Kludex review
Drops the dedicated _warnings.py — the side-effect-free-module constraint that justified it is moot now that the filter matches by message only. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 3de2aa1 commit 240b701

5 files changed

Lines changed: 17 additions & 29 deletions

File tree

pyproject.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,11 @@ filterwarnings = [
208208
"ignore:getargs.*The 'u' format is deprecated:DeprecationWarning",
209209
# `mcp` prefers `httpx2`; importing `mcp.shared._httpx` warns when falling back to
210210
# `httpx`. The lockfile pins `httpx`, so CI always exercises the fallback. We match on
211-
# the message string only — naming the category would force pytest to import
212-
# `mcp.shared._warnings`, which cascades through `mcp/__init__.py` and triggers the
213-
# very warning we're trying to filter (the same trap pydantic-ai documents). The
214-
# dedicated test in `tests/shared/test_httpx_shim.py` covers emission. Remove this entry
215-
# once `httpx2` is the dependency and the fallback is dropped.
211+
# the message string only — naming the category would force pytest's filter parser to
212+
# `__import__` the module hosting `MCPDeprecationWarning`, which cascades through
213+
# `mcp/__init__.py` and triggers the very warning we're trying to filter (the same trap
214+
# pydantic-ai documents). The dedicated test in `tests/shared/test_httpx_shim.py` covers
215+
# emission. Remove this entry once `httpx2` is the dependency and the fallback is dropped.
216216
"ignore:Using `httpx` with `mcp` is deprecated",
217217
]
218218

src/mcp/shared/_httpx.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,17 @@
99
dependency to `httpx2`.
1010
1111
The warning is emitted at module-import time and fires at most once per process via Python's
12-
module cache. `MCPDeprecationWarning` lives in `mcp.shared._warnings` so pytest's
13-
`filterwarnings` parser can resolve the category symbol without importing this shim.
12+
module cache.
1413
"""
1514

1615
from __future__ import annotations
1716

1817
import warnings
1918
from typing import TYPE_CHECKING
2019

21-
from mcp.shared._warnings import MCPDeprecationWarning
20+
from mcp.shared.exceptions import MCPDeprecationWarning
2221

23-
__all__ = ["MCPDeprecationWarning", "httpx"]
22+
__all__ = ["httpx"]
2423

2524

2625
if TYPE_CHECKING:

src/mcp/shared/_warnings.py

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/mcp/shared/exceptions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ def __str__(self) -> str:
4141
return self.message
4242

4343

44+
class MCPDeprecationWarning(UserWarning):
45+
"""Deprecation warning emitted by the `mcp` package.
46+
47+
Subclasses `UserWarning` (not `DeprecationWarning`) so it is visible by default —
48+
`DeprecationWarning` is silenced at the Python level for non-`__main__` callers.
49+
"""
50+
51+
4452
class StatelessModeNotSupported(RuntimeError):
4553
"""Raised when attempting to use a method that is not supported in stateless mode.
4654

tests/shared/test_httpx_shim.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import pytest
1515

16-
from mcp.shared._warnings import MCPDeprecationWarning
16+
from mcp.shared.exceptions import MCPDeprecationWarning
1717

1818

1919
def _force_reimport_shim() -> None:

0 commit comments

Comments
 (0)