Skip to content

Enhance route map logic for include/exclude OpenAPI routes #564

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 4 commits into from
May 23, 2025

Conversation

jlowin
Copy link
Owner

@jlowin jlowin commented May 23, 2025

Significantly expand the role and abilities of RouteMap objects, including more flexible inclusion/exclusion of routes.

This is expected to be released as 2.5, and deprecates (but maintains) old RouteMap behaviors.

Closes #548
Closes #557

@Copilot Copilot AI review requested due to automatic review settings May 23, 2025 01:12
@github-actions github-actions bot added documentation Improvements or additions to documentation tests labels May 23, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors route mapping to use a new MCPType enum, deprecates the old RouteType/route_type, and adds shortcut functions (ALL_TOOLS, EXCLUDE_PATTERN, etc.) for more flexible include/exclude logic.
Key changes:

  • Introduce MCPType and update RouteMap to use mcp_type, with backward‐compatibility warnings for route_type.
  • Add shortcut constructors (ALL_TOOLS(), EXCLUDE_PATTERN(), etc.) and update default mappings and helper logic in FastMCPOpenAPI.
  • Update tests and documentation to replace route_type/RouteType with mcp_type/MCPType and reflect deprecation of all_routes_as_tools.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/server/test_route_map_shortcuts.py New tests covering the shortcut functions
tests/server/openapi/test_openapi_path_parameters.py Swapped route_type import/usage for mcp_type/MCPType
tests/server/openapi/test_openapi.py Refactored tests to use mcp_type, async getters, and deprecation warnings
tests/deprecated/test_route_type_ignore.py Verified deprecation and conversion of RouteType.IGNORE
src/fastmcp/server/server.py Warn and redirect all_routes_as_tools to ALL_TOOLS()
src/fastmcp/server/openapi.py Added MCPType, enhanced RouteMap, naming, and exclusion logic
docs/patterns/openapi.mdx Updated docs to show mcp_type, shortcuts, and deprecations
Comments suppressed due to low confidence (2)

src/fastmcp/server/server.py:1154

  • It appears warnings.warn is used here without importing the warnings module in this file. Please add import warnings at the top of server.py to avoid a NameError at runtime.
warnings.warn(

docs/patterns/openapi.mdx:120

  • [nitpick] The leading space before mcp = FastMCP.from_openapi( may break the fenced code block formatting. Align this line with the opening backticks to ensure correct rendering.
 mcp = FastMCP.from_openapi(

@jlowin jlowin mentioned this pull request May 23, 2025
@jlowin jlowin merged commit 30aef0a into main May 23, 2025
6 checks passed
@jlowin jlowin deleted the custom-routes branch May 23, 2025 12:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: openapi documentation Improvements or additions to documentation feature tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add documentation of RouteType.IGNORE route_maps ignored – every FastAPI route exposed as a tool
1 participant