2525from mcp .server .stdio import stdio_server
2626from mcp .shared .context import RequestContext
2727from mcp .types import (
28+ AnyFunction ,
2829 EmbeddedResource ,
2930 GetPromptResult ,
3031 ImageContent ,
@@ -165,7 +166,7 @@ def get_context(self) -> "Context":
165166 return Context (request_context = request_context , fastmcp = self )
166167
167168 async def call_tool (
168- self , name : str , arguments : dict
169+ self , name : str , arguments : dict [ str , Any ]
169170 ) -> Sequence [TextContent | ImageContent | EmbeddedResource ]:
170171 """Call a tool by name with arguments."""
171172 context = self .get_context ()
@@ -214,7 +215,7 @@ async def read_resource(self, uri: AnyUrl | str) -> ReadResourceContents:
214215
215216 def add_tool (
216217 self ,
217- fn : Callable ,
218+ fn : AnyFunction ,
218219 name : str | None = None ,
219220 description : str | None = None ,
220221 ) -> None :
@@ -230,7 +231,9 @@ def add_tool(
230231 """
231232 self ._tool_manager .add_tool (fn , name = name , description = description )
232233
233- def tool (self , name : str | None = None , description : str | None = None ) -> Callable :
234+ def tool (
235+ self , name : str | None = None , description : str | None = None
236+ ) -> Callable [[AnyFunction ], AnyFunction ]:
234237 """Decorator to register a tool.
235238
236239 Tools can optionally request a Context object by adding a parameter with the
@@ -263,7 +266,7 @@ async def async_tool(x: int, context: Context) -> str:
263266 "Did you forget to call it? Use @tool() instead of @tool"
264267 )
265268
266- def decorator (fn : Callable ) -> Callable :
269+ def decorator (fn : AnyFunction ) -> AnyFunction :
267270 self .add_tool (fn , name = name , description = description )
268271 return fn
269272
@@ -284,7 +287,7 @@ def resource(
284287 name : str | None = None ,
285288 description : str | None = None ,
286289 mime_type : str | None = None ,
287- ) -> Callable :
290+ ) -> Callable [[ AnyFunction ], AnyFunction ] :
288291 """Decorator to register a function as a resource.
289292
290293 The function will be called when the resource is read to generate its content.
@@ -328,7 +331,7 @@ async def get_weather(city: str) -> str:
328331 "Did you forget to call it? Use @resource('uri') instead of @resource"
329332 )
330333
331- def decorator (fn : Callable ) -> Callable :
334+ def decorator (fn : AnyFunction ) -> AnyFunction :
332335 # Check if this should be a template
333336 has_uri_params = "{" in uri and "}" in uri
334337 has_func_params = bool (inspect .signature (fn ).parameters )
@@ -376,7 +379,7 @@ def add_prompt(self, prompt: Prompt) -> None:
376379
377380 def prompt (
378381 self , name : str | None = None , description : str | None = None
379- ) -> Callable :
382+ ) -> Callable [[ AnyFunction ], AnyFunction ] :
380383 """Decorator to register a prompt.
381384
382385 Args:
@@ -417,7 +420,7 @@ async def analyze_file(path: str) -> list[Message]:
417420 "Did you forget to call it? Use @prompt() instead of @prompt"
418421 )
419422
420- def decorator (func : Callable ) -> Callable :
423+ def decorator (func : AnyFunction ) -> AnyFunction :
421424 prompt = Prompt .from_function (func , name = name , description = description )
422425 self .add_prompt (prompt )
423426 return func
0 commit comments