mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-21 04:54:17 +02:00
Fix NotFoundError handling in ErrorHandlingMiddleware
Add NotFoundError to the list of exceptions that map to MCP Resource not found error (code -32001) instead of Internal error (code -32603). Co-authored-by: Jeremiah Lowin <jlowin@users.noreply.github.com>
This commit is contained in:
parent
330eaed11f
commit
7ed87f7eb3
1 changed files with 3 additions and 1 deletions
|
|
@ -9,6 +9,8 @@ from typing import Any
|
|||
from mcp import McpError
|
||||
from mcp.types import ErrorData
|
||||
|
||||
from fastmcp.exceptions import NotFoundError
|
||||
|
||||
from .middleware import CallNext, Middleware, MiddlewareContext
|
||||
|
||||
|
||||
|
|
@ -90,7 +92,7 @@ class ErrorHandlingMiddleware(Middleware):
|
|||
return McpError(
|
||||
ErrorData(code=-32602, message=f"Invalid params: {str(error)}")
|
||||
)
|
||||
elif error_type in (FileNotFoundError, KeyError):
|
||||
elif error_type in (FileNotFoundError, KeyError, NotFoundError):
|
||||
return McpError(
|
||||
ErrorData(code=-32001, message=f"Resource not found: {str(error)}")
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue