feat(client): store InitializeResult as initialize_result (#2300)
This commit is contained in:
parent
67201a9bbd
commit
20dd94632e
1 changed files with 64 additions and 37 deletions
|
|
@ -169,6 +169,30 @@ result = await session.list_resources(params=PaginatedRequestParams(cursor="next
|
|||
result = await session.list_tools(params=PaginatedRequestParams(cursor="next_page_token"))
|
||||
```
|
||||
|
||||
### `ClientSession.get_server_capabilities()` replaced by `initialize_result` property
|
||||
|
||||
`ClientSession` now stores the full `InitializeResult` via an `initialize_result` property. This provides access to `server_info`, `capabilities`, `instructions`, and the negotiated `protocol_version` through a single property. The `get_server_capabilities()` method has been removed.
|
||||
|
||||
**Before (v1):**
|
||||
|
||||
```python
|
||||
capabilities = session.get_server_capabilities()
|
||||
# server_info, instructions, protocol_version were not stored — had to capture initialize() return value
|
||||
```
|
||||
|
||||
**After (v2):**
|
||||
|
||||
```python
|
||||
result = session.initialize_result
|
||||
if result is not None:
|
||||
capabilities = result.capabilities
|
||||
server_info = result.server_info
|
||||
instructions = result.instructions
|
||||
version = result.protocol_version
|
||||
```
|
||||
|
||||
The high-level `Client.initialize_result` returns the same `InitializeResult` but is non-nullable — initialization is guaranteed inside the context manager, so no `None` check is needed. This replaces v1's `Client.server_capabilities`; use `client.initialize_result.capabilities` instead.
|
||||
|
||||
### `McpError` renamed to `MCPError`
|
||||
|
||||
The `McpError` exception class has been renamed to `MCPError` for consistent naming with the MCP acronym style used throughout the SDK.
|
||||
|
|
|
|||
Loading…
Reference in a new issue