From d16c69a46d38229f52ffe33d0ee1a6a3ba9eb447 Mon Sep 17 00:00:00 2001 From: "claude[bot]" <41898282+claude[bot]@users.noreply.github.com> Date: Fri, 3 Oct 2025 17:48:52 +0000 Subject: [PATCH] Add Any annotations to args and kwargs Fixes strict type checker warnings by adding explicit Any type annotations to *args and **kwargs parameters throughout the codebase. Changes: - tool_transform.py: forward(), forward_raw(), and _forward() - client.py: All __init__ overload signatures - proxy.py: All __init__ methods in proxy classes - oauth_proxy.py: __init__ method - low_level.py: LowLevelServer __init__ - tests.py: run_server_in_process() Co-authored-by: William Easton --- src/fastmcp/client/client.py | 22 +++++++++++----------- src/fastmcp/server/auth/oauth_proxy.py | 5 ++++- src/fastmcp/server/low_level.py | 2 +- src/fastmcp/server/proxy.py | 12 ++++++------ src/fastmcp/tools/tool_transform.py | 6 +++--- src/fastmcp/utilities/tests.py | 4 ++-- 6 files changed, 27 insertions(+), 24 deletions(-) diff --git a/src/fastmcp/client/client.py b/src/fastmcp/client/client.py index 68716a801..c1957c277 100644 --- a/src/fastmcp/client/client.py +++ b/src/fastmcp/client/client.py @@ -155,38 +155,38 @@ class Client(Generic[ClientTransportT]): """ @overload - def __init__(self: Client[T], transport: T, *args, **kwargs) -> None: ... + def __init__(self: Client[T], transport: T, *args: Any, **kwargs: Any) -> None: ... @overload def __init__( self: Client[SSETransport | StreamableHttpTransport], transport: AnyUrl, - *args, - **kwargs, + *args: Any, + **kwargs: Any, ) -> None: ... @overload def __init__( self: Client[FastMCPTransport], transport: FastMCP | FastMCP1Server, - *args, - **kwargs, + *args: Any, + **kwargs: Any, ) -> None: ... @overload def __init__( self: Client[PythonStdioTransport | NodeStdioTransport], transport: Path, - *args, - **kwargs, + *args: Any, + **kwargs: Any, ) -> None: ... @overload def __init__( self: Client[MCPConfigTransport], transport: MCPConfig | dict[str, Any], - *args, - **kwargs, + *args: Any, + **kwargs: Any, ) -> None: ... @overload @@ -198,8 +198,8 @@ class Client(Generic[ClientTransportT]): | StreamableHttpTransport ], transport: str, - *args, - **kwargs, + *args: Any, + **kwargs: Any, ) -> None: ... def __init__( diff --git a/src/fastmcp/server/auth/oauth_proxy.py b/src/fastmcp/server/auth/oauth_proxy.py index 97f5e7526..8400aa68a 100644 --- a/src/fastmcp/server/auth/oauth_proxy.py +++ b/src/fastmcp/server/auth/oauth_proxy.py @@ -89,7 +89,10 @@ class ProxyDCRClient(OAuthClientInformationFull): """ def __init__( - self, *args, allowed_redirect_uri_patterns: list[str] | None = None, **kwargs + self, + *args: Any, + allowed_redirect_uri_patterns: list[str] | None = None, + **kwargs: Any, ): """Initialize with allowed redirect URI patterns. diff --git a/src/fastmcp/server/low_level.py b/src/fastmcp/server/low_level.py index 7dd3e9d4b..eb9e87c2a 100644 --- a/src/fastmcp/server/low_level.py +++ b/src/fastmcp/server/low_level.py @@ -12,7 +12,7 @@ from mcp.server.models import InitializationOptions class LowLevelServer(_Server[LifespanResultT, RequestT]): - def __init__(self, *args, **kwargs): + def __init__(self, *args: Any, **kwargs: Any): super().__init__(*args, **kwargs) # FastMCP servers support notifications for all components self.notification_options = NotificationOptions( diff --git a/src/fastmcp/server/proxy.py b/src/fastmcp/server/proxy.py index 57ec5facf..6847befcd 100644 --- a/src/fastmcp/server/proxy.py +++ b/src/fastmcp/server/proxy.py @@ -69,7 +69,7 @@ class ProxyManagerMixin: class ProxyToolManager(ToolManager, ProxyManagerMixin): """A ToolManager that sources its tools from a remote client in addition to local and mounted tools.""" - def __init__(self, client_factory: ClientFactoryT, **kwargs): + def __init__(self, client_factory: ClientFactoryT, **kwargs: Any): super().__init__(**kwargs) self.client_factory = client_factory @@ -123,7 +123,7 @@ class ProxyToolManager(ToolManager, ProxyManagerMixin): class ProxyResourceManager(ResourceManager, ProxyManagerMixin): """A ResourceManager that sources its resources from a remote client in addition to local and mounted resources.""" - def __init__(self, client_factory: ClientFactoryT, **kwargs): + def __init__(self, client_factory: ClientFactoryT, **kwargs: Any): super().__init__(**kwargs) self.client_factory = client_factory @@ -204,7 +204,7 @@ class ProxyResourceManager(ResourceManager, ProxyManagerMixin): class ProxyPromptManager(PromptManager, ProxyManagerMixin): """A PromptManager that sources its prompts from a remote client in addition to local and mounted prompts.""" - def __init__(self, client_factory: ClientFactoryT, **kwargs): + def __init__(self, client_factory: ClientFactoryT, **kwargs: Any): super().__init__(**kwargs) self.client_factory = client_factory @@ -258,7 +258,7 @@ class ProxyTool(Tool, MirroredComponent): A Tool that represents and executes a tool on a remote server. """ - def __init__(self, client: Client, **kwargs): + def __init__(self, client: Client, **kwargs: Any): super().__init__(**kwargs) self._client = client @@ -354,7 +354,7 @@ class ProxyTemplate(ResourceTemplate, MirroredComponent): A ResourceTemplate that represents and creates resources from a remote server template. """ - def __init__(self, client: Client, **kwargs): + def __init__(self, client: Client, **kwargs: Any): super().__init__(**kwargs) self._client = client @@ -640,7 +640,7 @@ class StatefulProxyClient(ProxyClient[ClientTransportT]): Note that it is essential to ensure that the proxy server itself is also stateful. """ - def __init__(self, *args, **kwargs): + def __init__(self, *args: Any, **kwargs: Any): super().__init__(*args, **kwargs) self._caches: dict[ServerSession, Client[ClientTransportT]] = {} diff --git a/src/fastmcp/tools/tool_transform.py b/src/fastmcp/tools/tool_transform.py index c1bd5b69e..0cc5ed960 100644 --- a/src/fastmcp/tools/tool_transform.py +++ b/src/fastmcp/tools/tool_transform.py @@ -34,7 +34,7 @@ _current_tool: ContextVar[TransformedTool | None] = ContextVar( # type: ignore[ ) -async def forward(**kwargs) -> ToolResult: +async def forward(**kwargs: Any) -> ToolResult: """Forward to parent tool with argument transformation applied. This function can only be called from within a transformed tool's custom @@ -64,7 +64,7 @@ async def forward(**kwargs) -> ToolResult: return await tool.forwarding_fn(**kwargs) -async def forward_raw(**kwargs) -> ToolResult: +async def forward_raw(**kwargs: Any) -> ToolResult: """Forward directly to parent tool without transformation. This function bypasses all argument transformation and validation, calling the parent @@ -681,7 +681,7 @@ class TransformedTool(Tool): schema = compress_schema(schema, prune_defs=True) # Create forwarding function that closes over everything it needs - async def _forward(**kwargs): + async def _forward(**kwargs: Any): # Validate arguments valid_args = set(new_props.keys()) provided_args = set(kwargs.keys()) diff --git a/src/fastmcp/utilities/tests.py b/src/fastmcp/utilities/tests.py index 9d0efeaca..ce175e221 100644 --- a/src/fastmcp/utilities/tests.py +++ b/src/fastmcp/utilities/tests.py @@ -75,11 +75,11 @@ def _run_server(mcp_server: FastMCP, transport: Literal["sse"], port: int) -> No @contextmanager def run_server_in_process( server_fn: Callable[..., None], - *args, + *args: Any, provide_host_and_port: bool = True, host: str = "127.0.0.1", port: int | None = None, - **kwargs, + **kwargs: Any, ) -> Generator[str, None, None]: """ Context manager that runs a FastMCP server in a separate process and