Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dbsanfte opened this issue Apr 16, 2025 · 6 comments

Comments

@dbsanfte
Copy link

dbsanfte commented Apr 16, 2025

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.

@jlowin
Copy link
Owner

jlowin commented Apr 16, 2025

I believe this is the same issue as #186 and may already be fixed on main, which will be released as 2.2 shortly. If that is not the case, please re-open and we will try to solve ASAP

@jlowin jlowin closed this as completed Apr 16, 2025
@jlowin
Copy link
Owner

jlowin commented Apr 16, 2025

Update: 2.2 is out now if you'd like to confirm

@dbsanfte
Copy link
Author

@jlowin sadly I can still reproduce this using the code from the latest main (91fba14)

@jlowin
Copy link
Owner

jlowin commented Apr 16, 2025

I'm sorry to hear that! Can you share any code so I can replicate against that API?

@dbsanfte
Copy link
Author

Let me see what I can throw together tomorrow, will ping

@jlowin jlowin reopened this Apr 16, 2025
@dbsanfte
Copy link
Author

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

No branches or pull requests

2 participants