fix(config): Add support for MCP server configuration parameters (#812)

* fix(config): Add support for MCP server configuration parameters

* refact: rename the sse_readtimeout to sse_read_timeout

* update the code with review comments

* update the MCP document for the latest change
This commit is contained in:
Willem Jiang
2026-01-10 15:59:49 +08:00
committed by GitHub
parent e52e69bdd4
commit 6b73a53999
9 changed files with 207 additions and 13 deletions

View File

@@ -91,6 +91,7 @@ async def test_load_mcp_tools_sse_success(mock_sse_client, mock_get_tools):
timeout_seconds=7,
)
assert result == ["toolB"]
# When sse_read_timeout is None, it should not be passed
mock_sse_client.assert_called_once_with(
url="http://localhost:1234",
headers={"Authorization": "Bearer 1234567890"},
@@ -99,6 +100,58 @@ async def test_load_mcp_tools_sse_success(mock_sse_client, mock_get_tools):
mock_get_tools.assert_awaited_once_with(mock_client, 7)
@pytest.mark.asyncio
@patch("src.server.mcp_utils._get_tools_from_client_session", new_callable=AsyncMock)
@patch("src.server.mcp_utils.sse_client")
async def test_load_mcp_tools_sse_with_sse_read_timeout(mock_sse_client, mock_get_tools):
"""Test that sse_read_timeout parameter is used when provided."""
mock_get_tools.return_value = ["toolC"]
mock_client = MagicMock()
mock_sse_client.return_value = mock_client
result = await mcp_utils.load_mcp_tools(
server_type="sse",
url="http://localhost:1234",
headers={"Authorization": "Bearer token"},
timeout_seconds=10,
sse_read_timeout=5,
)
assert result == ["toolC"]
# Both timeout_seconds and sse_read_timeout should be passed
mock_sse_client.assert_called_once_with(
url="http://localhost:1234",
headers={"Authorization": "Bearer token"},
timeout=10,
sse_read_timeout=5,
)
# But timeout_seconds should be used for the session timeout
mock_get_tools.assert_awaited_once_with(mock_client, 10)
@pytest.mark.asyncio
@patch("src.server.mcp_utils._get_tools_from_client_session", new_callable=AsyncMock)
@patch("src.server.mcp_utils.sse_client")
async def test_load_mcp_tools_sse_without_sse_read_timeout(mock_sse_client, mock_get_tools):
"""Test that timeout_seconds is used when sse_read_timeout is not provided."""
mock_get_tools.return_value = ["toolD"]
mock_client = MagicMock()
mock_sse_client.return_value = mock_client
result = await mcp_utils.load_mcp_tools(
server_type="sse",
url="http://localhost:1234",
timeout_seconds=20,
)
assert result == ["toolD"]
# When sse_read_timeout is not provided, it should not be passed
mock_sse_client.assert_called_once_with(
url="http://localhost:1234",
headers=None,
timeout=20,
)
mock_get_tools.assert_awaited_once_with(mock_client, 20)
@pytest.mark.asyncio
async def test_load_mcp_tools_sse_missing_url():
with pytest.raises(HTTPException) as exc: