3131 from mcp .client .sse import sse_client
3232 from mcp .client .stdio import StdioServerParameters , stdio_client
3333 from mcp .client .streamable_http import GetSessionIdCallback , streamablehttp_client
34+ from mcp .shared import exceptions as mcp_exceptions
3435 from mcp .shared .context import RequestContext
35- from mcp .shared .exceptions import McpError
3636 from mcp .shared .message import SessionMessage
3737except ImportError as _import_error :
3838 raise ImportError (
4242
4343# after mcp imports so any import error maps to this file, not _mcp.py
4444from . import _mcp , _utils , exceptions , messages , models
45+ from .exceptions import MCPServerCapabilitiesError , MCPServerError
4546
4647__all__ = 'MCPServer' , 'MCPServerStdio' , 'MCPServerHTTP' , 'MCPServerSSE' , 'MCPServerStreamableHTTP' , 'load_mcp_servers'
4748
@@ -246,7 +247,7 @@ async def direct_call_tool(
246247 ),
247248 mcp_types .CallToolResult ,
248249 )
249- except McpError as e :
250+ except mcp_exceptions . McpError as e :
250251 raise exceptions .ModelRetry (e .error .message )
251252
252253 if result .isError :
@@ -321,32 +322,32 @@ async def list_resources(self) -> list[_mcp.Resource]:
321322 - We also don't subscribe to resource changes to avoid complexity.
322323
323324 Raises:
324- ServerCapabilitiesError : If the server does not support resources.
325+ MCPServerCapabilitiesError : If the server does not support resources.
325326 MCPServerError: If the server returns an error.
326327 """
327328 async with self : # Ensure server is running
328329 if not self .capabilities .resources :
329- raise exceptions . ServerCapabilitiesError ('Server does not support resources capability' )
330+ raise MCPServerCapabilitiesError ('Server does not support resources capability' )
330331 try :
331332 result = await self ._client .list_resources ()
332- except McpError as e :
333- raise exceptions . MCPServerError .from_mcp_sdk_error (e ) from e
333+ except mcp_exceptions . McpError as e :
334+ raise MCPServerError .from_mcp_sdk_error (e ) from e
334335 return [_mcp .map_from_mcp_resource (r ) for r in result .resources ]
335336
336337 async def list_resource_templates (self ) -> list [_mcp .ResourceTemplate ]:
337338 """Retrieve resource templates that are currently present on the server.
338339
339340 Raises:
340- ServerCapabilitiesError : If the server does not support resources.
341+ MCPServerCapabilitiesError : If the server does not support resources.
341342 MCPServerError: If the server returns an error.
342343 """
343344 async with self : # Ensure server is running
344345 if not self .capabilities .resources :
345- raise exceptions . ServerCapabilitiesError ('Server does not support resources capability' )
346+ raise MCPServerCapabilitiesError ('Server does not support resources capability' )
346347 try :
347348 result = await self ._client .list_resource_templates ()
348- except McpError as e :
349- raise exceptions . MCPServerError .from_mcp_sdk_error (e ) from e
349+ except mcp_exceptions . McpError as e :
350+ raise MCPServerError .from_mcp_sdk_error (e ) from e
350351 return [_mcp .map_from_mcp_resource_template (t ) for t in result .resourceTemplates ]
351352
352353 @overload
@@ -370,17 +371,17 @@ async def read_resource(
370371 If the resource has multiple content items, returns a list of items.
371372
372373 Raises:
373- ServerCapabilitiesError : If the server does not support resources.
374+ MCPServerCapabilitiesError : If the server does not support resources.
374375 MCPServerError: If the server returns an error (e.g., resource not found).
375376 """
376377 resource_uri = uri if isinstance (uri , str ) else uri .uri
377378 async with self : # Ensure server is running
378379 if not self .capabilities .resources :
379- raise exceptions . ServerCapabilitiesError ('Server does not support resources capability' )
380+ raise MCPServerCapabilitiesError ('Server does not support resources capability' )
380381 try :
381382 result = await self ._client .read_resource (AnyUrl (resource_uri ))
382- except McpError as e :
383- raise exceptions . MCPServerError .from_mcp_sdk_error (e ) from e
383+ except mcp_exceptions . McpError as e :
384+ raise MCPServerError .from_mcp_sdk_error (e ) from e
384385 return (
385386 self ._get_content (result .contents [0 ])
386387 if len (result .contents ) == 1
0 commit comments