Skip to content
Closed
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
24 changes: 20 additions & 4 deletions mcp_server/paddleocr_mcp/tasks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ async def _invoke_tool(
normalized_input = adapter.normalize(input_data)
adapter.validate(normalized_input)

ctx = get_context()
await ctx.info(
f"--- {self.tool_name} tool received input_data: {normalized_input[:50]} ---"
)
await self._log_received_input(normalized_input)

final_params = self._inference.get_final_params(runtime_params or {})
self._inference.validate_params(final_params)
Expand All @@ -100,6 +97,25 @@ async def _invoke_tool(
return_images=return_images,
)

async def _log_received_input(self, normalized_input: str) -> None:
"""Best-effort tool-call log; must never fail the tool call.

``get_context()`` raises when there is no active MCP request context,
and ``ctx.info()`` raises while the MCP session has not been established
(``request_context is None``). Either failure used to reach the client
as a generic, undiagnosable "Error calling tool" instead of running the
tool (issue #18391).
"""
try:
ctx = get_context()
if getattr(ctx, "request_context", None) is None:
return
await ctx.info(
f"--- {self.tool_name} tool received input_data: {normalized_input[:50]} ---"
)
except Exception: # noqa: BLE001 - logging is best-effort, never fatal
return

def register_tools(self, mcp: FastMCP) -> None:
mcp.tool(self.tool_name, description=self._tool_description())(
self._invoke_tool
Expand Down