@@ -212,13 +212,13 @@ from mcp.server.fastmcp import FastMCP
212
212
mcp = FastMCP(" My App" )
213
213
214
214
215
- @mcp.resource (" config://app" )
215
+ @mcp.resource (" config://app" , title = " Application Configuration " )
216
216
def get_config () -> str :
217
217
""" Static configuration data"""
218
218
return " App configuration here"
219
219
220
220
221
- @mcp.resource (" users://{user_id} /profile" )
221
+ @mcp.resource (" users://{user_id} /profile" , title = " User Profile " )
222
222
def get_user_profile (user_id : str ) -> str :
223
223
""" Dynamic user data"""
224
224
return f " Profile data for user { user_id} "
@@ -235,13 +235,13 @@ from mcp.server.fastmcp import FastMCP
235
235
mcp = FastMCP(" My App" )
236
236
237
237
238
- @mcp.tool ()
238
+ @mcp.tool (title = " BMI Calculator " )
239
239
def calculate_bmi (weight_kg : float , height_m : float ) -> float :
240
240
""" Calculate BMI given weight in kg and height in meters"""
241
241
return weight_kg / (height_m** 2 )
242
242
243
243
244
- @mcp.tool ()
244
+ @mcp.tool (title = " Weather Fetcher " )
245
245
async def fetch_weather (city : str ) -> str :
246
246
""" Fetch current weather for a city"""
247
247
async with httpx.AsyncClient() as client:
@@ -260,12 +260,12 @@ from mcp.server.fastmcp.prompts import base
260
260
mcp = FastMCP(" My App" )
261
261
262
262
263
- @mcp.prompt ()
263
+ @mcp.prompt (title = " Code Review " )
264
264
def review_code (code : str ) -> str :
265
265
return f " Please review this code: \n\n { code} "
266
266
267
267
268
- @mcp.prompt ()
268
+ @mcp.prompt (title = " Debug Assistant " )
269
269
def debug_error (error : str ) -> list[base.Message]:
270
270
return [
271
271
base.UserMessage(" I'm seeing this error:" ),
@@ -918,6 +918,42 @@ async def main():
918
918
tool_result = await session.call_tool(" echo" , {" message" : " hello" })
919
919
```
920
920
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
+
921
957
### OAuth Authentication for Clients
922
958
923
959
The SDK includes [ authorization support] ( https://modelcontextprotocol.io/specification/2025-03-26/basic/authorization ) for connecting to protected MCP servers:
0 commit comments