Commit graph

30 commits

Author SHA1 Message Date
Anthony James Padavano
16eb2ffcb0
fix: serialize object query params per OpenAPI style/explode rules (#3662)
Object-typed query parameters with explode=true (the default) were
passed as raw Python dicts to httpx, which called str() on them —
producing Python repr syntax (single quotes, capitalized booleans)
instead of proper query parameter serialization.

Per the OpenAPI specification, style=form with explode=true on objects
expands each property as a separate query parameter (e.g.
?myAttribute=true). This change handles dict values in both the
explode=true and explode=false branches of _serialize_query_params,
using the existing _query_scalar_to_str helper for correct boolean
formatting.

Fixes #2857
2026-03-27 21:42:36 -04:00
Jeremiah Lowin
ca76b82878
Respect OpenAPI content type in request body serialization (#3611) 2026-03-24 18:39:37 -04:00
Jeremiah Lowin
6f30e89dd1
Fix query parameter serialization to respect OpenAPI explode/style settings (#3595)
* Fix query parameter serialization to respect OpenAPI explode setting

* Support pipeDelimited and spaceDelimited query param styles

* Lowercase booleans in comma/pipe/space-joined query values

* Omit empty arrays from query string when explode=false

* Handle object query params with explode=false
2026-03-23 15:19:55 -04:00
Jeremiah Lowin
40bdfb6b1d
fix: URL-encode path params to prevent SSRF/path traversal (GHSA-vv7q-7jx5-f767) (#3507)
* fix: URL-encode path params in OpenAPI provider to prevent SSRF/path traversal

Co-authored-by: Claude <noreply@anthropic.com>

* Exempt too-long from core-category requirement in triage

* fix: also encode dots in path params to prevent bare .. traversal

* fix: only encode .. (not all dots) to preserve valid dotted values

* fix: encode all dots in path params to prevent single-dot normalization

* fix: check decoded path stays within prefix in double-encoding test

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-03-15 10:45:24 -04:00
Jeremiah Lowin
610551c7b6
Split large test files to comply with loq line limit (#3328) 2026-02-28 11:21:11 -05:00
manojPal23234
507e6b80ab
OpenAPI: rewrite $ref under propertyNames and patternProperties in _replace_ref_with_defs; add regression test for dict[StrEnum, Model] (#3306)
* Normalize OpenAPI $ref everywhere (incl. propertyNames); migrate components→$defs; add regression test

* Fix: normalize $ref in propertyNames and additionalProperties; add regression test

* Deterministic migration: components.schemas override $defs on collision; preserve direct $defs refs via alias; add collision test

* Fix: rewrite $ref in propertyNames and patternProperties in _replace_ref_with_defs

* Fix syntax error, formatting, and stray files

* Skip boolean subschemas in patternProperties

---------

Co-authored-by: Jeremiah Lowin <153965+jlowin@users.noreply.github.com>
2026-02-26 16:08:54 -05:00
Jeremiah Lowin
1caf40eee8
Fix circular reference crash in OpenAPI schemas (#3245)
* Fix circular reference crash in OpenAPI schemas (#3242, #1206, #1016)

* chore: Update SDK documentation

---------

Co-authored-by: marvin-context-protocol[bot] <225465937+marvin-context-protocol[bot]@users.noreply.github.com>
2026-02-20 09:21:54 -05:00
Jeremiah Lowin
fe57c3d689
Make $ref dereferencing optional via FastMCP(dereference_refs=...) (#3151)
Co-authored-by: marvin-context-protocol[bot] <225465937+marvin-context-protocol[bot]@users.noreply.github.com>
2026-02-11 13:45:37 -05:00
Jeremiah Lowin
880d835ccc
Add CIMD (Client ID Metadata Document) support for OAuth (#2871) 2026-02-06 13:44:52 -05:00
Jeremiah Lowin
2b6a0faf1c
Add loq file size limits and clean up type ignores (#2859) 2026-01-13 07:29:12 -05:00
Jeremiah Lowin
627c6cdad4
Dereference $ref in tool schemas for MCP client compatibility (#2808) 2026-01-07 18:30:08 -05:00
Jeremiah Lowin
b501f05794
Switch to new OpenAPI parser as default (#2513)
* Switch to new OpenAPI parser as default

Remove the legacy OpenAPI parser and make the experimental parser the
default. The experimental parser (introduced in 2.11) offers better
performance, improved compatibility, and a more maintainable architecture.

- Delete legacy parser (server/openapi.py, utilities/openapi.py)
- Move experimental parser to main locations
- Remove enable_new_openapi_parser feature flag
- Update documentation to remove experimental references

* Add deprecation stubs for experimental OpenAPI imports

* Add deprecated enable_new_openapi_parser setting and deprecation tests

* SDK docs

* REview comments

* Fix docstrings

* Update docstring

* Review comments

* Fix broken links
2025-12-01 20:29:18 -05:00
Jeremiah Lowin
6cc9559f84
Bump ty to ==0.0.1a25 (#2350)
* Bump ty to >=0.0.1a25 with type fixes

Follow-up to #2295. Updates ty and fixes compatibility issues with alpha 25, including:

- Updated ignore comment syntax (possibly-unbound-attribute → possibly-missing-attribute)
- Fixed async generator type handling with anext()
- Fixed type narrowing for timeout parameters
- Converted base_url assignments to AnyHttpUrl after string manipulation
- Added CallToolResult to return type annotations
- Removed redundant type casts
- Fixed test form data to use strings instead of bytes

ty alpha 25 has limitations with isinstance() narrowing on unions (see pyproject.toml for details), requiring some targeted type ignores.

* Pin ty to ==0.0.1a25

Alpha releases can have breaking changes, so pin to the tested version.
2025-11-02 20:02:45 -05:00
William Easton
94b1eb9d6e
feat: introduce inline snapshots (#1605)
Co-authored-by: William Easton <strawgate@users.noreply.github.com>
Co-authored-by: marvin-context-protocol[bot] <225465937+marvin-context-protocol[bot]@users.noreply.github.com>
2025-08-25 10:08:55 -04:00
Jeremiah Lowin
52a0fc078a
Fix nullable field handling in OpenAPI to JSON Schema conversion (#1279)
Co-authored-by: Claude <noreply@anthropic.com>
2025-07-28 20:31:23 -04:00
Magnus
912bba2385
fix: replace oneOf with anyOf in OpenAPI schemas to handle overlapping unions (#1119)
Co-authored-by: Jeremiah Lowin <153965+jlowin@users.noreply.github.com>
2025-07-11 13:31:45 -04:00
Jeremiah Lowin
6c9263001b
Add output schema support for OpenAPI tools (#1073)
* Add output schema support for OpenAPI tools

Implement automatic output schema extraction from OpenAPI responses for
FastMCP tools, addressing issue #1070. Tools generated from OpenAPI specs
now have meaningful output schemas instead of null, improving agent
efficiency when working with structured API responses.

- Add extract_output_schema_from_responses() function to parse response schemas
- Enhance OpenAPITool to accept and use output schemas with proper wrapping
- Automatically wrap non-object responses to comply with MCP requirements
- Include schema definitions and compress unused ones
- Add comprehensive test suite covering object, array, and primitive responses
- Update existing tests to handle structured output with proper typing
- Maintain backward compatibility for specs without response schemas

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Move output schema tests to dedicated test file

Reorganize output schema tests into test_openapi_output_schemas.py to keep
the main test_openapi.py file focused and smaller, as requested. Added two
additional tests for schema definitions handling.

- Move all extract_output_schema_from_responses() tests to new file
- Add tests for schema definitions inclusion
- Remove output schema imports from main test file

---------

Co-authored-by: Claude <noreply@anthropic.com>
2025-07-07 12:51:01 -04:00
Aditya Bansal
f524652f25 Add OpenAPI extensions support to HTTPRoute
- Add extensions field to HTTPRoute class to store x-* fields
  - Extract extensions from operation's model_extra in parser
  - Add test to verify extensions are properly parsed
2025-06-27 15:27:36 -07:00
Jeremiah Lowin
6584750667 Fix external schema reference handling in OpenAPI parser
Previously, external schema references (URLs) in OpenAPI schemas were
silently passed through and only failed during JSON schema validation
with confusing "failed to match exactly one schema" errors.

This change:
- Detects external references in _replace_ref_with_defs() and raises clear error messages
- Updates exception handlers to propagate external reference errors while preserving other error handling
- Adds comprehensive test coverage for external reference detection
- Provides helpful error messages explaining that FastMCP only supports local schema references

Fixes #926

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-06-25 21:25:06 -04:00
Owen W. Taylor
14d1b8a94d openapi: Rewrite recursive #/components/schemas/ references
When a schema referenced another schema as #/components/schemas/...
that wasn't properly rewritten into #/$defs/..
2025-06-20 14:34:47 -04:00
Jeremiah Lowin
a8c309f59f Make sure tests are atomic 2025-06-04 10:29:25 -04:00
ShiWei
82a987b900 add tests for _replace_ref_with_defs 2025-06-04 09:23:37 +08:00
ShiWei
6baa906813 replace nested requestBody's #/components/ with 2025-06-04 08:54:55 +08:00
Jeremiah Lowin
213abc4244 Pass client headers through to OpenAPI client 2025-05-23 12:38:24 -04:00
Jeremiah Lowin
ff318e655d Add reprs for OpenAPI objects 2025-05-14 13:42:20 -04:00
Jeremiah Lowin
56801435ac Support openapi 3.0 and 3.1 2025-04-13 22:38:37 -04:00
Jeremiah Lowin
79190e40e9 Ensure that openapi tags are transferred to MCP objects 2025-04-12 12:40:57 -04:00
zzstoatzz
16af43e272 use type 2025-04-11 03:42:00 -05:00
Jeremiah Lowin
9ca99d5809 Add OpenAPI server and tests 2025-04-10 11:16:58 -04:00
Jeremiah Lowin
a683abb8a3 Add openapi parsing utilities 2025-04-08 21:11:52 -04:00