Skip to content

Commit 994ebad

Browse files
committed
allow output schema to be None distinct from empty dict which makes not much sense
1 parent c3d4d4f commit 994ebad

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/mcp/server/fastmcp/tools/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Tool(BaseModel):
2323
name: str = Field(description="Name of the tool")
2424
description: str = Field(description="Description of what the tool does")
2525
parameters: dict[str, Any] = Field(description="JSON schema for tool parameters")
26-
output: dict[str, Any] = Field(description="JSON schema for tool output")
26+
output: dict[str, Any] | None = Field(description="JSON schema for tool output", default=None, )
2727
fn_metadata: FuncMetadata = Field(
2828
description="Metadata about the function including a pydantic model for tool"
2929
" arguments"
@@ -99,7 +99,7 @@ async def run(
9999
if self.context_kwarg is not None
100100
else None,
101101
)
102-
if self.output.get("type") == "object":
102+
if self.output and self.output.get("type") == "object":
103103
return DataContent(
104104
type="data",
105105
data=result,

src/mcp/server/fastmcp/utilities/func_metadata.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def model_dump_one_level(self) -> dict[str, Any]:
4646

4747
class FuncMetadata(BaseModel):
4848
arg_model: Annotated[type[ArgModelBase], WithJsonSchema(None)]
49-
output_schema: dict[str, Any]
49+
output_schema: dict[str, Any] | None
5050
# We can add things in the future like
5151
# - Maybe some args are excluded from attempting to parse from JSON
5252
# - Maybe some args are special (like context) for dependency injection
@@ -137,7 +137,7 @@ def func_metadata(
137137
sig = _get_typed_signature(func)
138138
params = sig.parameters
139139
dynamic_pydantic_model_params: dict[str, Any] = {}
140-
output_schema: dict[str, Any] = {}
140+
output_schema: dict[str, Any] | None = None
141141
globalns = getattr(func, "__globals__", {})
142142
for param in params.values():
143143
if param.name.startswith("_"):

0 commit comments

Comments
 (0)