-
Notifications
You must be signed in to change notification settings - Fork 6k
/
Copy pathtest_mcp_config.py
63 lines (48 loc) · 1.96 KB
/
test_mcp_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import pytest
from openhands.core.config.mcp_config import MCPConfig
def test_valid_sse_config():
"""Test a valid SSE configuration."""
config = MCPConfig(mcp_servers=['http://server1:8080', 'http://server2:8080'])
config.validate_servers() # Should not raise any exception
def test_empty_sse_config():
"""Test SSE configuration with empty servers list."""
config = MCPConfig(mcp_servers=[])
config.validate_servers()
def test_invalid_sse_url():
"""Test SSE configuration with invalid URL format."""
config = MCPConfig(mcp_servers=['not_a_url'])
with pytest.raises(ValueError) as exc_info:
config.validate_servers()
assert 'Invalid URL' in str(exc_info.value)
def test_duplicate_sse_urls():
"""Test SSE configuration with duplicate server URLs."""
config = MCPConfig(mcp_servers=['http://server1:8080', 'http://server1:8080'])
with pytest.raises(ValueError) as exc_info:
config.validate_servers()
assert 'Duplicate MCP server URLs are not allowed' in str(exc_info.value)
def test_from_toml_section_valid():
"""Test creating config from valid TOML section."""
data = {
'mcp_servers': ['http://server1:8080'],
}
result = MCPConfig.from_toml_section(data)
assert 'mcp' in result
assert result['mcp'].mcp_servers == ['http://server1:8080']
def test_from_toml_section_invalid_sse():
"""Test creating config from TOML section with invalid SSE URL."""
data = {
'mcp_servers': ['not_a_url'],
}
with pytest.raises(ValueError) as exc_info:
MCPConfig.from_toml_section(data)
assert 'Invalid URL' in str(exc_info.value)
def test_complex_urls():
"""Test SSE configuration with complex URLs."""
config = MCPConfig(
mcp_servers=[
'https://user:pass@server1:8080/path?query=1',
'wss://server2:8443/ws',
'http://subdomain.example.com:9090',
]
)
config.validate_servers() # Should not raise any exception