-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use httpx.AsyncClient for async http requests #34
Conversation
@@ -768,7 +790,7 @@ uvicorn.run(app, host="0.0.0.0", port=8000) | |||
</Step> | |||
<Step title="Run tests"> | |||
```bash | |||
uv add --dev pytest pytest-asyncio |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
httpx and starlette both depend on anyio which ships with an async test framework - so you don't need to install an extra one here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change to httpx looks great—thank you!
Re: anyio
, although we use it in our SDK, it may make examples or getting started a bit more confusing than using asyncio
, because the latter is part of the standard library. We've purposely opted to stick with asyncio
for now. Do you mind reverting those bits? 🙏
@@ -108,20 +108,20 @@ Let's build your first MCP server in Python! We'll create a weather server that | |||
Add this functionality: | |||
|
|||
```python | |||
# Create reusable session | |||
http = requests.Session() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's nowhere to run a context manager and expose it to request handlers, so we're forced to create a new client each request: modelcontextprotocol/python-sdk#67
Happy to drop the use of anyio.run, but having multiple async plugins for pytest installed is overkill |
To stay consistent across the example, the implementation should use one async runtime for now. I would think it's best if for now we keep asyncio and create an issue to follow up if we should just switch the whole example, including the implementation itself, to anyio given that it is transient a dependency anyway. |
Yes I configured it to use asyncio only |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
requests.Session does blocking IO which blocks the event loop! No other requests can be processed concurrently