From 47888425e26aab12274b2dcdd2d1978c078b552f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=96=87=E9=BE=99?= Date: Thu, 29 May 2025 11:05:20 +0800 Subject: [PATCH] Print MCP exception stacktrace --- src/mcpo/utils/main.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/mcpo/utils/main.py b/src/mcpo/utils/main.py index 4d72815..a5151e6 100644 --- a/src/mcpo/utils/main.py +++ b/src/mcpo/utils/main.py @@ -1,4 +1,5 @@ import json +import traceback from typing import Any, Dict, ForwardRef, List, Optional, Type, Union from fastapi import HTTPException @@ -236,7 +237,9 @@ def get_tool_handler( return final_response except McpError as e: - print(f"MCP Error calling {endpoint_name}: {e.error}") + print( + f"MCP Error calling {endpoint_name}: {traceback.format_exc()}" + ) status_code = MCP_ERROR_TO_HTTP_STATUS.get(e.error.code, 500) raise HTTPException( status_code=status_code, @@ -247,7 +250,9 @@ def get_tool_handler( ), ) except Exception as e: - print(f"Unexpected error calling {endpoint_name}: {e}") + print( + f"Unexpected error calling {endpoint_name}: {traceback.format_exc()}" + ) raise HTTPException( status_code=500, detail={"message": "Unexpected error", "error": str(e)}, @@ -286,7 +291,9 @@ def get_tool_handler( return final_response except McpError as e: - print(f"MCP Error calling {endpoint_name}: {e.error}") + print( + f"MCP Error calling {endpoint_name}: {traceback.format_exc()}" + ) status_code = MCP_ERROR_TO_HTTP_STATUS.get(e.error.code, 500) # Propagate the error received from MCP as an HTTP exception raise HTTPException( @@ -298,7 +305,9 @@ def get_tool_handler( ), ) except Exception as e: - print(f"Unexpected error calling {endpoint_name}: {e}") + print( + f"Unexpected error calling {endpoint_name}: {traceback.format_exc()}" + ) raise HTTPException( status_code=500, detail={"message": "Unexpected error", "error": str(e)},