Repository navigation
Update _client_info on the ClientSession upon initialization with serverInfo #1018
Copy link
Copy link
Closed
Labels
P3Nice to haves, rare edge casesNice to haves, rare edge casesenhancementRequest for a new feature that's not currently supportedRequest for a new feature that's not currently supportedgood first issueGood for newcomersGood for newcomersready for workEnough information for someone to start working onEnough information for someone to start working on
Description
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 resultThe 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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P3Nice to haves, rare edge casesNice to haves, rare edge casesenhancementRequest for a new feature that's not currently supportedRequest for a new feature that's not currently supportedgood first issueGood for newcomersGood for newcomersready for workEnough information for someone to start working onEnough information for someone to start working on
Activity
shivama205 commentedon Mar 4, 2026
I'd like to pick this up. Previous PRs:
_client_infowith server info, which conflates client and server identityserver_infoseparately, which is the correct approachI've submitted #2211 following the same pattern as
get_server_capabilities(): storeserver_infofromInitializeResulton the session and expose it viaget_server_info(). Includes unit tests.feat: store server_info on ClientSession during initialization
feat(client): store full InitializeResult as server_params
refactor(client): rename to initialize_result, decompose Client prope…
feat(client): store full InitializeResult as server_params
refactor(client): rename to initialize_result, decompose Client prope…
simplify(client): collapse to single initialize_result proxy
feat(client): store full InitializeResult as server_params
refactor(client): rename to initialize_result, decompose Client prope…
simplify(client): collapse to single initialize_result proxy
fix(tests): update test_integration.py for initialize_result