Skip to content

from_openapi: tool calls fail output validation when the response omits a required writeOnly property #5321

Closed

Description

@asasemahmed

What happened?

A schema shared by a request body and its response marks password as writeOnly and required. The generated tool's output schema still requires password. The API's response correctly leaves it out, and the client rejects the call.

Example Code

import asyncio

import httpx2

from fastmcp import Client, FastMCP

user = {"$ref": "#/components/schemas/User"}
spec = {
    "openapi": "3.0.3",
    "info": {"title": "Users", "version": "1.0"},
    "paths": {
        "/users": {
            "post": {
                "operationId": "create_user",
                "requestBody": {"required": True, "content": {"application/json": {"schema": user}}},
                "responses": {"201": {"description": "Created", "content": {"application/json": {"schema": user}}}},
            }
        }
    },
    "components": {
        "schemas": {
            "User": {
                "type": "object",
                "required": ["name", "password"],
                "properties": {
                    "name": {"type": "string"},
                    "password": {"type": "string", "writeOnly": True},
                },
            }
        }
    },
}


def handler(request: httpx2.Request) -> httpx2.Response:
    # The API never echoes the writeOnly password back
    return httpx2.Response(201, json={"name": "ada"})


async def main():
    api = httpx2.AsyncClient(transport=httpx2.MockTransport(handler), base_url="https://api.example.com")
    mcp = FastMCP.from_openapi(spec, client=api)
    async with Client(mcp) as client:
        tool = (await client.list_tools())[0]
        print("output required:", tool.output_schema["required"])
        result = await client.call_tool("create_user", {"name": "ada", "password": "s3cret"})
        print(result.structured_content)


asyncio.run(main())

Output:

output required: ['name', 'password']
...
RuntimeError: Invalid structured content returned by tool create_user: 'password' is a required property

Version Information

FastMCP version:                                          4.0.11.dev11+89b00b7f
MCP version:                                                              2.0.0
Python version:                                                         3.12.14
Platform:                                             Windows-11-10.0.26200-SP0

Activity

  1. added
    bug
    openapi
    on Sep 28, 2026
  2. added a commit that references this issue on Oct 8, 2026
    4a98517
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugopenapi

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions