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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
9 changes: 5 additions & 4 deletions src/mcp/server/fastmcp/utilities/func_metadata.py
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
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import functools
import inspect
import json
from collections.abc import Awaitable, Callable, Sequence
from itertools import chain
from types import GenericAlias
from typing import Annotated, Any, cast, get_args, get_origin, get_type_hints

import anyio
import anyio.to_thread
import pydantic_core
from pydantic import BaseModel, ConfigDict, Field, WithJsonSchema, create_model
from pydantic.fields import FieldInfo
Expand Down Expand Up @@ -53,9 +56,7 @@ def model_dump_one_level(self) -> dict[str, Any]:
kwargs[output_name] = value
return kwargs

model_config = ConfigDict(
arbitrary_types_allowed=True,
)
model_config = ConfigDict(arbitrary_types_allowed=True)


class FuncMetadata(BaseModel):
Expand Down Expand Up @@ -85,7 +86,7 @@ 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(functools.partial(fn, **arguments_parsed_dict))

def convert_result(self, result: Any) -> Any:
"""Convert the result of a function call to the appropriate format for
Expand Down

Back | FazBrowse Home | New Git URL