Jeremiah Lowin Claude commited on
Commit
d33e60d
·
1 Parent(s): b3ed3b5

Fix parameter location enum handling in OpenAPI parser

Browse files

Fixes issue where ParameterLocation enum values from openapi_pydantic
were not properly converted to strings, causing validation errors.

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

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

src/fastmcp/utilities/openapi.py CHANGED
@@ -302,11 +302,15 @@ class OpenAPIParser(
302
 
303
  # Extract parameter info - handle both 3.0 and 3.1 parameter models
304
  param_in = parameter.param_in # Both use param_in
305
- param_location = self._convert_to_parameter_location(param_in)
 
 
 
 
306
  param_schema_obj = parameter.param_schema # Both use param_schema
307
 
308
  # Skip duplicate parameters (same name and location)
309
- param_key = (parameter.name, param_in)
310
  if param_key in seen_params:
311
  continue
312
  seen_params[param_key] = True
 
302
 
303
  # Extract parameter info - handle both 3.0 and 3.1 parameter models
304
  param_in = parameter.param_in # Both use param_in
305
+ # Handle enum or string parameter locations
306
+ param_in_str = (
307
+ param_in.value if hasattr(param_in, "value") else param_in
308
+ )
309
+ param_location = self._convert_to_parameter_location(param_in_str)
310
  param_schema_obj = parameter.param_schema # Both use param_schema
311
 
312
  # Skip duplicate parameters (same name and location)
313
+ param_key = (parameter.name, param_in_str)
314
  if param_key in seen_params:
315
  continue
316
  seen_params[param_key] = True
tests/server/openapi/test_openapi_path_parameters.py CHANGED
@@ -455,3 +455,28 @@ async def test_array_query_parameter_exploded_format(mock_client):
455
  json=None,
456
  timeout=None,
457
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
455
  json=None,
456
  timeout=None,
457
  )
458
+
459
+
460
+ def test_parameter_location_enum_handling():
461
+ """Test that ParameterLocation enum values are handled correctly (issue #950)."""
462
+ from fastapi import FastAPI, Path, Query
463
+
464
+ from fastmcp import FastMCP
465
+
466
+ # Create FastAPI app with path and query parameters
467
+ app = FastAPI(title="Parameter Location Test")
468
+
469
+ @app.get("/tenants/{tenant_id}/data")
470
+ async def get_tenant_data(
471
+ tenant_id: str = Path(..., description="The tenant ID"),
472
+ limit: int = Query(10, description="Data limit"),
473
+ ):
474
+ return {"tenant_id": tenant_id, "limit": limit}
475
+
476
+ # This should not raise a validation error about ParameterLocation
477
+ mcp_server = FastMCP(
478
+ name="Test MCP", instructions="Test server for parameter location enum handling"
479
+ ).from_fastapi(app, name="Test MCP", tags={"test"})
480
+
481
+ # Verify the server was created successfully
482
+ assert mcp_server is not None