Skip to content

Support dict/list bodies in fetch() with automatic JSON serialization#33

Merged
simonediroma merged 1 commit into
mainfrom
claude/fix-webfetch-error-Oasyz
Apr 8, 2026
Merged

Support dict/list bodies in fetch() with automatic JSON serialization#33
simonediroma merged 1 commit into
mainfrom
claude/fix-webfetch-error-Oasyz

Conversation

@simonediroma
Copy link
Copy Markdown
Owner

Summary

Enhanced the fetch() function to accept dict and list objects as request bodies, automatically serializing them to JSON format. This improves the API ergonomics by eliminating the need for callers to manually serialize JSON payloads.

Key Changes

  • Updated the body parameter type annotation from str | None to str | dict | list | None
  • Added automatic JSON serialization for dict and list body types
  • Automatically sets Content-Type: application/json header when a dict/list body is provided (if not already set)
  • Updated docstring to reflect the new functionality

Implementation Details

  • The serialization logic is placed before the HTTP request is made, ensuring the body is converted to a string before being sent
  • The Content-Type header check is case-insensitive to avoid duplicate headers
  • Only sets the header if one isn't already present, respecting explicit user-provided headers

https://claude.ai/code/session_014xQUrZCmX99mTwb26tndQY

…rror

When Claude passes a JSON object (dict) as the `body` parameter, FastMCP's
Pydantic validation rejected it because `body` was typed as `str | None`.
Now accepts `str | dict | list | None` and auto-serializes dicts/lists to
JSON, also setting Content-Type: application/json when not already present.

https://claude.ai/code/session_014xQUrZCmX99mTwb26tndQY
@simonediroma simonediroma merged commit ebb3070 into main Apr 8, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants