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:
claude[bot] 2025-10-17 18:44:28 +00:00
commit 7ed87f7eb3

View file

@ -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)}")
)