Skip to content

ClientSessionGroup silently drops resources with the same name and different URIs #3976

Backlog

Description

@saggl

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.

Activity

  1. Suman-00X commented on Dec 5, 2026

    @Suman-00X

    Root cause: _aggregate_components keys resources_temp by resource name, so a second resource with the same name from the same server overwrites the first; the duplicate check after it only compares against components already in the group.

    A possible fix: detect same-server name collisions while building the temp dicts and raise the same INVALID_PARAMS error used for cross-server duplicates (the group stays unchanged), covering prompts and tools too, with regression tests for each.

    This comment was drafted with AI assistance (Claude Code).

  2. saggl commented on Dec 5, 2026

    @saggl
    Author

    Thanks, that matches what I saw. One detail from the patch I tested: it records duplicate names while collecting the components, then raises INVALID_PARAMS after the listing try/except blocks, before updating the group. Those blocks catch MCPError, so raising inside one would turn the collision into a warning and let registration continue.

    I’m happy to submit the tested patch if a maintainer would like me to take this on.

    Codex helped draft this reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions