Skip to content

Commit cb17c8b

Browse files
committed
Allow generic parameters to Context on resources
1 parent 0790305 commit cb17c8b

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/mcp/server/fastmcp/resources/templates.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import inspect
66
import re
77
from collections.abc import Callable
8-
from typing import TYPE_CHECKING, Any
8+
from typing import TYPE_CHECKING, Any, get_origin
99

1010
from pydantic import BaseModel, Field, validate_call
1111

@@ -58,7 +58,9 @@ def from_function(
5858

5959
sig = inspect.signature(fn)
6060
for param_name, param in sig.parameters.items():
61-
if param.annotation is Context:
61+
if get_origin(param.annotation) is not None:
62+
continue
63+
if issubclass(param.annotation, Context):
6264
context_kwarg = param_name
6365
break
6466

0 commit comments

Comments
 (0)