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
5 changes: 5 additions & 0 deletions src/fast_agent/commands/handlers/mcp_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import math
import re
import shlex
from dataclasses import dataclass
Expand Down Expand Up @@ -123,6 +124,10 @@ def parse_connect_input(target_text: str) -> ParsedMcpConnectInput:
if idx >= len(tokens):
raise ValueError("Missing value for --timeout")
timeout_seconds = float(tokens[idx])
if not math.isfinite(timeout_seconds) or timeout_seconds <= 0:
raise ValueError(
"Invalid value for --timeout: expected a finite number greater than 0"
)
elif token == "--oauth":
trigger_oauth = True
elif token == "--no-oauth":
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/fast_agent/commands/test_mcp_runtime_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,15 @@ async def attach_mcp_server(self, agent_name, server_name, server_config=None, o
"for this connection mode."
)


@pytest.mark.parametrize("raw_timeout", ["nan", "inf", "-inf", "0", "-1"])
def test_parse_connect_input_rejects_non_finite_or_non_positive_timeout(
raw_timeout: str,
) -> None:
with pytest.raises(ValueError, match="--timeout"):
mcp_runtime.parse_connect_input(f"npx demo-server --timeout {raw_timeout}")


@pytest.mark.asyncio
async def test_handle_mcp_connect_and_disconnect() -> None:
manager = _Manager()
Expand Down
Loading