Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/mcp/server/fastmcp/utilities/func_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,11 @@ async def call_fn_with_arg_validation(
if fn_is_async:
return await fn(**arguments_parsed_dict)
else:
return fn(**arguments_parsed_dict)
return await anyio.to_thread.run_sync(lambda: fn(**arguments_parsed_dict))

@cubic-dev-ai cubic-dev-ai Bot Jun 27, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: Add the missing anyio import before using anyio.to_thread.run_sync; otherwise every synchronous tool call fails at runtime.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/mcp/server/fastmcp/utilities/func_metadata.py, line 96:

<comment>Add the missing `anyio` import before using `anyio.to_thread.run_sync`; otherwise every synchronous tool call fails at runtime.</comment>

<file context>
@@ -93,7 +93,11 @@ async def call_fn_with_arg_validation(
             return await fn(**arguments_parsed_dict)
         else:
-            return fn(**arguments_parsed_dict)
+            return await anyio.to_thread.run_sync(lambda: fn(**arguments_parsed_dict))
+            # Sync functions are offloaded to a thread to avoid blocking the event loop.
+            # anyio.to_thread.run_sync() uses copy_context() internally, so contextvars
</file context>
Fix with cubic

# Sync functions are offloaded to a thread to avoid blocking the event loop.
# anyio.to_thread.run_sync() uses copy_context() internally, so contextvars
# propagate correctly. Context is passed explicitly via arguments_parsed_dict,
# not through contextvars, so it is unaffected.

def convert_result(self, result: Any) -> Any:
"""
Expand Down
Loading