Spaces:
Running
Running
Jeremiah Lowin commited on
Commit ·
40feb9b
1
Parent(s): ca8cdf5
Update openapi.py
Browse files
src/fastmcp/server/openapi.py
CHANGED
|
@@ -642,26 +642,12 @@ class FastMCPOpenAPI(FastMCP):
|
|
| 642 |
),
|
| 643 |
]
|
| 644 |
|
| 645 |
-
# Advanced: Custom route mapping function for fine-grained control
|
| 646 |
-
def custom_route_mapper(route, mcp_type, name):
|
| 647 |
-
# Convert all admin routes to tools regardless of HTTP method
|
| 648 |
-
if "/admin/" in route.path:
|
| 649 |
-
return MCPType.TOOL, f"admin_{name}"
|
| 650 |
-
|
| 651 |
-
# Rename all user-specific routes to include "user_"
|
| 652 |
-
if "/users/{id}" in route.path:
|
| 653 |
-
return mcp_type, f"user_{name}"
|
| 654 |
-
|
| 655 |
-
# Accept defaults for all other routes
|
| 656 |
-
return None
|
| 657 |
-
|
| 658 |
# Create server with custom mappings and route mapper
|
| 659 |
server = FastMCPOpenAPI(
|
| 660 |
openapi_spec=spec,
|
| 661 |
client=httpx.AsyncClient(),
|
| 662 |
name="API Server",
|
| 663 |
route_maps=custom_mappings,
|
| 664 |
-
route_map_fn=custom_route_mapper,
|
| 665 |
)
|
| 666 |
```
|
| 667 |
"""
|
|
@@ -687,8 +673,8 @@ class FastMCPOpenAPI(FastMCP):
|
|
| 687 |
route_maps: Optional list of RouteMap objects defining route mappings
|
| 688 |
route_map_fn: Optional callable for advanced route type mapping.
|
| 689 |
Receives (route, mcp_type) and returns MCPType or None.
|
| 690 |
-
|
| 691 |
-
|
| 692 |
Receives (route, component) and can modify the component in-place.
|
| 693 |
Called on every created component.
|
| 694 |
timeout: Optional timeout (in seconds) for all requests
|
|
|
|
| 642 |
),
|
| 643 |
]
|
| 644 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 645 |
# Create server with custom mappings and route mapper
|
| 646 |
server = FastMCPOpenAPI(
|
| 647 |
openapi_spec=spec,
|
| 648 |
client=httpx.AsyncClient(),
|
| 649 |
name="API Server",
|
| 650 |
route_maps=custom_mappings,
|
|
|
|
| 651 |
)
|
| 652 |
```
|
| 653 |
"""
|
|
|
|
| 673 |
route_maps: Optional list of RouteMap objects defining route mappings
|
| 674 |
route_map_fn: Optional callable for advanced route type mapping.
|
| 675 |
Receives (route, mcp_type) and returns MCPType or None.
|
| 676 |
+
Called on every route, including excluded ones.
|
| 677 |
+
mcp_component_fn: Optional callable for component customization.
|
| 678 |
Receives (route, component) and can modify the component in-place.
|
| 679 |
Called on every created component.
|
| 680 |
timeout: Optional timeout (in seconds) for all requests
|