Skip to content

[Bug] OpenAPI form-urlencoded bodies send object properties as Python repr #5850

Closed

Description

@BlueX888

Summary

An OpenAPI operation with an application/x-www-form-urlencoded request body sends object-typed properties as a Python repr string. A property filter: {type: object} with {"name": "alice", "age": 30} is transmitted as:

filter=%7B%27name%27%3A+%27alice%27%2C+%27age%27%3A+30%7D&tags=a&tags=b

i.e. filter={'name': 'alice', 'age': 30}. Nested None becomes the literal text None, not null. Per the OAS Encoding Object, object properties default to contentType: application/json, so the value should be filter={"name": "alice", "age": 30}; an explicit style/explode would flatten it to name=alice&age=30. String arrays already repeat correctly (tags=a&tags=b).

Most form-decoding servers reject or mis-store these values, so any OpenAPI endpoint taking a structured form field is unusable through this provider.

Reproduction (current main adf90b6, offline)

spec = {"openapi": "3.0.0", "paths": {"/submit": {"post": {
    "requestBody": {"content": {"application/x-www-form-urlencoded": {"schema": {
        "type": "object",
        "properties": {
            "filter": {"type": "object", "properties": {"name": {"type": "string"}, "age": {"type": "integer"}}},
            "tags": {"type": "array", "items": {"type": "string"}}}}}}},
    ...
}}}}

with a mock transport capturing request.content; call the tool with {"filter": {"name": "alice", "age": 30}, "tags": ["a", "b"]}.

  • actual: filter=%7B%27name%27%3A+%27alice%27%2C+%27age%27%3A+30%7D&tags=a&tags=b
  • expected: filter=%7B%22name%22%3A+%22alice%22%2C+%22age%22%3A+30%7D&tags=a&tags=b

Root cause

fastmcp_slim/fastmcp/utilities/openapi/director.py, RequestDirector.build, application/x-www-form-urlencoded branch (base ~lines 181-185): the body dict is passed directly to httpx2.Request(data=body). httpx stringifies dict/list-of-dict values with str() and ignores per-property encoding overrides for urlencoded bodies.

Suggested fix

Build the form data per property: JSON-encode object-typed values and arrays of objects (honoring an explicit encoding.<prop>.contentType, defaulting to application/json per OAS), leave primitives and arrays of primitives to httpx so they keep repeating the key, and keep multipart/JSON bodies untouched.

Tests

A fix with six regression tests is ready (object inline and $ref, nested null, array of objects, explicit encoding contentType, JSON-body control), using a mock transport that records the raw body. I'll open the linked PR with red/green evidence.

Activity

  1. added
    bugSomething isn't working. Reports of errors, unexpected behavior, or broken functionality.
    openapiRelated to OpenAPI integration, parsing, or code generation features.
    on Oct 19, 2026
  2. added a commit that references this issue on Nov 10, 2026
    c15826a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working. Reports of errors, unexpected behavior, or broken functionality.low-priorityopenapiRelated to OpenAPI integration, parsing, or code generation features.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions