@@ -112,6 +112,7 @@ class MCPServer(AbstractToolset[Any], ABC):
112
112
_client : ClientSession
113
113
_read_stream : MemoryObjectReceiveStream [SessionMessage | Exception ]
114
114
_write_stream : MemoryObjectSendStream [SessionMessage ]
115
+ _server_info : mcp_types .Implementation
115
116
116
117
def __init__ (
117
118
self ,
@@ -177,6 +178,15 @@ def label(self) -> str:
177
178
def tool_name_conflict_hint (self ) -> str :
178
179
return 'Set the `tool_prefix` attribute to avoid name conflicts.'
179
180
181
+ @property
182
+ def server_info (self ) -> mcp_types .Implementation :
183
+ """Access the information send by the MCP server during initialization."""
184
+ if getattr (self , '_server_info' , None ) is None :
185
+ raise AttributeError (
186
+ f'The `{ self .__class__ .__name__ } .server_info` is only instantiated after initialization.'
187
+ )
188
+ return self ._server_info
189
+
180
190
async def list_tools (self ) -> list [mcp_types .Tool ]:
181
191
"""Retrieve tools that are currently active on the server.
182
192
@@ -312,8 +322,8 @@ async def __aenter__(self) -> Self:
312
322
self ._client = await exit_stack .enter_async_context (client )
313
323
314
324
with anyio .fail_after (self .timeout ):
315
- await self ._client .initialize ()
316
-
325
+ result = await self ._client .initialize ()
326
+ self . _server_info = result . serverInfo
317
327
if log_level := self .log_level :
318
328
await self ._client .set_logging_level (log_level )
319
329
0 commit comments