mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-13 23:11:40 +00:00
fix(mcp): require server_name or alias when creating an MCP server
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
ae74b06ae3
commit
bbfc51da04
2 changed files with 25 additions and 2 deletions
|
|
@ -195,11 +195,16 @@ if MCP_AVAILABLE:
|
|||
expires_at: datetime
|
||||
|
||||
def _validate_mcp_server_name_fields(payload: Any) -> None:
|
||||
candidates: list[tuple[str, str | None]] = []
|
||||
|
||||
server_name = getattr(payload, "server_name", None)
|
||||
alias = getattr(payload, "alias", None)
|
||||
|
||||
if not server_name and not alias:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail={"error": "An MCP server requires a server_name or alias."},
|
||||
)
|
||||
|
||||
candidates: list[tuple[str, str | None]] = []
|
||||
if server_name:
|
||||
candidates.append(("server_name", server_name))
|
||||
if alias:
|
||||
|
|
|
|||
|
|
@ -3624,6 +3624,24 @@ class TestManagementPayloadValidation:
|
|||
|
||||
assert payload.alias == "valid_server"
|
||||
|
||||
def test_rejects_missing_server_name_and_alias(self):
|
||||
payload = SimpleNamespace(server_name=None, alias=None)
|
||||
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
mgmt_endpoints.validate_and_normalize_mcp_server_payload(payload)
|
||||
|
||||
assert exc_info.value.status_code == 400
|
||||
assert "server_name or alias" in exc_info.value.detail["error"]
|
||||
|
||||
def test_rejects_empty_server_name_and_alias(self):
|
||||
payload = SimpleNamespace(server_name="", alias="")
|
||||
|
||||
with pytest.raises(HTTPException) as exc_info:
|
||||
mgmt_endpoints.validate_and_normalize_mcp_server_payload(payload)
|
||||
|
||||
assert exc_info.value.status_code == 400
|
||||
assert "server_name or alias" in exc_info.value.detail["error"]
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_health_check_view_all_mode(self):
|
||||
"""view_all mode should return health info for all MCP servers."""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue