ClientSessionGroup silently drops resources with the same name and different URIs

未關閉
#3,976 2 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
45/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python
領域
api, backend

研究方向

Start by locating ClientSessionGroup and how it registers resources, then read the existing duplicate-key handling for resources from different servers. Reproduce the report with two resources named Introduction at different URIs and check the group contents and error behavior. Done means registration reports the collision and does not silently drop either resource.

由索引模型根據 Issue 內容生成。

描述

Initial Checks
Release line

2.x (current stable)

Description

I ran the example below on mcp 2.3.0. The client listed both resources named Introduction: docs://library/intro and docs://archive/intro. Adding that same session to a ClientSessionGroup succeeded, but the group contained only {'Introduction': 'docs://archive/intro'}. There was no indication that the library resource had been dropped.

The group already rejects duplicate keys across servers. I expected it to report the same collision when both resources came from one server. I reran the example with a local patch and got INVALID_PARAMS (-32602) for the name Introduction. The client still listed both URIs, and the group remained empty.

Codex helped investigate, wrote the local patch and regression tests, and drafted this report. I ran both versions and checked the output.

Example Code
import anyio
from mcp import Client, ClientSessionGroup, MCPError
from mcp.server import MCPServer

server = MCPServer("Guides")


@server.resource("docs://library/intro", name="Introduction")
def library_intro() -> str:
    return "Library guide"


@server.resource("docs://archive/intro", name="Introduction")
def archive_intro() -> str:
    return "Archive guide"


async def main() -> None:
    async with Client(server) as client:
        resources = (await client.list_resources()).resources
        print("Client listed:", sorted((r.name, str(r.uri)) for r in resources))
        assert client.server_info is not None
        group = ClientSessionGroup()
        try:
            await group.connect_with_session(client.server_info, client.session)
        except MCPError as error:
            print("Group rejected registration:", error.error.code, error)
        print("Group resources:", {key: str(r.uri) for key, r in group.resources.items()})


anyio.run(main)
Python & MCP Python SDK
Python 3.14.4, mcp 2.3.0. Also reproduced on main at 77001c96.
主要語言
Python
星號
25k
分支
4.2k
平均合併
10 分鐘
30 天內合併 PR
1

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

modelcontextprotocol/python-sdk 的其他 Issue

查看 modelcontextprotocol/python-sdk 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。