libtmux_mcp.middleware.ToolErrorResultMiddleware
Python
- Python
- Ruby Unavailable
- Lua Unavailable
- TypeScript Unavailable
- Rust Unavailable
- Go Unavailable
- Java Unavailable
- .NET Unavailable
- C++ Unavailable
- Swift Unavailable
- Bases:
- ErrorHandlingMiddleware
Convert tool-call failures into rich
ToolResulterrors.Replaces the stock
ErrorHandlingMiddlewarebehavior fortools/callonly. The stocktransform_errors=Truepath funnels every non-MCP exception through a-32603catch-all, so agents received"Internal error: Pane not found: %5"— the transform mangled every expected failure message. This subclass intercepts tool-call exceptions first (on_call_toolis the innermost hook of a middleware's chain) and returns_error_tool_resultinstead; non-tool messages fall through to the inheritedon_message.That inherited transform matches the not-found exception types by exact class --
error_type in (FileNotFoundError, KeyError, NotFoundError)-- so only an unknown resource URI, which fastmcp raises asNotFoundErroritself, reaches a client as-32002. Thetmux://handlers raiseResourceErrorfor a missing session, and path screening raisesResourceSecurityError, aNotFoundError*subclass*; neither is an exact match, so both arrive as-32603"Internal error" -- the code that tells a client the server is broken, for what is really an absent or disallowed target.Logging honors
FastMCPError.log_level(fastmcp >= 3.3): the expected failures demoted to WARNING byExpectedToolErrorno longer get re-shouted at ERROR by the stock_log_error. Argument-schema validation failures — raised by fastmcp before tool code can classify them — are treated as expected too (see_is_schema_validation_error), and when the rejected arguments include unexpected names the error result carries a synthesized suggestion telling the agent which names to drop or fix (see_error_tool_result).Ordering invariant: must sit outside
AuditMiddlewareandToolsetMiddleware. Both depend on exception semantics: audit detects failures by catching them, and toolset denials must propagate as exceptions for audit to record them. Converting the exception to a result any deeper in the stack would silently break both.
Members
- on_call_tool ( self , context : MiddlewareContext , call_next : t.Any ) t.Any
-
Convert tool-call exceptions into
is_errorresults.