ClientSessionGroup silently drops resources with the same name and different URIs

Aperta
#3,976 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
api, backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.
Lingua principale
Python
Stelle
25k
Fork
4.2k
Merge medio
10m
PR unite (30g)
1

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di modelcontextprotocol/python-sdk

Tutte le issue di modelcontextprotocol/python-sdk

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.