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
This commit is contained in:
nate nowack 2026-08-03 10:53:23 -05:00 committed by GitHub
commit a7e9b70919
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 11 additions and 7 deletions

View file

@ -45,6 +45,7 @@ from fastmcp import _install_hints
if TYPE_CHECKING: if TYPE_CHECKING:
from fastmcp.client.transports import ( from fastmcp.client.transports import (
ClientTransport, ClientTransport,
FastMCPTransport,
SSETransport, SSETransport,
StdioTransport, StdioTransport,
StreamableHttpTransport, StreamableHttpTransport,
@ -153,7 +154,7 @@ class _TransformingMCPServerMixin(BaseModel):
return wrapped_mcp_server, transport return wrapped_mcp_server, transport
def to_transport(self) -> ClientTransport: def to_transport(self) -> FastMCPTransport:
"""Get the transport for the transforming MCP server.""" """Get the transport for the transforming MCP server."""
try: try:
from fastmcp.client.transports import FastMCPTransport from fastmcp.client.transports import FastMCPTransport
@ -209,7 +210,7 @@ class StdioMCPServer(BaseModel):
model_config = ConfigDict(extra="allow") # Preserve unknown fields 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 from fastmcp.client.transports import StdioTransport
return StdioTransport( return StdioTransport(
@ -261,7 +262,9 @@ class RemoteMCPServer(BaseModel):
extra="allow", arbitrary_types_allowed=True extra="allow", arbitrary_types_allowed=True
) # Preserve unknown fields ) # Preserve unknown fields
def to_transport(self) -> StreamableHttpTransport | SSETransport: def to_transport(
self,
) -> StreamableHttpTransport | SSETransport | FastMCPTransport:
from fastmcp.client.transports import ( from fastmcp.client.transports import (
SSETransport, SSETransport,
StreamableHttpTransport, StreamableHttpTransport,

View file

@ -157,6 +157,8 @@ exclude = [
"examples/smart_home", # needs phue "examples/smart_home", # needs phue
"examples/apps/qr_server", # needs qrcode "examples/apps/qr_server", # needs qrcode
"examples/providers/sqlite", # needs aiosqlite "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/memory.py", # needs asyncpg, numpy, pydantic_ai, pgvector
"examples/get_file.py", # needs aiohttp "examples/get_file.py", # needs aiohttp
] ]
@ -165,9 +167,8 @@ exclude = [
python-version = "3.10" python-version = "3.10"
[tool.ty.analysis] [tool.ty.analysis]
# prefab_ui is the apps SDK; pyautogui/PIL are optional runtime deps used only # prefab_ui is the apps SDK and is not installed here.
# inside example tool bodies (screenshot demos) and are not installed here. replace-imports-with-any = ["prefab_ui.**"]
replace-imports-with-any = ["prefab_ui.**", "pyautogui", "PIL", "PIL.**"]
[tool.ty.rules] [tool.ty.rules]
division-by-zero = "warn" division-by-zero = "warn"

View file

@ -96,7 +96,7 @@ class InMemoryStdioMCPServer(StdioMCPServer):
mcp: FastMCP mcp: FastMCP
command: str = "in-memory" command: str = "in-memory"
def to_transport(self) -> FastMCPTransport: # ty: ignore[invalid-method-override] def to_transport(self) -> FastMCPTransport:
return FastMCPTransport(mcp=self.mcp) return FastMCPTransport(mcp=self.mcp)