-
Notifications
You must be signed in to change notification settings - Fork 719
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
When FastAPI endpoints use Pydantic models with Union types containing arrays (e.g., Union[str, List[str]]), the generated MCP tool schema is missing the required items property for the array type. This causes LLMs like OpenAI to reject the schema with: "Invalid schema for function 'xxx': In context=('properties', 'text'), array schema missing items."
To Reproduce
- Create a FastAPI app with a Union type parameter:
from fastapi import FastAPI
from pydantic import BaseModel
from typing import Union, List
from fastapi_mcp import FastApiMCP
app = FastAPI()
class TextRequest(BaseModel):
text: Union[str, List[str]] # Union with array type
keywords: List[str]
@app.post("/process")
def process_text(request: TextRequest):
return {"processed": True}
mcp = FastApiMCP(app)
- Connect an LLM (e.g., via LiteLLM) to the MCP server
- The LLM will fail to call the tool with error:
litellm.BadRequestError: OpenAIException - Error code: 400 - {
'error': {
'message': "Invalid schema for function 'process_text_process_post':
In context=('properties', 'text'), array schema missing items.",
'type': 'invalid_request_error',
'param': 'tools[0].function.parameters',
'code': 'invalid_function_parameters'
}
}
System Info
- OS: Ubuntu 22.04
- Python version: 3.12.6
- fastapi-mcp version: 0.4.0
- FastAPI version: 0.115.6
- Pydantic version: 2.10.4
- MCP version: 1.1.3
- LLM Provider: OpenAI (via LiteLLM)
andrewbolster
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working