Merge branch 'main' into welcome

This commit is contained in:
Jeremiah Lowin 2025-06-11 20:16:06 -04:00 committed by GitHub
commit 674287c962
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 44 additions and 3 deletions

View file

@ -1231,7 +1231,6 @@ class FastMCP(Generic[LifespanResultT]):
port: int | None = None,
log_level: str | None = None,
path: str | None = None,
message_path: str | None = None,
uvicorn_config: dict[str, Any] | None = None,
) -> None:
"""Run the server using SSE transport."""
@ -1333,10 +1332,14 @@ class FastMCP(Generic[LifespanResultT]):
event_store=None,
auth=self.auth,
json_response=(
json_response or self._deprecated_settings.json_response
json_response
if json_response is not None
else self._deprecated_settings.json_response
),
stateless_http=(
stateless_http or self._deprecated_settings.stateless_http
stateless_http
if stateless_http is not None
else self._deprecated_settings.stateless_http
),
debug=self._deprecated_settings.debug,
middleware=middleware,

View file

@ -97,6 +97,7 @@ class ArgTransform:
type: New type for the argument. Use ... for no change.
hide: If True, hide this argument from clients but pass a constant value to parent.
required: If True, make argument required (remove default). Use ... for no change.
examples: Examples for the argument. Use ... for no change.
Examples:
# Rename argument 'old_name' to 'new_name'
@ -137,6 +138,7 @@ class ArgTransform:
type: Any | EllipsisType = NotSet
hide: bool = False
required: Literal[True] | EllipsisType = NotSet
examples: Any | EllipsisType = NotSet
def __post_init__(self):
"""Validate that only one of default or default_factory is provided."""
@ -584,6 +586,10 @@ class TransformedTool(Tool):
# Update the schema with the type information from TypeAdapter
new_schema.update(type_schema)
# Handle examples transformation
if transform.examples is not NotSet:
new_schema["examples"] = transform.examples
return new_name, new_schema, is_required
@staticmethod

View file

@ -987,3 +987,35 @@ class TestEnableDisable:
with pytest.raises(ToolError):
await client.call_tool("new_add", {"x": 1, "y": 2})
def test_arg_transform_examples_in_schema(add_tool):
# Simple example
new_tool = Tool.from_tool(
add_tool,
transform_args={
"old_x": ArgTransform(examples=[1, 2, 3]),
},
)
prop = get_property(new_tool, "old_x")
assert prop["examples"] == [1, 2, 3]
# Nested example (e.g., for array type)
new_tool2 = Tool.from_tool(
add_tool,
transform_args={
"old_x": ArgTransform(examples=[["a", "b"], ["c", "d"]]),
},
)
prop2 = get_property(new_tool2, "old_x")
assert prop2["examples"] == [["a", "b"], ["c", "d"]]
# If not set, should not be present
new_tool3 = Tool.from_tool(
add_tool,
transform_args={
"old_x": ArgTransform(),
},
)
prop3 = get_property(new_tool3, "old_x")
assert "examples" not in prop3