From 3d31b9a890817224a5fd4db9dbd6d74aa1f3868e Mon Sep 17 00:00:00 2001 From: ege-arhan Date: Sun, 13 Sep 2026 23:06:01 +0000 Subject: [PATCH] Simplify get_display_name logic Deduplicate title-first precedence shared across all object types. Only Tool-specific annotations.title remains as a special middle branch. Fixes #3480 --- src/mcp/shared/metadata_utils.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/mcp/shared/metadata_utils.py b/src/mcp/shared/metadata_utils.py index b646133477..9181ee5c50 100644 --- a/src/mcp/shared/metadata_utils.py +++ b/src/mcp/shared/metadata_utils.py @@ -32,15 +32,14 @@ def get_display_name(obj: Tool | Resource | Prompt | ResourceTemplate | Implemen Returns: The display name to use for UI presentation """ - if isinstance(obj, Tool): - # Tools have special precedence: title > annotations.title > name - if hasattr(obj, "title") and obj.title is not None: - return obj.title - if obj.annotations and hasattr(obj.annotations, "title") and obj.annotations.title is not None: + # All objects have title-first precedence, regardless of being a Tool or not. + if hasattr(obj, "title") and obj.title is not None: + return obj.title + + # Special middle branch for Tool-specific not None `annotations.title`. + if isinstance(obj, Tool) and obj.annotations: + if hasattr(obj.annotations, "title") and obj.annotations.title is not None: return obj.annotations.title - return obj.name - else: - # All other objects: title > name - if hasattr(obj, "title") and obj.title is not None: - return obj.title - return obj.name + + # All other objects: name as last fallback. + return obj.name