This commit is contained in:
2026-07-22 22:53:15 -07:00
parent d87fcb85be
commit 48132aa21c
6 changed files with 149 additions and 135 deletions
+9 -1
View File
@@ -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):