Title: Lazy HTTP connections seem to make error handling difficult. · Issue #1393 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: Lazy HTTP connections seem to make error handling difficult. · Issue #1393 · modelcontextprotocol/python-sdk
X Title: Lazy HTTP connections seem to make error handling difficult. · Issue #1393 · modelcontextprotocol/python-sdk
Description: Question When using streamablehttp_client, since HTTP connections are initialized with anyio.create_task_group, if the server is unreachable, an error will occur unexpectedly at some point later. Is this the intended behavior? If the con...
Open Graph Description: Question When using streamablehttp_client, since HTTP connections are initialized with anyio.create_task_group, if the server is unreachable, an error will occur unexpectedly at some point later. I...
X Description: Question When using streamablehttp_client, since HTTP connections are initialized with anyio.create_task_group, if the server is unreachable, an error will occur unexpectedly at some point later. I...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/1393
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Lazy HTTP connections seem to make error handling difficult.","articleBody":"### Question\n\nWhen using streamablehttp_client, since HTTP connections are initialized with anyio.create_task_group, if the server is unreachable, an error will occur unexpectedly at some point later. Is this the intended behavior? If the connection is impossible, I want to wait and handle the error. However, the current behavior executes the code after the initialization and then throws an error at some point. If the error had occurred earlier, the code below it wouldn't have needed to execute. I consider this excessive optimization. Is there a reason for this design?\n\n### Additional Context\n\n```python\nimport asyncio\nfrom langchain_mcp_adapters.tools import load_mcp_tools\nfrom mcp import ClientSession\nfrom mcp.client.streamable_http import streamablehttp_client\n\nasync def _init_and_load(session: ClientSession):\n try:\n async with asyncio.timeout(10): # \u003c\u003c I cannot access the server and will time out.\n await session.initialize()\n return await load_mcp_tools(session)\n except Exception as e:\n return []\n\nasync def main():\n async with streamablehttp_client(url=\"https://some.unreachable.domain\") as client:\n async with ClientSession(client[0], client[1]) as session:\n tools = await _init_and_load(session)\n await asyncio.sleep(100) # \u003c\u003c A httpx.ConnectTimeout exception occurred while performing the following operation!!\n```\n\n```python\nimport asyncio\nfrom langchain_mcp_adapters.tools import load_mcp_tools\nfrom mcp import ClientSession\nfrom mcp.client.streamable_http import streamablehttp_client\n\nasync def _init_and_load(session: ClientSession):\n try:\n await session.initialize()\n return await load_mcp_tools(session)\n except Exception as e: # \u003c\u003c Since the error is caused by tg, this cannot handle the error too!!\n return []\n\nasync def main():\n async with streamablehttp_client(url=\"https://some.unreachable.domain\", timeout=10) as client:\n async with ClientSession(client[0], client[1]) as session:\n tools = await _init_and_load(session)\n await asyncio.sleep(100)\n```","author":{"url":"https://github.com/caffeinism","@type":"Person","name":"caffeinism"},"datePublished":"2025-09-24T03:58:14.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/1393/python-sdk/issues/1393"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:5cade630-492e-2764-c3e5-aeb33c8158ed |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ADAC:15675C:133F867:1B83B8C:6A634662 |
| html-safe-nonce | f45041356836b4d10e2226d789383010454696fdd924848efd4fba2671b71bcc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBREFDOjE1Njc1QzoxMzNGODY3OjFCODNCOEM6NkE2MzQ2NjIiLCJ2aXNpdG9yX2lkIjoiNjc5NzE5MzY4MzY5ODY2NTA1OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 7bd57393df0d12794341a1ee25b825cc13956947c7a79193c017a988a4485d2a |
| hovercard-subject-tag | issue:3447524437 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/python-sdk/1393/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2c443600bfeeceb8f66e7ecb787ec67780b63e3cbc0c0250043f40731e0204e7/modelcontextprotocol/python-sdk/issues/1393 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2c443600bfeeceb8f66e7ecb787ec67780b63e3cbc0c0250043f40731e0204e7/modelcontextprotocol/python-sdk/issues/1393 |
| og:image:alt | Question When using streamablehttp_client, since HTTP connections are initialized with anyio.create_task_group, if the server is unreachable, an error will occur unexpectedly at some point later. I... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | caffeinism |
| hostname | github.com |
| expected-hostname | github.com |
| None | 59e55daad7174ca59d63c6974d58276ccb5477442e550bebb3c035e1bef11c94 |
| turbo-cache-control | no-preview |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 990295d92a4cc7b63fbbd83a046217cd7d77d49c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width