1212from pydantic import BaseModel , Field
1313from pydantic .networks import AnyUrl
1414from pydantic_settings import BaseSettings , SettingsConfigDict
15+ from typing_extensions import TypeAlias
1516
1617from mcp .server .fastmcp .exceptions import ResourceError
1718from mcp .server .fastmcp .prompts import Prompt , PromptManager
4849
4950logger = get_logger (__name__ )
5051
52+ _Function : TypeAlias = Callable [..., Any ]
53+
5154
5255class Settings (BaseSettings ):
5356 """FastMCP server settings.
@@ -165,7 +168,7 @@ def get_context(self) -> "Context":
165168 return Context (request_context = request_context , fastmcp = self )
166169
167170 async def call_tool (
168- self , name : str , arguments : dict
171+ self , name : str , arguments : dict [ str , Any ]
169172 ) -> Sequence [TextContent | ImageContent | EmbeddedResource ]:
170173 """Call a tool by name with arguments."""
171174 context = self .get_context ()
@@ -214,7 +217,7 @@ async def read_resource(self, uri: AnyUrl | str) -> ReadResourceContents:
214217
215218 def add_tool (
216219 self ,
217- fn : Callable ,
220+ fn : _Function ,
218221 name : str | None = None ,
219222 description : str | None = None ,
220223 ) -> None :
@@ -230,7 +233,9 @@ def add_tool(
230233 """
231234 self ._tool_manager .add_tool (fn , name = name , description = description )
232235
233- def tool (self , name : str | None = None , description : str | None = None ) -> Callable :
236+ def tool (
237+ self , name : str | None = None , description : str | None = None
238+ ) -> Callable [[_Function ], _Function ]:
234239 """Decorator to register a tool.
235240
236241 Tools can optionally request a Context object by adding a parameter with the
@@ -263,7 +268,7 @@ async def async_tool(x: int, context: Context) -> str:
263268 "Did you forget to call it? Use @tool() instead of @tool"
264269 )
265270
266- def decorator (fn : Callable ) -> Callable :
271+ def decorator (fn : _Function ) -> _Function :
267272 self .add_tool (fn , name = name , description = description )
268273 return fn
269274
@@ -284,7 +289,7 @@ def resource(
284289 name : str | None = None ,
285290 description : str | None = None ,
286291 mime_type : str | None = None ,
287- ) -> Callable :
292+ ) -> Callable [[ _Function ], _Function ] :
288293 """Decorator to register a function as a resource.
289294
290295 The function will be called when the resource is read to generate its content.
@@ -328,7 +333,7 @@ async def get_weather(city: str) -> str:
328333 "Did you forget to call it? Use @resource('uri') instead of @resource"
329334 )
330335
331- def decorator (fn : Callable ) -> Callable :
336+ def decorator (fn : _Function ) -> _Function :
332337 # Check if this should be a template
333338 has_uri_params = "{" in uri and "}" in uri
334339 has_func_params = bool (inspect .signature (fn ).parameters )
@@ -376,7 +381,7 @@ def add_prompt(self, prompt: Prompt) -> None:
376381
377382 def prompt (
378383 self , name : str | None = None , description : str | None = None
379- ) -> Callable :
384+ ) -> Callable [[ _Function ], _Function ] :
380385 """Decorator to register a prompt.
381386
382387 Args:
@@ -417,7 +422,7 @@ async def analyze_file(path: str) -> list[Message]:
417422 "Did you forget to call it? Use @prompt() instead of @prompt"
418423 )
419424
420- def decorator (func : Callable ) -> Callable :
425+ def decorator (func : _Function ) -> _Function :
421426 prompt = Prompt .from_function (func , name = name , description = description )
422427 self .add_prompt (prompt )
423428 return func
0 commit comments