Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions litellm/proxy/_experimental/mcp_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ def _capture_host_progress_callback(host_server) -> Optional[Callable]:
if not (host_ctx and hasattr(host_ctx, "meta") and host_ctx.meta):
return None
host_token = getattr(host_ctx.meta, "progressToken", None)
if not (host_token and hasattr(host_ctx, "session") and host_ctx.session):
if host_token is None or not (hasattr(host_ctx, "session") and host_ctx.session):
return None
host_session = host_ctx.session

Expand All @@ -732,7 +732,7 @@ async def forward_progress(progress: float, total: Optional[float]):
except Exception as e:
verbose_logger.error(f"Failed to forward progress to Host: {e}")

verbose_logger.debug(f"Host progressToken captured: {host_token[:8]}...")
verbose_logger.debug(f"Host progressToken captured: {str(host_token)[:8]}...")
return forward_progress

async def _build_virtual_call_logging_obj(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,47 @@ def test_returns_callable_when_token_present(self) -> None:
host.request_context.session = MagicMock()
assert callable(_capture_host_progress_callback(host))

def test_returns_callable_when_token_is_integer(self) -> None:
from litellm.proxy._experimental.mcp_server.server import (
_capture_host_progress_callback,
)

host = MagicMock()
host.request_context.meta.progressToken = 12345
host.request_context.session = MagicMock()
assert callable(_capture_host_progress_callback(host))

def test_returns_callable_when_token_is_zero(self) -> None:
from litellm.proxy._experimental.mcp_server.server import (
_capture_host_progress_callback,
)

host = MagicMock()
host.request_context.meta.progressToken = 0
host.request_context.session = MagicMock()
assert callable(_capture_host_progress_callback(host))

@pytest.mark.asyncio
async def test_forwarded_progress_token_preserves_integer_value(self) -> None:
from litellm.proxy._experimental.mcp_server.server import (
_capture_host_progress_callback,
)

host = MagicMock()
host.request_context.meta.progressToken = 12345
session = AsyncMock()
host.request_context.session = session

callback = _capture_host_progress_callback(host)
assert callback is not None
await callback(0.5, 1.0)

session.send_progress_notification.assert_awaited_once_with(
progress_token=12345,
progress=0.5,
total=1.0,
)


class TestHandleListToolsVirtual:
"""Covers the protocol list_tools early-return when the flag is enabled."""
Expand Down
Loading