Skip to content

Update _client_info on the ClientSession upon initialization with serverInfo #1018

Closed

Description

@mconflitti-pbc

Description

Currently, when a ClientSession is created and no client_info arg is passed, it uses the default client info object. My expectation would be that upon session initialization, the clientinfo data is updated with the value returned from the MCP server it connected to. This information is available within the InitializationResult but not used by the SDK so the only way to get that info is to grab it during initialization manually.

Example of grabbing info like the name defined by the MCP server when the client connects:

            transport = await self.exit_stack.enter_async_context(
                streamablehttp_client(server_url, headers=headers)
            )
            self.read, self.write, _ = transport
            self.session = await self.exit_stack.enter_async_context(
                ClientSession(self.read, self.write)
            )

            server = await self.session.initialize()
            self.name = server.serverInfo.name  # <====

ClientSession does the following:

class ClientSession(
    BaseSession[
        types.ClientRequest,
        types.ClientNotification,
        types.ClientResult,
        types.ServerRequest,
        types.ServerNotification,
    ]
):
    def __init__(
        self,
        read_stream: MemoryObjectReceiveStream[SessionMessage | Exception],
        write_stream: MemoryObjectSendStream[SessionMessage],
        # ...
        client_info: types.Implementation | None = None,
    ) -> None:
        super().__init__(...)
        self._client_info = client_info or DEFAULT_CLIENT_INFO # <<<<<<
       # ...

    async def initialize(self) -> types.InitializeResult:
        # ...
        result = await self.send_request(
            types.ClientRequest(
                types.InitializeRequest(
                    method="initialize",
                    params=types.InitializeRequestParams(
                        protocolVersion=types.LATEST_PROTOCOL_VERSION,
                        capabilities=types.ClientCapabilities(
                            sampling=sampling,
                            experimental=None,
                            roots=roots,
                        ),
                        clientInfo=self._client_info,
                    ),
                )
            ),
            types.InitializeResult,
        )
        # ...
        return result

The result is returned but ClientSession._client_info is not updated with the values coming from the result. The simplest thing would just be to set _client_info to serverInfo.

References

No response

Activity

  1. shivama205 commented on Mar 4, 2026

    @shivama205
    Contributor

    I'd like to pick this up. Previous PRs:

    I've submitted #2211 following the same pattern as get_server_capabilities(): store server_info from InitializeResult on the session and expose it via get_server_info(). Includes unit tests.

  2. added a commit that references this issue on Mar 4, 2026
    a3d5a83
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

    P3Nice to haves, rare edge casesenhancementRequest for a new feature that's not currently supportedgood first issueGood for newcomersready for workEnough information for someone to start working on

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions