mirror of
https://github.com/apache/superset.git
synced 2026-04-18 07:35:09 +00:00
fix(mcp): Improve validation errors and field aliases to reduce failed LLM tool calls (#38625)
This commit is contained in:
committed by
GitHub
parent
56d6bb1913
commit
d91b96814e
@@ -481,10 +481,12 @@ class TestParseRequestDecorator:
|
||||
result = sync_tool('{"name": "test", "count": 5}', extra="data")
|
||||
assert result == "test:5:data"
|
||||
|
||||
def test_decorator_raises_validation_error_async(self):
|
||||
"""Should raise ValidationError for invalid data in async function."""
|
||||
def test_decorator_raises_tool_error_for_invalid_data_async(self):
|
||||
"""Should raise ToolError with field details for invalid data."""
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from fastmcp.exceptions import ToolError
|
||||
|
||||
@parse_request(self.RequestModel)
|
||||
async def async_tool(request, ctx=None):
|
||||
return f"{request.name}:{request.count}"
|
||||
@@ -493,20 +495,22 @@ class TestParseRequestDecorator:
|
||||
|
||||
mock_ctx = MagicMock()
|
||||
with patch("fastmcp.server.dependencies.get_context", return_value=mock_ctx):
|
||||
with pytest.raises(ValidationError):
|
||||
with pytest.raises(ToolError, match="Required fields for RequestModel"):
|
||||
asyncio.run(async_tool('{"name": "test"}')) # Missing count
|
||||
|
||||
def test_decorator_raises_validation_error_sync(self):
|
||||
"""Should raise ValidationError for invalid data in sync function."""
|
||||
def test_decorator_raises_tool_error_for_invalid_data_sync(self):
|
||||
"""Should raise ToolError with field details for invalid data."""
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from fastmcp.exceptions import ToolError
|
||||
|
||||
@parse_request(self.RequestModel)
|
||||
def sync_tool(request, ctx=None):
|
||||
return f"{request.name}:{request.count}"
|
||||
|
||||
mock_ctx = MagicMock()
|
||||
with patch("fastmcp.server.dependencies.get_context", return_value=mock_ctx):
|
||||
with pytest.raises(ValidationError):
|
||||
with pytest.raises(ToolError, match="Required fields for RequestModel"):
|
||||
sync_tool('{"name": "test"}') # Missing count
|
||||
|
||||
def test_decorator_with_complex_model_async(self):
|
||||
|
||||
Reference in New Issue
Block a user