π The fast, Pythonic way to build MCP servers and clients.
Stabilize upgraded ty checks (#4526)
Jeremiah Lowin66c0270bc1b2
diff --git a/fastmcp_slim/fastmcp/client/mixins/task_management.py b/fastmcp_slim/fastmcp/client/mixins/task_management.pyindex 533f78304..634a47435 100644--- a/fastmcp_slim/fastmcp/client/mixins/task_management.py+++ b/fastmcp_slim/fastmcp/client/mixins/task_management.py@@ -166,10 +166,8 @@ class ClientTaskManagementMixin:)# Send protocol request- params = PaginatedRequestParams(- cursor=cursor,- limit=limit, # type: ignore[call-arg] # Optional field in MCP SDK # ty:ignore[unknown-argument]- _meta=request_meta, # type: ignore[unknown-argument]+ params = PaginatedRequestParams.model_validate(+ {"cursor": cursor, "limit": limit, "_meta": request_meta})request = ListTasksRequest(params=params)server_response = await self._await_with_session_monitoring(diff --git a/fastmcp_slim/fastmcp/client/sampling/handlers/google_genai.py b/fastmcp_slim/fastmcp/client/sampling/handlers/google_genai.pyindex d79e98b2f..12d6064e6 100644--- a/fastmcp_slim/fastmcp/client/sampling/handlers/google_genai.py+++ b/fastmcp_slim/fastmcp/client/sampling/handlers/google_genai.py@@ -2,6 +2,7 @@import base64from collections.abc import Sequence+from typing import Any, castfrom uuid import uuid4try:@@ -123,7 +124,7 @@ class GoogleGenaiSamplingHandler:max_output_tokens=params.max_tokens,stop_sequences=params.stop_sequences,thinking_config=thinking_config,- tools=google_tools, # ty: ignore[invalid-argument-type]+ tools=cast(Any, google_tools),tool_config=tool_config,),)diff --git a/fastmcp_slim/fastmcp/client/sampling/handlers/openai.py b/fastmcp_slim/fastmcp/client/sampling/handlers/openai.pyindex af54ba099..fb8828e7d 100644--- a/fastmcp_slim/fastmcp/client/sampling/handlers/openai.py+++ b/fastmcp_slim/fastmcp/client/sampling/handlers/openai.py@@ -2,7 +2,7 @@import jsonfrom collections.abc import Iterator, Sequence-from typing import Any, Literal, get_args+from typing import Any, Literal, cast, get_argsfrom mcp import ClientSession, ServerSessionfrom mcp_types import (@@ -507,7 +507,7 @@ class OpenAISamplingHandler:raise ValueError("No content in response from completion")return CreateMessageResultWithTools(- content=content, # type: ignore[arg-type] # ty:ignore[invalid-argument-type]+ content=cast(Any, content),role="assistant",model=chat_completion.model,stop_reason=stop_reason,diff --git a/fastmcp_slim/fastmcp/server/providers/prefab_synthesis.py b/fastmcp_slim/fastmcp/server/providers/prefab_synthesis.pyindex 2ee639d8c..e47bd0391 100644--- a/fastmcp_slim/fastmcp/server/providers/prefab_synthesis.py+++ b/fastmcp_slim/fastmcp/server/providers/prefab_synthesis.py@@ -15,7 +15,7 @@ the app name + tool name). CSP on the resource is the tool'sfrom __future__ import annotations-from typing import TYPE_CHECKING, Any+from typing import TYPE_CHECKING, Any, castfrom fastmcp.server.providers.addressing import (HASH_LENGTH,@@ -142,7 +142,7 @@ def _build_resource_for_tool(tool: Tool) -> Resource | None:uri = f"ui://prefab/tool/{tool_hash}/renderer.html"return TextResource(- uri=uri, # type: ignore[arg-type] # ty:ignore[invalid-argument-type]+ uri=cast(Any, uri),name=f"Prefab Renderer ({tool.name})",text=get_renderer_html(),mime_type=UI_MIME_TYPE,diff --git a/fastmcp_slim/fastmcp/server/server.py b/fastmcp_slim/fastmcp/server/server.pyindex e940ac2a2..110d5fcc0 100644--- a/fastmcp_slim/fastmcp/server/server.py+++ b/fastmcp_slim/fastmcp/server/server.py@@ -107,7 +107,7 @@ logger = get_logger(__name__)def _version_request_meta(version: VersionSpec | None,-) -> dict[str, Any] | None:+) -> mcp_types.RequestParamsMeta | None:if version is None:return None@@ -127,9 +127,8 @@ def _version_request_meta(if not version_value:return None- # SDK v2: request `_meta` is a plain dict (the `Meta` type alias), not the- # old `RequestParams.Meta` nested model.- return {"fastmcp": {"version": version_value}}+ # RequestParamsMeta does not declare application-specific extension keys.+ return cast(mcp_types.RequestParamsMeta, {"fastmcp": {"version": version_value}})# The MCP SDK warns "Tool X not listed, no validation will be performed"@@ -1245,9 +1244,7 @@ class FastMCP(message=mcp_types.CallToolRequestParams(name=name,arguments=arguments or {},- # `_meta` carries the app-level `fastmcp` version key, which the- # reserved-key RequestParamsMeta TypedDict can't express statically.- _meta=_version_request_meta(version), # type: ignore[unknown-argument] # ty: ignore[invalid-argument-type]+ _meta=_version_request_meta(version),),source="client",type="request",@@ -1415,9 +1412,7 @@ class FastMCP(mw_context = MiddlewareContext(message=mcp_types.ReadResourceRequestParams(uri=str(uri),- # `_meta` carries the app-level `fastmcp` version key, which the- # reserved-key RequestParamsMeta TypedDict can't express statically.- _meta=_version_request_meta(version), # type: ignore[unknown-argument] # ty: ignore[invalid-argument-type]+ _meta=_version_request_meta(version),),source="client",type="request",@@ -1612,9 +1607,7 @@ class FastMCP(message=mcp_types.GetPromptRequestParams(name=name,arguments=arguments,- # `_meta` carries the app-level `fastmcp` version key, which the- # reserved-key RequestParamsMeta TypedDict can't express statically.- _meta=_version_request_meta(version), # type: ignore[unknown-argument] # ty: ignore[invalid-argument-type]+ _meta=_version_request_meta(version),),source="client",type="request",diff --git a/tests/server/auth/oauth_proxy/test_authorization.py b/tests/server/auth/oauth_proxy/test_authorization.pyindex 791ffbabd..f3272094e 100644--- a/tests/server/auth/oauth_proxy/test_authorization.py+++ b/tests/server/auth/oauth_proxy/test_authorization.py@@ -16,11 +16,13 @@ class TestOAuthProxyAuthorization:async def test_authorize_creates_transaction(self, oauth_proxy):"""Test that authorize creates transaction and redirects to consent."""- client = OAuthClientInformationFull(- client_id="test-client",- client_secret="test-secret",- redirect_uris=[AnyUrl("http://localhost:54321/callback")],- jwt_signing_key="test-secret", # type: ignore[call-arg] # Optional field in MCP SDK # ty:ignore[unknown-argument]+ client = OAuthClientInformationFull.model_validate(+ {+ "client_id": "test-client",+ "client_secret": "test-secret",+ "redirect_uris": ["http://localhost:54321/callback"],+ "jwt_signing_key": "test-secret",+ })# Register client first (required for consent flow)diff --git a/tests/server/auth/test_cimd.py b/tests/server/auth/test_cimd.pyindex 3cd05c2d1..bf7013990 100644--- a/tests/server/auth/test_cimd.py+++ b/tests/server/auth/test_cimd.py@@ -93,7 +93,9 @@ class TestCIMDDocument:def test_missing_redirect_uris_rejected(self):"""Test that redirect_uris is required for CIMD."""with pytest.raises(ValidationError) as exc_info:- CIMDDocument(client_id=AnyHttpUrl("https://example.com/client.json"))+ CIMDDocument.model_validate(+ {"client_id": "https://example.com/client.json"}+ )assert "redirect_uris" in str(exc_info.value)def test_empty_redirect_uris_rejected(self):diff --git a/tests/test_mcp_config.py b/tests/test_mcp_config.pyindex 13b8b67c9..a33208ca1 100644--- a/tests/test_mcp_config.py+++ b/tests/test_mcp_config.py@@ -715,26 +715,28 @@ async def test_canonical_multi_client_with_transforms(tmp_path: Path):script_path = tmp_path / "test.py"script_path.write_text(server_script)- config = CanonicalMCPConfig(- mcpServers={- "test_1": {- "command": "python",- "args": [str(script_path)],- "tools": { # <--- Will be ignored as it's not valid for a canonical MCPConfig- "add": {- "name": "transformed_add",- "arguments": {- "a": {"name": "transformed_a"},- "b": {"name": "transformed_b"},- },- }+ config = CanonicalMCPConfig.model_validate(+ {+ "mcpServers": {+ "test_1": {+ "command": "python",+ "args": [str(script_path)],+ "tools": { # <--- Will be ignored as it's not valid for a canonical MCPConfig+ "add": {+ "name": "transformed_add",+ "arguments": {+ "a": {"name": "transformed_a"},+ "b": {"name": "transformed_b"},+ },+ }+ },},- },- "test_2": {- "command": "python",- "args": [str(script_path)],- },- } # type: ignore[reportUnknownArgumentType] # ty:ignore[invalid-argument-type]+ "test_2": {+ "command": "python",+ "args": [str(script_path)],+ },+ }+ })client = Client(config)diff --git a/tests/utilities/test_components.py b/tests/utilities/test_components.pyindex cea67ea5f..0e136a51e 100644--- a/tests/utilities/test_components.py+++ b/tests/utilities/test_components.py@@ -170,9 +170,8 @@ class TestFastMCPComponent:def test_tags_deduplication(self):"""Test that tags are deduplicated when passed as a sequence."""- component = FastMCPComponent(- name="test",- tags=["tag1", "tag2", "tag1", "tag2"], # type: ignore[arg-type] # ty:ignore[invalid-argument-type]+ component = FastMCPComponent.model_validate(+ {"name": "test", "tags": ["tag1", "tag2", "tag1", "tag2"]})assert component.tags == {"tag1", "tag2"}