From 3fb089a5b6d97307077abb9bfdcd82753f95d31a Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Sat, 26 Apr 2025 07:56:36 -0400 Subject: [PATCH] Use PEP 649 annotations --- src/fastmcp/server/server.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/fastmcp/server/server.py b/src/fastmcp/server/server.py index b1547292e..65dd33ea4 100644 --- a/src/fastmcp/server/server.py +++ b/src/fastmcp/server/server.py @@ -1,5 +1,7 @@ """FastMCP - A more ergonomic interface for MCP servers.""" +from __future__ import annotations + import datetime from collections.abc import AsyncIterator, Awaitable, Callable from contextlib import ( @@ -63,7 +65,7 @@ class MountedServer: def __init__( self, prefix: str, - server: "FastMCP", + server: FastMCP, tool_separator: str | None = None, resource_separator: str | None = None, prompt_separator: str | None = None, @@ -149,7 +151,7 @@ class TimedCache: @asynccontextmanager -async def default_lifespan(server: "FastMCP") -> AsyncIterator[Any]: +async def default_lifespan(server: FastMCP) -> AsyncIterator[Any]: """Default lifespan context manager that does nothing. Args: @@ -162,8 +164,8 @@ async def default_lifespan(server: "FastMCP") -> AsyncIterator[Any]: def _lifespan_wrapper( - app: "FastMCP", - lifespan: Callable[["FastMCP"], AbstractAsyncContextManager[LifespanResultT]], + app: FastMCP, + lifespan: Callable[[FastMCP], AbstractAsyncContextManager[LifespanResultT]], ) -> Callable[ [MCPServer[LifespanResultT]], AbstractAsyncContextManager[LifespanResultT] ]: @@ -183,7 +185,7 @@ class FastMCP(Generic[LifespanResultT]): instructions: str | None = None, lifespan: ( Callable[ - ["FastMCP[LifespanResultT]"], + [FastMCP[LifespanResultT]], AbstractAsyncContextManager[LifespanResultT], ] | None @@ -277,7 +279,7 @@ class FastMCP(Generic[LifespanResultT]): self._mcp_server.get_prompt()(self._mcp_get_prompt) self._mcp_server.list_resource_templates()(self._mcp_list_resource_templates) - def get_context(self) -> "Context[ServerSession, LifespanResultT]": + def get_context(self) -> Context[ServerSession, LifespanResultT]: """ Returns a Context object. Note that the context will only be valid during a request; outside a request, most methods will error. @@ -770,7 +772,7 @@ class FastMCP(Generic[LifespanResultT]): def mount( self, prefix: str, - server: "FastMCP[LifespanResultT]", + server: FastMCP[LifespanResultT], tool_separator: str | None = None, resource_separator: str | None = None, prompt_separator: str | None = None, @@ -795,7 +797,7 @@ class FastMCP(Generic[LifespanResultT]): async def import_server( self, prefix: str, - server: "FastMCP[LifespanResultT]", + server: FastMCP[LifespanResultT], tool_separator: str | None = None, resource_separator: str | None = None, prompt_separator: str | None = None, @@ -869,7 +871,7 @@ class FastMCP(Generic[LifespanResultT]): @classmethod def from_openapi( cls, openapi_spec: dict[str, Any], client: httpx.AsyncClient, **settings: Any - ) -> "FastMCPOpenAPI": + ) -> FastMCPOpenAPI: """ Create a FastMCP server from an OpenAPI specification. """ @@ -879,8 +881,8 @@ class FastMCP(Generic[LifespanResultT]): @classmethod def from_fastapi( - cls, app: "Any", name: str | None = None, **settings: Any - ) -> "FastMCPOpenAPI": + cls, app: Any, name: str | None = None, **settings: Any + ) -> FastMCPOpenAPI: """ Create a FastMCP server from a FastAPI application. """ @@ -898,7 +900,7 @@ class FastMCP(Generic[LifespanResultT]): ) @classmethod - def from_client(cls, client: "Client", **settings: Any) -> "FastMCPProxy": + def from_client(cls, client: Client, **settings: Any) -> FastMCPProxy: """ Create a FastMCP proxy server from a FastMCP client. """