-
Notifications
You must be signed in to change notification settings - Fork 805
Description
I'm encountering an issue when calling the MCP server for the /get_articles/ endpoint using the Langchain MCP adapters. The error occurs when the publication_date field is not provided, even though it is marked as optional in the FastAPI endpoint definition. Additionally, if I specify a publication_date, I also get an error saying that the domain is mandatory, which should not be the case as both fields are optional.
Endpoint definition
@app.get("/get_articles/", response_model=List[ArticlesReadLight], tags=["Articles"])
async def get_articles(
publication_date: Optional[dt] = Query(default=None),
domain: Optional[str] = Query(default=None),
limit: Optional[int] = Query(default=5),
session: Session = Depends(get_session),
):
"""Return a list of articles depending on the domain and/or the publication date.
A limit can be set to return a specific number of articles, as an integer.
Raises a 404 error if no articles are matching the query."""
query = select(Articles)
where_clauses = []
if publication_date:
where_clauses.append(Articles.publish_date >= publication_date)
if domain:
where_clauses.append(Articles.domain == domain)
if where_clauses:
query = query.where(and_(*where_clauses))
query = query.order_by(Articles.publish_date.desc()).limit(limit)
# Log the generated SQL query
compiled_query = query.compile(compile_kwargs={"literal_binds": True})
logger.info(f"Publication Date: {publication_date}")
logger.info(f"Generated SQL Query: {compiled_query}")
articles = session.exec(query).all()
if not articles:
logger.warning("No articles found matching the criteria.")
raise HTTPException(status_code=404, detail="Articles not found")
logger.info(f"Retrieved {len(articles)} articles.")
return articles
Error message
Error: ToolException("Error executing tool get_articles_get_articles__get: 1 validation error for get_articles_get_articles__getArguments publication_date Field required [type=missing, input_value={'domain': 'news.google.com', 'limit': 5}, input_type=dict] For further information visit https://errors.pydantic.dev/2.9/v/missing") Please fix your mistakes.
Expected Behavior:
The publication_date field should be optional.
Actual Behavior:
The server raises a validation error indicating that the publication_date field is required, even though it is marked as optional in the endpoint definition.
fastapi_mcp version: 0.1.8
langchain-mcp-adapters version: 0.0.7