Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/fastmcp/prompts/prompt_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from mcp import GetPromptResult

from fastmcp import settings
from fastmcp.exceptions import NotFoundError, PromptError
from fastmcp.exceptions import FastMCPError, NotFoundError, PromptError
from fastmcp.prompts.prompt import FunctionPrompt, Prompt, PromptResult
from fastmcp.settings import DuplicateBehavior
from fastmcp.utilities.logging import get_logger
Expand Down Expand Up @@ -107,9 +107,8 @@ async def render_prompt(
try:
messages = await prompt.render(arguments)
return GetPromptResult(description=prompt.description, messages=messages)
except PromptError as e:
logger.exception(f"Error rendering prompt {name!r}")
raise e
except FastMCPError:
raise
except Exception as e:
logger.exception(f"Error rendering prompt {name!r}")
if self.mask_error_details:
Expand Down
23 changes: 9 additions & 14 deletions src/fastmcp/resources/resource_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pydantic import AnyUrl

from fastmcp import settings
from fastmcp.exceptions import NotFoundError, ResourceError
from fastmcp.exceptions import FastMCPError, NotFoundError, ResourceError
from fastmcp.resources.resource import Resource
from fastmcp.resources.template import (
ResourceTemplate,
Expand Down Expand Up @@ -268,10 +268,9 @@ async def get_resource(self, uri: AnyUrl | str) -> Resource:
uri_str,
params=params,
)
# Pass through ResourceErrors as-is
except ResourceError as e:
logger.error(f"Error creating resource from template: {e}")
raise e
# Pass through FastMCPErrors as-is
except FastMCPError:
raise
# Handle other exceptions
except Exception as e:
logger.error(f"Error creating resource from template: {e}")
Expand Down Expand Up @@ -299,10 +298,9 @@ async def read_resource(self, uri: AnyUrl | str) -> str | bytes:
try:
return await resource.read()

# raise ResourceErrors as-is
except ResourceError as e:
logger.exception(f"Error reading resource {uri_str!r}")
raise e
# raise FastMCPErrors as-is
except FastMCPError:
raise

# Handle other exceptions
except Exception as e:
Expand All @@ -322,11 +320,8 @@ async def read_resource(self, uri: AnyUrl | str) -> str | bytes:
try:
resource = await template.create_resource(uri_str, params=params)
return await resource.read()
except ResourceError as e:
logger.exception(
f"Error reading resource from template {uri_str!r}"
)
raise e
except FastMCPError:
raise
except Exception as e:
logger.exception(
f"Error reading resource from template {uri_str!r}"
Expand Down
12 changes: 5 additions & 7 deletions src/fastmcp/tools/tool_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pydantic import ValidationError

from fastmcp import settings
from fastmcp.exceptions import NotFoundError, ToolError
from fastmcp.exceptions import FastMCPError, NotFoundError, ToolError
from fastmcp.settings import DuplicateBehavior
from fastmcp.tools.tool import Tool, ToolResult
from fastmcp.tools.tool_transform import (
Expand Down Expand Up @@ -158,12 +158,10 @@ async def call_tool(self, key: str, arguments: dict[str, Any]) -> ToolResult:
tool = await self.get_tool(key)
try:
return await tool.run(arguments)
except ValidationError as e:
logger.exception(f"Error validating tool {key!r}: {e}")
raise e
except ToolError as e:
logger.exception(f"Error calling tool {key!r}")
raise e
except FastMCPError:
raise
except ValidationError:
raise
except Exception as e:
logger.exception(f"Error calling tool {key!r}")
if self.mask_error_details:
Expand Down
Loading