@@ -338,6 +338,8 @@ to the `@tool` decorator.
338338``` python
339339""" Example showing structured output with tools."""
340340
341+ from typing import TypedDict
342+
341343from pydantic import BaseModel, Field
342344
343345from mcp.server.fastmcp import FastMCP
@@ -365,12 +367,8 @@ def get_weather(city: str) -> WeatherData:
365367 condition = " sunny" ,
366368 wind_speed = 5.2 ,
367369 )
368- ```
369370
370- _ Full example: [ examples/snippets/servers/structured_output.py] ( https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/snippets/servers/structured_output.py ) _
371- <!-- /snippet-source -->
372371
373- ``` python
374372# Using TypedDict for simpler structures
375373class LocationInfo (TypedDict ):
376374 latitude: float
@@ -437,6 +435,9 @@ def get_temperature(city: str) -> float:
437435 # Returns: {"result": 22.5}
438436```
439437
438+ _ Full example: [ examples/snippets/servers/structured_output.py] ( https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/snippets/servers/structured_output.py ) _
439+ <!-- /snippet-source -->
440+
440441### Prompts
441442
442443Prompts are reusable templates that help LLMs interact with your server effectively:
@@ -814,21 +815,46 @@ uv run mcp install server.py -f .env
814815
815816For advanced scenarios like custom deployments:
816817
818+ <!-- snippet-source examples/snippets/servers/direct_execution.py -->
817819``` python
820+ """ Example showing direct execution of an MCP server.
821+
822+ This is the simplest way to run an MCP server directly.
823+ cd to the `examples/snippets` directory and run:
824+ uv run direct-execution-server
825+ or
826+ python servers/direct_execution.py
827+ """
828+
818829from mcp.server.fastmcp import FastMCP
819830
820831mcp = FastMCP(" My App" )
821832
822- if __name__ == " __main__" :
833+
834+ @mcp.tool ()
835+ def hello (name : str = " World" ) -> str :
836+ """ Say hello to someone."""
837+ return f " Hello, { name} ! "
838+
839+
840+ def main ():
841+ """ Entry point for the direct execution server."""
823842 mcp.run()
843+
844+
845+ if __name__ == " __main__" :
846+ main()
824847```
825848
849+ _ Full example: [ examples/snippets/servers/direct_execution.py] ( https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/snippets/servers/direct_execution.py ) _
850+ <!-- /snippet-source -->
851+
826852Run it with:
827853
828854``` bash
829- python server .py
855+ python servers/direct_execution .py
830856# or
831- uv run mcp run server .py
857+ uv run mcp run servers/direct_execution .py
832858```
833859
834860Note that ` uv run mcp run ` or ` uv run mcp dev ` only supports server using FastMCP and not the low-level server variant.
@@ -1277,9 +1303,30 @@ async def main():
12771303
12781304When building MCP clients, the SDK provides utilities to help display human-readable names for tools, resources, and prompts:
12791305
1306+ <!-- snippet-source examples/snippets/clients/display_utilities.py -->
12801307``` python
1308+ """ Client display utilities example.
1309+
1310+ This example shows how to use the SDK's display utilities to show
1311+ human-readable names for tools, resources, and prompts.
1312+
1313+ cd to the `examples/snippets` directory and run:
1314+ uv run display-utilities-client
1315+ """
1316+
1317+ import asyncio
1318+ import os
1319+
1320+ from mcp import ClientSession, StdioServerParameters
1321+ from mcp.client.stdio import stdio_client
12811322from mcp.shared.metadata_utils import get_display_name
1282- from mcp.client.session import ClientSession
1323+
1324+ # Create server parameters for stdio connection
1325+ server_params = StdioServerParameters(
1326+ command = " uv" , # Using uv to run the server
1327+ args = [" run" , " server" , " fastmcp_quickstart" , " stdio" ],
1328+ env = {" UV_INDEX" : os.environ.get(" UV_INDEX" , " " )},
1329+ )
12831330
12841331
12851332async def display_tools (session : ClientSession):
@@ -1301,8 +1348,39 @@ async def display_resources(session: ClientSession):
13011348 for resource in resources_response.resources:
13021349 display_name = get_display_name(resource)
13031350 print (f " Resource: { display_name} ( { resource.uri} ) " )
1351+
1352+ templates_response = await session.list_resource_templates()
1353+ for template in templates_response.resourceTemplates:
1354+ display_name = get_display_name(template)
1355+ print (f " Resource Template: { display_name} " )
1356+
1357+
1358+ async def run ():
1359+ """ Run the display utilities example."""
1360+ async with stdio_client(server_params) as (read, write):
1361+ async with ClientSession(read, write) as session:
1362+ # Initialize the connection
1363+ await session.initialize()
1364+
1365+ print (" === Available Tools ===" )
1366+ await display_tools(session)
1367+
1368+ print (" \n === Available Resources ===" )
1369+ await display_resources(session)
1370+
1371+
1372+ def main ():
1373+ """ Entry point for the display utilities client."""
1374+ asyncio.run(run())
1375+
1376+
1377+ if __name__ == " __main__" :
1378+ main()
13041379```
13051380
1381+ _ Full example: [ examples/snippets/clients/display_utilities.py] ( https://github.com/modelcontextprotocol/python-sdk/blob/main/examples/snippets/clients/display_utilities.py ) _
1382+ <!-- /snippet-source -->
1383+
13061384The ` get_display_name() ` function implements the proper precedence rules for displaying names:
13071385
13081386- For tools: ` title ` > ` annotations.title ` > ` name `
0 commit comments