1212from pydantic import BaseModel , Field
1313from pydantic .networks import AnyUrl
1414from pydantic_settings import BaseSettings , SettingsConfigDict
15- from typing_extensions import TypeAlias
1615
1716from mcp .server .fastmcp .exceptions import ResourceError
1817from mcp .server .fastmcp .prompts import Prompt , PromptManager
2625from mcp .server .stdio import stdio_server
2726from mcp .shared .context import RequestContext
2827from mcp .types import (
28+ AnyFunction ,
2929 EmbeddedResource ,
3030 GetPromptResult ,
3131 ImageContent ,
4949
5050logger = get_logger (__name__ )
5151
52- _Function : TypeAlias = Callable [..., Any ]
53-
5452
5553class Settings (BaseSettings ):
5654 """FastMCP server settings.
@@ -217,7 +215,7 @@ async def read_resource(self, uri: AnyUrl | str) -> ReadResourceContents:
217215
218216 def add_tool (
219217 self ,
220- fn : _Function ,
218+ fn : AnyFunction ,
221219 name : str | None = None ,
222220 description : str | None = None ,
223221 ) -> None :
@@ -235,7 +233,7 @@ def add_tool(
235233
236234 def tool (
237235 self , name : str | None = None , description : str | None = None
238- ) -> Callable [[_Function ], _Function ]:
236+ ) -> Callable [[AnyFunction ], AnyFunction ]:
239237 """Decorator to register a tool.
240238
241239 Tools can optionally request a Context object by adding a parameter with the
@@ -268,7 +266,7 @@ async def async_tool(x: int, context: Context) -> str:
268266 "Did you forget to call it? Use @tool() instead of @tool"
269267 )
270268
271- def decorator (fn : _Function ) -> _Function :
269+ def decorator (fn : AnyFunction ) -> AnyFunction :
272270 self .add_tool (fn , name = name , description = description )
273271 return fn
274272
@@ -289,7 +287,7 @@ def resource(
289287 name : str | None = None ,
290288 description : str | None = None ,
291289 mime_type : str | None = None ,
292- ) -> Callable [[_Function ], _Function ]:
290+ ) -> Callable [[AnyFunction ], AnyFunction ]:
293291 """Decorator to register a function as a resource.
294292
295293 The function will be called when the resource is read to generate its content.
@@ -333,7 +331,7 @@ async def get_weather(city: str) -> str:
333331 "Did you forget to call it? Use @resource('uri') instead of @resource"
334332 )
335333
336- def decorator (fn : _Function ) -> _Function :
334+ def decorator (fn : AnyFunction ) -> AnyFunction :
337335 # Check if this should be a template
338336 has_uri_params = "{" in uri and "}" in uri
339337 has_func_params = bool (inspect .signature (fn ).parameters )
@@ -381,7 +379,7 @@ def add_prompt(self, prompt: Prompt) -> None:
381379
382380 def prompt (
383381 self , name : str | None = None , description : str | None = None
384- ) -> Callable [[_Function ], _Function ]:
382+ ) -> Callable [[AnyFunction ], AnyFunction ]:
385383 """Decorator to register a prompt.
386384
387385 Args:
@@ -422,7 +420,7 @@ async def analyze_file(path: str) -> list[Message]:
422420 "Did you forget to call it? Use @prompt() instead of @prompt"
423421 )
424422
425- def decorator (func : _Function ) -> _Function :
423+ def decorator (func : AnyFunction ) -> AnyFunction :
426424 prompt = Prompt .from_function (func , name = name , description = description )
427425 self .add_prompt (prompt )
428426 return func
0 commit comments