Skip to content

Commit ae390c5

Browse files
committed
fix for long input names in tool creation
Signed-off-by: Shoumi <[email protected]>
1 parent 80f7bd6 commit ae390c5

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

mcpgateway/main.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
WebSocket,
4646
WebSocketDisconnect,
4747
)
48+
from fastapi.exceptions import RequestValidationError
4849
from fastapi.background import BackgroundTasks
4950
from fastapi.middleware.cors import CORSMiddleware
5051
from fastapi.responses import JSONResponse, RedirectResponse, StreamingResponse
@@ -290,6 +291,24 @@ async def validation_exception_handler(_request: Request, exc: ValidationError):
290291
return JSONResponse(status_code=422, content=ErrorFormatter.format_validation_error(exc))
291292

292293

294+
@app.exception_handler(RequestValidationError)
295+
async def request_validation_exception_handler(_request: Request, exc: RequestValidationError):
296+
"""Handle FastAPI request validation errors globally.
297+
298+
Intercepts RequestValidationError exceptions raised by FastAPI's automatic
299+
request validation and returns a properly formatted JSON error response.
300+
This ensures that user input is not reflected back in error messages.
301+
302+
Args:
303+
_request: The FastAPI request object that triggered the validation error.
304+
exc: The FastAPI RequestValidationError exception.
305+
306+
Returns:
307+
JSONResponse: A 422 Unprocessable Entity response with sanitized error details.
308+
"""
309+
return JSONResponse(status_code=422, content=ErrorFormatter.format_validation_error(exc))
310+
311+
293312
@app.exception_handler(IntegrityError)
294313
async def database_exception_handler(_request: Request, exc: IntegrityError):
295314
"""Handle SQLAlchemy database integrity constraint violations globally.

0 commit comments

Comments
 (0)