FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Don't block the event loop on non-async functions by Kludex · Pull Request #1909 · modelcontextprotocol/python-sdk · GitHub

Don't block the event loop on non-async functions - #1909

Merged
Kludex merged 2 commits into
mainfrom
run-anyio-to-thread
Jan 19, 2026
Merged

Don't block the event loop on non-async functions#1909
Kludex merged 2 commits into
mainfrom
run-anyio-to-thread

Conversation

Kludex commented Jan 18, 2026
edited
Loading

Copy link
Copy Markdown
Member

maxisbey previously approved these changes Jan 19, 2026
Kludex merged commit 1c258ae into main Jan 19, 2026
26 checks passed
Kludex deleted the run-anyio-to-thread branch January 19, 2026 13:47
maxisbey added a commit that referenced this pull request Mar 31, 2026
PR #1909 fixed this for tools by running sync functions via
anyio.to_thread.run_sync, but the same blocking pattern existed in
FunctionResource.read, ResourceTemplate.create_resource, and
Prompt.render. All three called self.fn() directly and checked
inspect.iscoroutine(result) afterward, so a blocking sync
@mcp.resource or @mcp.prompt handler would still freeze the event loop.

This applies the same fix: check inspect.iscoroutinefunction(self.fn)
up front and dispatch sync functions to a worker thread. Verified that
pydantic.validate_call (used to wrap stored functions in templates and
prompts) preserves async-ness, so the check works correctly on the
wrapped function.

Github-Issue: #1646
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fastmcp tool func block asyncio

2 participants


Back | FazBrowse Home | New Git URL