-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Open
Labels
P3Nice to haves, rare edge casesNice to haves, rare edge casesPR welcomePRs for this issue are welcome and will be reviewed by maintainersPRs for this issue are welcome and will be reviewed by maintainersenhancementNew feature or requestNew feature or requestgood 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
Metadata
Metadata
Assignees
Labels
P3Nice to haves, rare edge casesNice to haves, rare edge casesPR welcomePRs for this issue are welcome and will be reviewed by maintainersPRs for this issue are welcome and will be reviewed by maintainersenhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomersready for workEnough information for someone to start working onEnough information for someone to start working on