Refactor
This commit is contained in:
+9
-1
@@ -3,6 +3,7 @@ import uuid
|
||||
import json
|
||||
from typing import Any, Dict, Union, List
|
||||
from starlette.responses import Response
|
||||
from tools.utils import ToolError
|
||||
|
||||
class MCPServer:
|
||||
def __init__(self):
|
||||
@@ -40,7 +41,14 @@ class MCPServer:
|
||||
media_type="application/json"
|
||||
)
|
||||
|
||||
result_data = await tool.handler(args)
|
||||
try:
|
||||
result_data = await tool.handler(args)
|
||||
except ToolError as e:
|
||||
# Convert tool errors into a text response so the LLM can understand and potentially fix the input
|
||||
result_data = {"text": str(e)}
|
||||
except Exception as e:
|
||||
# Catch-all for unexpected crashes to prevent server death
|
||||
result_data = {"text": f"Unexpected internal error: {str(e)}"}
|
||||
|
||||
# Handle results that are already lists of content (for multimodal/multi-part responses)
|
||||
if isinstance(result_data, list):
|
||||
|
||||
Reference in New Issue
Block a user