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
17 changes: 16 additions & 1 deletion e2e_test/infra/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
from .gateway import Gateway, WorkerInfo, launch_cloud_gateway
from .gpu_monitor import GPUMonitor
from .gpu_monitor import should_monitor as should_monitor_gpu
from .mock_mcp import IMAGE_GENERATION_PNG_BASE64, MockMcpServer, mock_mcp_server
from .model_specs import ( # Default model paths; Model groups
CHAT_MODELS,
DEFAULT_EMBEDDING_MODEL_PATH,
Expand Down Expand Up @@ -161,3 +160,19 @@
# Evaluation
"run_eval",
]

# The mock MCP server is only used by the agentic (responses) lane and drags
# in the `mcp` SDK at import time. Resolve its symbols lazily so infra
# consumers that never touch it — model download, chat/router lanes — keep
# working even when the venv's `mcp` lacks `mcp.server.fastmcp` (e.g.
# TensorRT-LLM's `pip install --pre` resolving mcp to a 2.x pre-release,
# which removed the module).
_LAZY_MOCK_MCP = ("IMAGE_GENERATION_PNG_BASE64", "MockMcpServer", "mock_mcp_server")


def __getattr__(name: str) -> object:
if name in _LAZY_MOCK_MCP:
from . import mock_mcp

return getattr(mock_mcp, name)
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
Comment on lines +173 to +178

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To optimize module attribute lookups, we can cache the resolved attributes in the module's globals. This ensures that __getattr__ is only triggered once per attribute, and subsequent accesses will bypass __getattr__ entirely by retrieving the value directly from the module's namespace.

Suggested change
def __getattr__(name: str) -> object:
if name in _LAZY_MOCK_MCP:
from . import mock_mcp
return getattr(mock_mcp, name)
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
def __getattr__(name: str) -> object:
if name in _LAZY_MOCK_MCP:
from . import mock_mcp
value = getattr(mock_mcp, name)
globals()[name] = value
return value
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")

3 changes: 2 additions & 1 deletion e2e_test/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ dependencies = [
"grpcio-health-checking",
"httpx",
"jinja2",
"mcp>=1.0",
# infra.mock_mcp_server needs mcp.server.fastmcp: added in 1.2, removed in 2.0
"mcp>=1.2,<2",
"numpy",
"openai",
"pandas",
Expand Down
Loading