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
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.