Simplify `src/mcp/shared/metadata_utils.py::get_display_name` logic.
還沒有人認領這個 Issue。
評估
- 難度
- 1/5
- 預估耗時
- 1 小時以內
- 新手友好度
- 88/100
- Issue 類型
- 重構
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- python
研究方向
閱讀 src/mcp/shared/metadata_utils.py::get_display_name,並將其目前的優先順序與提議的調整進行比較。當對每個列出的物件都先檢查 title、Tool annotations.title 仍作為中間 fallback,且 obj.name 仍作為最終 fallback 時,工作即完成。
由索引模型根據 Issue 內容生成。
描述
Current Code Logic
As of now, src/mcp/shared/metadata_utils.py::get_display_name works like this:
def get_display_name(obj: Tool | Resource | Prompt | ResourceTemplate | Implementation) -> str:
"""Get the display name for an MCP object with proper precedence.
This is a client-side utility function designed to help MCP clients display
human-readable names in their user interfaces. When servers provide a 'title'
field, it should be preferred over the programmatic 'name' field for display.
For tools: title > annotations.title > name
For other objects: title > name
Example:
```python
# In a client displaying available tools
tools = await session.list_tools()
for tool in tools.tools:
display_name = get_display_name(tool)
print(f"Available tool: {display_name}")
```
Args:
obj: An MCP object with name and optional title fields
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:
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
However, code logic here can simplify, since title-first precedence applies to every object type.
Only Tool-specific not None annotations.title fallback needs a special middle branch.
Proposed Logical Adjustments
# 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
# All other objects: name as last fallback.
return obj.name
- 主要語言
- Python
- 星號
- 24.3k
- 分支
- 4k
- 平均合併
- 1 天 19 分鐘
- 30 天內合併 PR
- 29
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
modelcontextprotocol/python-sdk 的其他 Issue
-
v1 v2
難度 2/5 1-3 小時 新手友好度 85/100
modelcontextprotocol/python-sdk#3546 · 5 則留言 ·
-
v1 v2
難度 2/5 1-3 小時 新手友好度 76/100
modelcontextprotocol/python-sdk#3545 · 1 則留言 ·
-
v1 v2
難度 1/5 1 小時以內 新手友好度 91/100
modelcontextprotocol/python-sdk#3508 · 2 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 64/100
modelcontextprotocol/python-sdk#3504 ·
-
v1 v2
難度 2/5 1-3 小時 新手友好度 82/100
modelcontextprotocol/python-sdk#3492 · 1 則留言 ·
查看 modelcontextprotocol/python-sdk 的全部 Issue
相似的 Issue
-
🐛 Bug 🔔 Pending processing
難度 2/5 1-3 小時 新手友好度 84/100
jumpserver/jumpserver#17584 ·
-
link-check link-check:sphinx-theme
難度 2/5 1-3 小時 新手友好度 72/100
-
難度 2/5 1-3 小時 新手友好度 90/100
modelscope/DiffSynth-Studio#1702 ·
-
難度 2/5 1-3 小時 新手友好度 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
難度 2/5 1-3 小時 新手友好度 88/100
OpenHands/extensions#626 · 1 則留言 ·