From a7e9b709192d19a9c014d95ef4fbedc35befeeec Mon Sep 17 00:00:00 2001 From: nate nowack Date: Mon, 3 Aug 2026 10:53:23 -0500 Subject: [PATCH] Fix static analysis with latest ty (#4739) * Fix upgrade static analysis Generated with Codex * Preserve concrete transport return types Generated with Codex * Avoid widening transport return types Generated with Codex * Model transforming transport return types Generated with Codex * Exclude standalone screenshot examples from ty Generated with Codex --- fastmcp_slim/fastmcp/mcp_config.py | 9 ++++++--- pyproject.toml | 7 ++++--- tests/test_mcp_config.py | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/fastmcp_slim/fastmcp/mcp_config.py b/fastmcp_slim/fastmcp/mcp_config.py index c09d9f3c6..b18ea1a3e 100644 --- a/fastmcp_slim/fastmcp/mcp_config.py +++ b/fastmcp_slim/fastmcp/mcp_config.py @@ -45,6 +45,7 @@ from fastmcp import _install_hints if TYPE_CHECKING: from fastmcp.client.transports import ( ClientTransport, + FastMCPTransport, SSETransport, StdioTransport, StreamableHttpTransport, @@ -153,7 +154,7 @@ class _TransformingMCPServerMixin(BaseModel): return wrapped_mcp_server, transport - def to_transport(self) -> ClientTransport: + def to_transport(self) -> FastMCPTransport: """Get the transport for the transforming MCP server.""" try: from fastmcp.client.transports import FastMCPTransport @@ -209,7 +210,7 @@ class StdioMCPServer(BaseModel): model_config = ConfigDict(extra="allow") # Preserve unknown fields - def to_transport(self) -> StdioTransport: + def to_transport(self) -> StdioTransport | FastMCPTransport: from fastmcp.client.transports import StdioTransport return StdioTransport( @@ -261,7 +262,9 @@ class RemoteMCPServer(BaseModel): extra="allow", arbitrary_types_allowed=True ) # Preserve unknown fields - def to_transport(self) -> StreamableHttpTransport | SSETransport: + def to_transport( + self, + ) -> StreamableHttpTransport | SSETransport | FastMCPTransport: from fastmcp.client.transports import ( SSETransport, StreamableHttpTransport, diff --git a/pyproject.toml b/pyproject.toml index 005194822..27b3596b0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -157,6 +157,8 @@ exclude = [ "examples/smart_home", # needs phue "examples/apps/qr_server", # needs qrcode "examples/providers/sqlite", # needs aiosqlite + "examples/fastmcp_config_demo", # needs pyautogui, Pillow + "examples/screenshot.py", # needs pyautogui, Pillow "examples/memory.py", # needs asyncpg, numpy, pydantic_ai, pgvector "examples/get_file.py", # needs aiohttp ] @@ -165,9 +167,8 @@ exclude = [ python-version = "3.10" [tool.ty.analysis] -# prefab_ui is the apps SDK; pyautogui/PIL are optional runtime deps used only -# inside example tool bodies (screenshot demos) and are not installed here. -replace-imports-with-any = ["prefab_ui.**", "pyautogui", "PIL", "PIL.**"] +# prefab_ui is the apps SDK and is not installed here. +replace-imports-with-any = ["prefab_ui.**"] [tool.ty.rules] division-by-zero = "warn" diff --git a/tests/test_mcp_config.py b/tests/test_mcp_config.py index a35af2287..93d673e61 100644 --- a/tests/test_mcp_config.py +++ b/tests/test_mcp_config.py @@ -96,7 +96,7 @@ class InMemoryStdioMCPServer(StdioMCPServer): mcp: FastMCP command: str = "in-memory" - def to_transport(self) -> FastMCPTransport: # ty: ignore[invalid-method-override] + def to_transport(self) -> FastMCPTransport: return FastMCPTransport(mcp=self.mcp)