From bef59e858434c3139eda64557daf3b96c4c75d13 Mon Sep 17 00:00:00 2001 From: aifanatic Date: Tue, 27 Oct 2026 07:48:31 -0500 Subject: [PATCH] Python: move the TypeSafe MCP sample to mcp 2.x The MCP sample pinned mcp<2, but Agent Framework's MCP client imports mcp.Client from mcp 2.x, so the documented command failed to open the MCP session. With mcp 2.x installed instead, the weather server failed to start because FastMCP was renamed to MCPServer. Port the server to MCPServer, keep its tool returning plain text, and pin both scripts and the README command to mcp>=2.2.0,<3 like the rest of the repository. Co-Authored-By: Claude Opus 5.5 --- python/packages/typesafe/samples/README.md | 2 +- python/packages/typesafe/samples/mcp_function_calling.py | 2 +- python/packages/typesafe/samples/mcp_weather_server.py | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/python/packages/typesafe/samples/README.md b/python/packages/typesafe/samples/README.md index 49debea6403..d73d1123ab3 100644 --- a/python/packages/typesafe/samples/README.md +++ b/python/packages/typesafe/samples/README.md @@ -84,7 +84,7 @@ uv run --env-file .env --package agent-framework-typesafe \ uv run --env-file .env --package agent-framework-typesafe \ python packages/typesafe/samples/function_calling.py -uv run --with "mcp>=1.27.0,<2" --env-file .env --package agent-framework-typesafe \ +uv run --with "mcp>=2.2.0,<3" --env-file .env --package agent-framework-typesafe \ python packages/typesafe/samples/mcp_function_calling.py uv run --env-file .env --package agent-framework-typesafe \ diff --git a/python/packages/typesafe/samples/mcp_function_calling.py b/python/packages/typesafe/samples/mcp_function_calling.py index 5d256cf47b2..26f3a2cb2a9 100644 --- a/python/packages/typesafe/samples/mcp_function_calling.py +++ b/python/packages/typesafe/samples/mcp_function_calling.py @@ -2,7 +2,7 @@ # requires-python = ">=3.10" # dependencies = [ # "agent-framework-typesafe", -# "mcp>=1.27.0,<2", +# "mcp>=2.2.0,<3", # ] # /// diff --git a/python/packages/typesafe/samples/mcp_weather_server.py b/python/packages/typesafe/samples/mcp_weather_server.py index a4d14ca7c73..07697cd6283 100644 --- a/python/packages/typesafe/samples/mcp_weather_server.py +++ b/python/packages/typesafe/samples/mcp_weather_server.py @@ -1,7 +1,7 @@ # /// script # requires-python = ">=3.10" # dependencies = [ -# "mcp>=1.27.0,<2", +# "mcp>=2.2.0,<3", # ] # /// @@ -11,7 +11,7 @@ from typing import Literal -from mcp.server.fastmcp import FastMCP +from mcp.server.mcpserver import MCPServer """ Local stdio MCP server used by mcp_function_calling.py. @@ -22,10 +22,10 @@ """ # 1. Define a small deterministic MCP server and one compatible closed-set tool. -server = FastMCP(name="typesafe-weather-sample") +server = MCPServer(name="typesafe-weather-sample") -@server.tool(name="get_weather", description="Get weather for Seattle or Paris.") +@server.tool(name="get_weather", description="Get weather for Seattle or Paris.", structured_output=False) def get_weather(city: Literal["Seattle", "Paris"], detailed: bool) -> str: """Return deterministic sample weather.""" suffix = " with a detailed hourly forecast" if detailed else ""