fastmcp/examples
zzstoatzz 7d2f1f9671 Fix: Prompt arg handling & docs for #541
Addresses #541:
- Server now auto-deserializes JSON string args (list, dict, BaseModel) for prompts. This simplifies server-side prompt logic by reducing boilerplate `json.loads()` calls.
- Docs updated to clarify `list_resource_templates` usage for templatized resources.
- Docs updated to require client-side `json.dumps()` for complex `get_prompt` arguments, resolving the original Pydantic error.
- Adds a new example (`examples/dynamic_story_prompt/`) demonstrating the server-side deserialization benefit and correct client-side serialization.

Closes #541.

---
Notes for Reviewers:
- **Server-Side Auto-Deserialization:** This change introduces a "magic" `json.loads()` in `Prompt.render`. This is an intentional DX improvement. It only triggers for `str` inputs targeting `list`, `dict`, or `BaseModel` type hints. If `json.loads()` fails (e.g., malformed JSON), the original string is passed to Pydantic's `validate_call`, ensuring robust error handling. This avoids boilerplate in user prompt functions.
- **Client `get_prompt()` Return Value:** The `examples/dynamic_story_prompt/story_client.py` parses the result of `client.get_prompt()` by iterating and looking for a `('messages', ...)` tuple. This reflects the observed behavior of the current `client.get_prompt()`. This commit does *not* change `client.get_prompt()`'s return behavior; the example merely adapts to it. A separate discussion might be warranted for potentially simplifying `client.get_prompt()`'s return signature in the future.
2025-05-27 19:38:32 -05:00
..
dynamic_story_prompt Fix: Prompt arg handling & docs for #541 2025-05-27 19:38:32 -05:00
smart_home add readme to smarthome example 2025-05-01 09:45:57 -05:00
complex_inputs.py Update composition docs 2025-05-10 15:47:20 -04:00
desktop.py Update composition docs 2025-05-10 15:47:20 -04:00
echo.py Merge branch 'main' into updates 2024-11-30 19:34:19 -05:00
in_memory_proxy_example.py Add as_proxy improvements and tests 2025-05-17 12:23:48 -04:00
memory.py add note 2024-12-03 13:13:33 -06:00
mount_example.py o 2025-04-13 18:27:17 -05:00
sampling.py Add sampling and roots functionality and tests 2025-04-11 11:11:53 -04:00
screenshot.py Basic cleanup 2025-04-05 17:39:51 -04:00
serializer.py Fix kwarg 2025-05-03 12:15:07 -04:00
simple_echo.py Basic cleanup 2025-04-05 17:39:51 -04:00
tags_example.py Add support for RouteMap tags, update docs 2025-05-22 21:59:16 -04:00
text_me.py Basic cleanup 2025-04-05 17:39:51 -04:00