[PR #5972] fix(docs): Fixed async usage in MCP agent #4754

Closed
opened 2026-02-20 17:50:41 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langchain-ai/langgraph/pull/5972

State: closed
Merged: No


Wrapped the tutorial code in async def main() with asyncio.run() since top-level await is not valid in Python scripts.
This makes the tutorial fully copy-paste runnable as intended and prevents SyntaxError: 'await' outside async function.

Problem

The MCP client code was using await outside of an async function, causing a SyntaxError: 'await' outside async function when trying to run the script. Without proper async function wrapping, the code would throw this error and not be executable.

Changes

wrap async/await code in proper async function

  • Add asyncio import for async execution
  • Wrap main code in async def main() function
  • Add asyncio.run(main()) to execute async code
  • Makes code copy-paste ready and immediately runnable
**Original Pull Request:** https://github.com/langchain-ai/langgraph/pull/5972 **State:** closed **Merged:** No --- Wrapped the tutorial code in `async def main()` with `asyncio.run()` since top-level `await` is not valid in Python scripts. This makes the tutorial fully copy-paste runnable as intended and prevents `SyntaxError: 'await' outside async function`. ## Problem The MCP client code was using `await` outside of an async function, causing a `SyntaxError: 'await' outside async function` when trying to run the script. Without proper async function wrapping, the code would throw this error and not be executable. ## Changes wrap async/await code in proper async function - Add asyncio import for async execution - Wrap main code in async def main() function - Add asyncio.run(main()) to execute async code - Makes code copy-paste ready and immediately runnable
yindo added the pull-request label 2026-02-20 17:50:41 -05:00
yindo closed this issue 2026-02-20 17:50:42 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraph#4754