Skip to content

Commit f1df2ac

Browse files
committed
refactor: simplify get_display_name control flow
Remove duplicate title check by moving universal title-first logic outside the isinstance(Tool) conditional. This improves readability and maintainability while preserving all existing behavior. Fixes #3480 - All 12 existing test assertions pass - 100% code coverage maintained - Type checking clean (pyright) - Linting clean (ruff)
1 parent 6affe5c commit f1df2ac

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

src/mcp/shared/metadata_utils.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,14 @@ def get_display_name(obj: Tool | Resource | Prompt | ResourceTemplate | Implemen
3232
Returns:
3333
The display name to use for UI presentation
3434
"""
35-
if isinstance(obj, Tool):
36-
# Tools have special precedence: title > annotations.title > name
37-
if hasattr(obj, "title") and obj.title is not None:
38-
return obj.title
39-
if obj.annotations and hasattr(obj.annotations, "title") and obj.annotations.title is not None:
35+
# All objects prefer title first
36+
if hasattr(obj, "title") and obj.title is not None:
37+
return obj.title
38+
39+
# Tools have special fallback: check annotations.title
40+
if isinstance(obj, Tool) and obj.annotations:
41+
if hasattr(obj.annotations, "title") and obj.annotations.title is not None:
4042
return obj.annotations.title
41-
return obj.name
42-
else:
43-
# All other objects: title > name
44-
if hasattr(obj, "title") and obj.title is not None:
45-
return obj.title
46-
return obj.name
43+
44+
# Universal fallback to name
45+
return obj.name

0 commit comments

Comments
 (0)