Skip to content

fix: make sure items etc. is passed to mcp tools #86

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

Merged
merged 2 commits into from
Apr 21, 2025
Merged

fix: make sure items etc. is passed to mcp tools #86

merged 2 commits into from
Apr 21, 2025

Conversation

MagnusS0
Copy link
Contributor

Describe your changes

This patch fixes a bug in convert_openapi_to_mcp_tools where array‑typed parameters lost their items sub‑schema and caused downstream function‑calling errors.

  • Deep‑copy each parameter’s full schema instead of rebuilding only its type
  • Preserve items, format, enum, default, etc., for all path, query, and body parameters
  • No change to overall behaviour, tool definitions, HTTP mapping, and response docs remain the same

All existing tests still pass with same coverage.

Issue

OpenAI, Gemini and other providers expects 'items' in array schema in tools to be defined.
When converting these where removed from the OpenAPI schema leading to the below error.

I got this error in both Cursor and using PydanticAI.

pydantic_ai.exceptions.ModelHTTPError: status_code: 400, model_name: gpt-4.1-mini, body: {'message': "Invalid schema for function 'update_tags': In context=('properties', 'tags'), array schema missing items.", 'type': 'invalid_request_error', 'param': 'tools[3].function.parameters', 'code': 'invalid_function_parameters'}

Checklist before requesting a review

  • Added relevant tests
  • Run ruff & mypy
  • All tests pass
========================================================================= tests coverage ==========================================================================
_________________________________________________________ coverage: platform linux, python 3.12.2-final-0 _________________________________________________________

Name                                Stmts   Miss  Cover   Missing
-----------------------------------------------------------------
fastapi_mcp/__init__.py                 5      0   100%
fastapi_mcp/openapi/__init__.py         0      0   100%
fastapi_mcp/openapi/convert.py        151     14    91%   46-47, 52-53, 116-119, 122, 126-128, 211, 234
fastapi_mcp/openapi/utils.py           79      5    94%   15, 143, 145, 147, 161
fastapi_mcp/server.py                 165     19    88%   167-170, 198, 222, 234, 242, 248-251, 267, 278-279, 302-305, 330, 334
fastapi_mcp/transport/__init__.py       0      0   100%
fastapi_mcp/transport/sse.py           59      0   100%
fastapi_mcp/types.py                    0      0   100%
fastapi_mcp/utils/__init__.py           0      0   100%
-----------------------------------------------------------------
TOTAL                                 459     38    92%
Coverage XML written to file coverage.xml
Required test coverage of 80% reached. Total coverage: 91.72%
======================================================================= 67 passed in 14.82s =======================================================================

Copy link

codecov bot commented Apr 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@shira-ayal shira-ayal self-requested a review April 21, 2025 10:41
Copy link

@shira-ayal shira-ayal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi !
Thanks for contributing and using the library.
Can you please add a unit test for the line I marked?
Other than this, seems alright :)

@MagnusS0
Copy link
Contributor Author

Will do!
And thanks for building an awesome library 😄

@shira-ayal shira-ayal merged commit bbb7528 into tadata-org:main Apr 21, 2025
6 checks passed
@MagnusS0 MagnusS0 deleted the fix/convert branch April 21, 2025 17:09
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