modelcontextprotocol / modelcontextprotocol/python-sdk

Simplify `src/mcp/shared/metadata_utils.py::get_display_name` logic.

オープン 初心者向け
#3,480 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Python
スター
24.3k
フォーク
4k
平均マージ
1日 1時間
マージ済み PR(30日)
31

説明

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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

src/mcp/shared/metadata_utils.py::get_display_name を読み、現在の優先順位を提案されている調整と比較します。すべての一覧化されたオブジェクトで最初に title が確認され、Tool annotations.title が中間のフォールバックとして残り、obj.name が最後のフォールバックとして残れば、作業は完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
backend-api-design
issue の種類
リファクタリング
難易度
1/5
見積もり時間
1時間未満
活発さ
活発
明瞭さ
明確に書かれている
初心者へのやさしさ
88/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。