π The fast, Pythonic way to build MCP servers and clients.
Fix stale mcp.types imports in examples (#4452)
Jeremiah Lowin3c4303886075
diff --git a/examples/in_memory_proxy_example.py b/examples/in_memory_proxy_example.pyindex 305e9aba2..20cea7360 100644--- a/examples/in_memory_proxy_example.py+++ b/examples/in_memory_proxy_example.py@@ -9,11 +9,10 @@ It illustrates the pattern:import asyncio-from mcp.types import TextContent-from fastmcp import FastMCPfrom fastmcp.client import Clientfrom fastmcp.server import create_proxy+from fastmcp.types import TextContentclass EchoService:@@ -64,8 +63,10 @@ async def main():print(f"\n Calling 'echo' tool via proxy with message: '{message_to_echo}'")try:result = await final_client.call_tool("echo", {"message": message_to_echo})- if result and isinstance(result[0], TextContent):- print(f" Result from proxied 'echo' call: '{result[0].text}'")+ if result.content and isinstance(result.content[0], TextContent):+ print(+ f" Result from proxied 'echo' call: '{result.content[0].text}'"+ )else:print(f" Error: Unexpected result format from proxied 'echo' call: {result}"diff --git a/examples/smart_home/src/smart_home/hub.py b/examples/smart_home/src/smart_home/hub.pyindex 827eae159..30c4f24d2 100644--- a/examples/smart_home/src/smart_home/hub.py+++ b/examples/smart_home/src/smart_home/hub.py@@ -1,7 +1,7 @@-from mcp.types import ToolAnnotationsfrom phue import Bridgefrom fastmcp import FastMCP+from fastmcp.types import ToolAnnotationsfrom smart_home.lights.server import lights_mcpfrom smart_home.settings import settingsdiff --git a/examples/smart_home/src/smart_home/lights/server.py b/examples/smart_home/src/smart_home/lights/server.pyindex 7af3953d0..535b0f10d 100644--- a/examples/smart_home/src/smart_home/lights/server.py+++ b/examples/smart_home/src/smart_home/lights/server.py@@ -7,12 +7,12 @@from typing import Annotated, Any, Literal, TypedDict-from mcp.types import ToolAnnotationsfrom phue.exceptions import PhueExceptionfrom pydantic import Fieldfrom typing_extensions import NotRequiredfrom fastmcp import FastMCP+from fastmcp.types import ToolAnnotationsfrom smart_home.lights.hue_utils import _get_bridge, handle_phue_errordiff --git a/examples/task_elicitation.py b/examples/task_elicitation.pyindex 51f7b046a..2c7852e03 100644--- a/examples/task_elicitation.py+++ b/examples/task_elicitation.py@@ -22,11 +22,10 @@ Requires the `docket` extra (included in dev dependencies).import asynciofrom dataclasses import dataclass-from mcp.types import TextContent-from fastmcp import Context, FastMCPfrom fastmcp.client import Clientfrom fastmcp.server.elicitation import AcceptedElicitation+from fastmcp.types import TextContentmcp = FastMCP("Task Elicitation Demo")diff --git a/examples/tasks/client.py b/examples/tasks/client.pyindex f72814889..ac1dacf7c 100644--- a/examples/tasks/client.py+++ b/examples/tasks/client.py@@ -21,10 +21,11 @@ from pathlib import Pathfrom typing import Annotatedimport cyclopts-from mcp.types import GetTaskResult, TextContent+from mcp_types import GetTaskResultfrom rich.console import Consolefrom fastmcp.client import Client+from fastmcp.types import TextContentconsole = Console()app = cyclopts.App(name="tasks-client", help="FastMCP Tasks Example Client")@@ -43,7 +44,7 @@ def load_server():# Track last message to deduplicate consecutive identical notifications# Note: Docket fires separate events for progress.increment() and progress.set_message(),-# but MCP's statusMessage field only carries the text message (no numerical progress).+# but MCP's status_message field only carries the text message (no numerical progress).# This means we often get duplicate notifications with identical messages._last_notification_message = None@@ -57,10 +58,10 @@ def print_notification(status: GetTaskResult) -> None:global _last_notification_message# Skip if this is the same message we just printed- if status.statusMessage == _last_notification_message:+ if status.status_message == _last_notification_message:return- _last_notification_message = status.statusMessage+ _last_notification_message = status.status_messagecolor = {"working": "yellow",@@ -75,7 +76,7 @@ def print_notification(status: GetTaskResult) -> None:}.get(status.status, "β οΈ")console.print(- f"[{color}]π’ Notification: {status.status} {icon} - {status.statusMessage}[/{color}]"+ f"[{color}]π’ Notification: {status.status} {icon} - {status.status_message}[/{color}]")