12
12
from mcp .server .fastmcp .resources .types import FunctionResource , Resource
13
13
from mcp .server .fastmcp .utilities .context_injection import find_context_parameter , inject_context
14
14
from mcp .server .fastmcp .utilities .func_metadata import func_metadata
15
+ from mcp .types import Icon
15
16
16
17
if TYPE_CHECKING :
17
18
from mcp .server .fastmcp .server import Context
@@ -27,6 +28,7 @@ class ResourceTemplate(BaseModel):
27
28
title : str | None = Field (description = "Human-readable title of the resource" , default = None )
28
29
description : str | None = Field (description = "Description of what the resource does" )
29
30
mime_type : str = Field (default = "text/plain" , description = "MIME type of the resource content" )
31
+ icons : list [Icon ] | None = Field (default = None , description = "Optional list of icons for the resource template" )
30
32
fn : Callable [..., Any ] = Field (exclude = True )
31
33
parameters : dict [str , Any ] = Field (description = "JSON schema for function parameters" )
32
34
context_kwarg : str | None = Field (None , description = "Name of the kwarg that should receive context" )
@@ -40,6 +42,7 @@ def from_function(
40
42
title : str | None = None ,
41
43
description : str | None = None ,
42
44
mime_type : str | None = None ,
45
+ icons : list [Icon ] | None = None ,
43
46
context_kwarg : str | None = None ,
44
47
) -> ResourceTemplate :
45
48
"""Create a template from a function."""
@@ -67,6 +70,7 @@ def from_function(
67
70
title = title ,
68
71
description = description or fn .__doc__ or "" ,
69
72
mime_type = mime_type or "text/plain" ,
73
+ icons = icons ,
70
74
fn = fn ,
71
75
parameters = parameters ,
72
76
context_kwarg = context_kwarg ,
@@ -103,7 +107,7 @@ async def create_resource(
103
107
title = self .title ,
104
108
description = self .description ,
105
109
mime_type = self .mime_type ,
106
- icons = None , # Resource templates don't support icons
110
+ icons = self . icons ,
107
111
fn = lambda : result , # Capture result in closure
108
112
)
109
113
except Exception as e :
0 commit comments