Skip to content

feat: store server_info on ClientSession during initialization#2211

Open
shivama205 wants to merge 1 commit intomodelcontextprotocol:mainfrom
shivama205:feat/store-server-info-on-client-session
Open

feat: store server_info on ClientSession during initialization#2211
shivama205 wants to merge 1 commit intomodelcontextprotocol:mainfrom
shivama205:feat/store-server-info-on-client-session

Conversation

@shivama205
Copy link

Summary

  • Store server_info from InitializeResult on ClientSession during initialize(), alongside the already-stored _server_capabilities
  • Add get_server_info() method to access it after initialization (mirrors existing get_server_capabilities())
  • Previously, users had to capture the return value of initialize() to access server metadata like name/version

Closes #1018

Changes

  • Modified: src/mcp/client/session.py — added _server_info attribute, stored during initialize(), exposed via get_server_info()
  • Modified: tests/client/test_session.py — added test_get_server_info verifying None before init and correct value after

Test plan

  • All 12 client session tests pass
  • ruff check passes
  • ruff format passes
  • pyright passes with 0 errors

Store the server_info from InitializeResult on the session (alongside
the already-stored server_capabilities) and expose it via
get_server_info(), so callers no longer need to capture the return
value of initialize() to access server metadata.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update _client_info on the ClientSession upon initialization with serverInfo

1 participant