Skip to content

from_openapi server raises tons of Pydantic errors trying to parse JSON returned from the upstream api #187

Open
@dbsanfte

Description

@dbsanfte

I've been trying to debug an issue in fastmcp over the past few days related to JSON deserialisation.

I've stood up a FastMCP instance using the from_openapi method, against an OpenAPI json generated here:

https://converter.swagger.io/api/convert?url=https%3A%2F%2Fdevelopers.topdesk.com%2Fswagger%2Fincident_specification_3.8.5.yaml

This is the TopDesk Incident API:

https://developers.topdesk.com/explorer/?page=incident

When my local LLM calls the tool on the MCP server, the MCP server correctly and successfully calls the correct endpoint on the Topdesk API upstream, and it gets a list of incidents back. These appear to be well-structured JSON. But the MCP server fails to parse it with a bunch of Pydantic errors.

See below:

70 validation errors for CallToolResult
content.0.TextContent.type
  Field required [type=missing, input_value={'id': '34e2e1c4-f929-402... 'partialIncidents': []}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.11/v/missing\ncontent.0.TextContent.text
  Field required [type=missing, input_value={'id': '34e2e1c4-f929-402... 'partialIncidents': []}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.11/v/missing\ncontent.0.ImageContent.type
  Field required [type=missing, input_value={'id': '34e2e1c4-f929-402... 'partialIncidents': []}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.11/v/missing\ncontent.0.ImageContent.data
  Field required [type=missing, input_value={'id': '34e2e1c4-f929-402... 'partialIncidents': []}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.11/v/missing\ncontent.0.ImageContent.mimeType
  Field required [type=missing, input_value={'id': '34e2e1c4-f929-402... 'partialIncidents': []}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.11/v/missing\ncontent.0.EmbeddedResource.type
  Field required [type=missing, input_value={'id': '34e2e1c4-f929-402... 'partialIncidents': []}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.11/v/missing\ncontent.0.EmbeddedResource.resource
  Field required [type=missing, input_value={'id': '34e2e1c4-f929-402... 'partialIncidents': []}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.11/v/missing\ncontent.1.TextContent.type
  Field required [type=missing, input_value={'id': '72f59a2c-7a15-435... 'partialIncidents': []}, input_type=dict]
    For further information visit https://errors.pydantic.dev/2.11/v/missing\ncontent.1.TextContent.text
  Field required [type=missing, input_value={'id': '72f59a2c-7a15-435... 'partialIncidents': []}, input_type=dict]
...

The tool call itself made by the LLM is:

{
      "role": "assistant",
      "content": null,
      "tool_calls": [
        {
          "index": 0,
          "id": "919000339",
          "function": {
            "arguments": "{\"input\": \"{\\\"status\\\": \\\"firstLine\\\"}\"}",
            "name": "get_incidents"
          },
          "type": "function"
        }
      ]
    }

And that gives me:

2025-04-16 17:13:39,235 - httpx - INFO - HTTP Request: GET https://myinstance.topdesk.net/tas/api/incidents "HTTP/1.1 206 Partial Content"

So the error is definitely in the server somewhere.

I'm not quite sure where to go from here but I'm happy to help debug more if necessary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions