@@ -212,13 +212,13 @@ from mcp.server.fastmcp import FastMCP
212212mcp = FastMCP(" My App" )
213213
214214
215- @mcp.resource (" config://app" )
215+ @mcp.resource (" config://app" , title = " Application Configuration " )
216216def get_config () -> str :
217217 """ Static configuration data"""
218218 return " App configuration here"
219219
220220
221- @mcp.resource (" users://{user_id} /profile" )
221+ @mcp.resource (" users://{user_id} /profile" , title = " User Profile " )
222222def get_user_profile (user_id : str ) -> str :
223223 """ Dynamic user data"""
224224 return f " Profile data for user { user_id} "
@@ -235,13 +235,13 @@ from mcp.server.fastmcp import FastMCP
235235mcp = FastMCP(" My App" )
236236
237237
238- @mcp.tool ()
238+ @mcp.tool (title = " BMI Calculator " )
239239def calculate_bmi (weight_kg : float , height_m : float ) -> float :
240240 """ Calculate BMI given weight in kg and height in meters"""
241241 return weight_kg / (height_m** 2 )
242242
243243
244- @mcp.tool ()
244+ @mcp.tool (title = " Weather Fetcher " )
245245async def fetch_weather (city : str ) -> str :
246246 """ Fetch current weather for a city"""
247247 async with httpx.AsyncClient() as client:
@@ -260,12 +260,12 @@ from mcp.server.fastmcp.prompts import base
260260mcp = FastMCP(" My App" )
261261
262262
263- @mcp.prompt ()
263+ @mcp.prompt (title = " Code Review " )
264264def review_code (code : str ) -> str :
265265 return f " Please review this code: \n\n { code} "
266266
267267
268- @mcp.prompt ()
268+ @mcp.prompt (title = " Debug Assistant " )
269269def debug_error (error : str ) -> list[base.Message]:
270270 return [
271271 base.UserMessage(" I'm seeing this error:" ),
@@ -918,6 +918,42 @@ async def main():
918918 tool_result = await session.call_tool(" echo" , {" message" : " hello" })
919919```
920920
921+ ### Client Display Utilities
922+
923+ When building MCP clients, the SDK provides utilities to help display human-readable names for tools, resources, and prompts:
924+
925+ ``` python
926+ from mcp.shared.metadata_utils import get_display_name
927+ from mcp.client.session import ClientSession
928+
929+
930+ async def display_tools (session : ClientSession):
931+ """ Display available tools with human-readable names"""
932+ tools_response = await session.list_tools()
933+
934+ for tool in tools_response.tools:
935+ # get_display_name() returns the title if available, otherwise the name
936+ display_name = get_display_name(tool)
937+ print (f " Tool: { display_name} " )
938+ if tool.description:
939+ print (f " { tool.description} " )
940+
941+
942+ async def display_resources (session : ClientSession):
943+ """ Display available resources with human-readable names"""
944+ resources_response = await session.list_resources()
945+
946+ for resource in resources_response.resources:
947+ display_name = get_display_name(resource)
948+ print (f " Resource: { display_name} ( { resource.uri} ) " )
949+ ```
950+
951+ The ` get_display_name() ` function implements the proper precedence rules for displaying names:
952+ - For tools: ` title ` > ` annotations.title ` > ` name `
953+ - For other objects: ` title ` > ` name `
954+
955+ This ensures your client UI shows the most user-friendly names that servers provide.
956+
921957### OAuth Authentication for Clients
922958
923959The SDK includes [ authorization support] ( https://modelcontextprotocol.io/specification/2025-03-26/basic/authorization ) for connecting to protected MCP servers:
0 commit comments