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
18 changes: 6 additions & 12 deletions src/mcp/server/fastmcp/utilities/func_metadata.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
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,
RootModel,
WithJsonSchema,
create_model,
)
from pydantic import BaseModel, ConfigDict, Field, RootModel, WithJsonSchema, create_model
from pydantic.fields import FieldInfo
from pydantic.json_schema import GenerateJsonSchema, JsonSchemaWarningKind
from typing_extensions import is_typeddict
Expand Down Expand Up @@ -60,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 @@ -92,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