Skip to content

Commit ff35be8

Browse files
committed
Preserve dict output Field metadata
1 parent 0da9092 commit ff35be8

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,7 @@ def _try_create_model_and_schema(
397397
if origin is dict:
398398
args = get_args(type_expr)
399399
if len(args) == 2 and args[0] is str:
400-
# TODO: should we use the original annotation? We are losing any potential `Annotated`
401-
# metadata for Pydantic here:
402-
model = _create_dict_model(func_name, type_expr)
400+
model = _create_dict_model(func_name, original_annotation)
403401
else:
404402
# dict with non-str keys needs wrapping
405403
model = _create_wrapped_model(func_name, original_annotation)

tests/server/mcpserver/test_func_metadata.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,19 @@ def func_dict_list() -> dict[str, list[int]]: # pragma: no cover
258258
"title": "func_dict_listDictOutput",
259259
}
260260

261+
def func_dict_with_description() -> Annotated[
262+
dict[str, int], Field(description="Configuration values")
263+
]: # pragma: no cover
264+
return {"timeout": 30}
265+
266+
meta = func_metadata(func_dict_with_description)
267+
assert meta.output_schema == {
268+
"type": "object",
269+
"additionalProperties": {"type": "integer"},
270+
"title": "func_dict_with_descriptionDictOutput",
271+
"description": "Configuration values",
272+
}
273+
261274
# Test dict[int, str] - should be wrapped since key is not str
262275
def func_dict_int_key() -> dict[int, str]: # pragma: no cover
263276
return {1: "a", 2: "b"}

0 commit comments

Comments
 (0)