/** * Shared error handling for MCP tool handlers. * * Converts arbitrary errors into a typed user-facing tool result, * distinguishing between not-found (404), client errors (400-499), * server errors (500-599), and network/timeout issues. */ import { ToolResult } from "@prefecthq/fastmcp-ts/server"; export interface ToolErrorContext { /** MCP tool name, e.g. "search_tenders" (used in stderr logs). */ toolName: string; /** Short gerund describing what failed, e.g. "searching tenders". */ action: string; } /** * Builds a FastMCP tool result flagged as an error, carrying a single * user-facing text block. Use it for every error path so tool errors are * consistently returned as `isError: true` results (which the model can read * and act on) rather than thrown as protocol errors. */ export declare function toolErrorResult(text: string): ToolResult; /** * Converts an unknown error thrown from a tool handler into a typed tool result * with a user-facing message that matches the failure mode. * * Always logs the underlying error to stderr for operator debugging. */ export declare function toToolErrorResult(error: unknown, ctx: ToolErrorContext): ToolResult;