fix(langchain): widen langchain.mcp client type to Client[Any]

`load_mcp_tools`, `convert_mcp_tool`, and `call_tool_with_elicitation` annotated
their FastMCP client as `Client[ClientTransport]`. FastMCP's `Client` is invariant
in its transport type parameter, so no concrete client a caller constructs (e.g.
`Client(url)`, which infers a transport union) satisfies `Client[ClientTransport]` —
every real caller hits a mypy arg-type error. Widen the annotation to `Client[Any]`
and drop the now-unused `ClientTransport` import. Pure static-typing change; runtime
behavior is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Sydney RunkleandClaude Opus 4.8 committed 2026-08-20 16:31:46 -07:00
1 parent c08e4a106c
commit d96cfbdc6f
2 files changed
+3 -5

No files matched your search

@@ -23,7 +23,6 @@ from typing_extensions import NotRequired, TypedDict
if TYPE_CHECKING:
from fastmcp import Client
from fastmcp.client.transports import ClientTransport
from mcp.types import CallToolResult, InputResponses
_VALID_ACTIONS = ("accept", "decline", "cancel")
@@ -45,7 +44,7 @@ class MCPElicitation(TypedDict):
async def call_tool_with_elicitation(
client: Client[ClientTransport],
client: Client[Any],
name: str,
arguments: dict[str, Any],
) -> CallToolResult:
+2 -3
View File
@@ -26,7 +26,6 @@ if TYPE_CHECKING:
from collections.abc import Sequence
from fastmcp import Client
from fastmcp.client.transports import ClientTransport
from langchain_core.tools import BaseTool
from mcp.types import ContentBlock as MCPContentBlock
from mcp.types import Tool as MCPTool
@@ -51,7 +50,7 @@ class _ToolResult(Protocol):
async def load_mcp_tools(
client: Client[ClientTransport],
client: Client[Any],
*,
elicitation: ElicitationMode | None = None,
) -> list[BaseTool]:
@@ -79,7 +78,7 @@ async def load_mcp_tools(
def convert_mcp_tool(
tool: MCPTool,
client: Client[ClientTransport],
client: Client[Any],
*,
elicitation: ElicitationMode | None = None,
) -> BaseTool: