Skip to content

Commit f212f8f

Browse files
committed
fix: remove deprecation code
1 parent cbb0e37 commit f212f8f

File tree

4 files changed

+37
-334
lines changed

4 files changed

+37
-334
lines changed
Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,54 @@
11
import inspect
2-
import warnings
32
from collections.abc import Callable
43
from typing import Any, TypeVar, get_type_hints
54

6-
7-
def issue_deprecation_warning(func: Callable[..., Any], request_type: type) -> None:
8-
"""
9-
Issue a deprecation warning for handlers that don't use the new request parameter style.
10-
"""
11-
func_name = getattr(func, "__name__", str(func))
12-
warnings.warn(
13-
f"Handler '{func_name}' should accept a '{request_type.__name__}' parameter. "
14-
"Support for handlers without this parameter will be removed in a future version.",
15-
DeprecationWarning,
16-
stacklevel=4,
17-
)
18-
19-
205
T = TypeVar("T")
216
R = TypeVar("R")
227

238

24-
def create_call_wrapper(func: Callable[..., R], request_type: type[T]) -> tuple[Callable[[T], R], bool]:
9+
def create_call_wrapper(func: Callable[..., R], request_type: type[T]) -> Callable[[T], R]:
2510
"""
2611
Create a wrapper function that knows how to call func with the request object.
2712
28-
Returns a tuple of (wrapper_func, should_deprecate):
29-
- wrapper_func: A function that takes the request and calls func appropriately
30-
- should_deprecate: True if a deprecation warning should be issued
13+
Returns a wrapper function that takes the request and calls func appropriately.
3114
3215
The wrapper handles three calling patterns:
3316
1. Positional-only parameter typed as request_type (no default): func(req)
3417
2. Positional/keyword parameter typed as request_type (no default): func(**{param_name: req})
35-
3. No request parameter or parameter with default (deprecated): func()
18+
3. No request parameter or parameter with default: func()
3619
"""
3720
try:
3821
sig = inspect.signature(func)
3922
type_hints = get_type_hints(func)
4023
except (ValueError, TypeError, NameError):
41-
# Can't inspect signature or resolve type hints, assume no request parameter (deprecated)
42-
return lambda _: func(), True
24+
return lambda _: func()
4325

4426
# Check for positional-only parameter typed as request_type
4527
for param_name, param in sig.parameters.items():
4628
if param.kind == inspect.Parameter.POSITIONAL_ONLY:
4729
param_type = type_hints.get(param_name)
4830
if param_type == request_type:
49-
# Check if it has a default - if so, treat as old style (deprecated)
31+
# Check if it has a default - if so, treat as old style
5032
if param.default is not inspect.Parameter.empty:
51-
return lambda _: func(), True
33+
return lambda _: func()
5234
# Found positional-only parameter with correct type and no default
53-
return lambda req: func(req), False
35+
return lambda req: func(req)
5436

5537
# Check for any positional/keyword parameter typed as request_type
5638
for param_name, param in sig.parameters.items():
5739
if param.kind in (inspect.Parameter.POSITIONAL_OR_KEYWORD, inspect.Parameter.KEYWORD_ONLY):
5840
param_type = type_hints.get(param_name)
5941
if param_type == request_type:
60-
# Check if it has a default - if so, treat as old style (deprecated)
42+
# Check if it has a default - if so, treat as old style
6143
if param.default is not inspect.Parameter.empty:
62-
return lambda _: func(), True
44+
return lambda _: func()
6345

6446
# Found keyword parameter with correct type and no default
6547
# Need to capture param_name in closure properly
6648
def make_keyword_wrapper(name: str) -> Callable[[Any], Any]:
6749
return lambda req: func(**{name: req})
6850

69-
return make_keyword_wrapper(param_name), False
51+
return make_keyword_wrapper(param_name)
7052

71-
# No request parameter found - use old style (deprecated)
72-
return lambda _: func(), True
53+
# No request parameter found - use old style
54+
return lambda _: func()

src/mcp/server/lowlevel/server.py

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,7 @@ def decorator(
236236
):
237237
logger.debug("Registering handler for PromptListRequest")
238238

239-
# Create wrapper that knows how to call func with the request
240-
wrapper, _ = create_call_wrapper(func, types.ListPromptsRequest)
241-
242-
# if should_deprecate:
243-
# issue_deprecation_warning(func, types.ListPromptsRequest)
239+
wrapper = create_call_wrapper(func, types.ListPromptsRequest)
244240

245241
async def handler(req: types.ListPromptsRequest):
246242
result = await wrapper(req)
@@ -278,12 +274,7 @@ def decorator(
278274
):
279275
logger.debug("Registering handler for ListResourcesRequest")
280276

281-
# Create wrapper that knows how to call func with the request
282-
wrapper, _ = create_call_wrapper(func, types.ListResourcesRequest)
283-
284-
# TODO: Decide whether we want this sort of deprecation in a later PR
285-
# if should_deprecate:
286-
# issue_deprecation_warning(func, types.ListResourcesRequest)
277+
wrapper = create_call_wrapper(func, types.ListResourcesRequest)
287278

288279
async def handler(req: types.ListResourcesRequest):
289280
result = await wrapper(req)
@@ -416,12 +407,7 @@ def decorator(
416407
):
417408
logger.debug("Registering handler for ListToolsRequest")
418409

419-
# Create wrapper that knows how to call func with the request
420-
wrapper, _ = create_call_wrapper(func, types.ListToolsRequest)
421-
422-
# TODO: Decide whether we want this sort of deprecation in a later PR
423-
# if should_deprecate:
424-
# issue_deprecation_warning(func, types.ListToolsRequest)
410+
wrapper = create_call_wrapper(func, types.ListToolsRequest)
425411

426412
async def handler(req: types.ListToolsRequest):
427413
result = await wrapper(req)

tests/server/lowlevel/test_deprecation_warnings.py

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

0 commit comments

Comments
 (0)