Skip to content

Commit 37a6bb0

Browse files
committed
Move test fixtures from Python to mcp.json
More realistic
1 parent 25b3a7b commit 37a6bb0

File tree

3 files changed

+42
-51
lines changed

3 files changed

+42
-51
lines changed

src/mcp/client/config/mcp_servers_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def effective_args(self) -> list[str]:
3737
return parsed_args + explicit_args
3838

3939

40-
class StreamableHttpConfig(MCPServerConfig):
40+
class StreamableHTTPServerConfig(MCPServerConfig):
4141
"""Configuration for StreamableHTTP-based MCP servers."""
4242

4343
type: Literal["streamable_http"] = "streamable_http"
@@ -54,7 +54,7 @@ class SSEServerConfig(MCPServerConfig):
5454

5555

5656
# Discriminated union for different server config types
57-
ServerConfigUnion = Annotated[StdioServerConfig | StreamableHttpConfig | SSEServerConfig, Field(discriminator="type")]
57+
ServerConfigUnion = Annotated[StdioServerConfig | StreamableHTTPServerConfig | SSEServerConfig, Field(discriminator="type")]
5858

5959

6060
class MCPServersConfig(BaseModel):

tests/client/config/mcp.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"mcpServers": {
3+
"stdio_server": {
4+
"command": "python",
5+
"args": ["-m", "my_server"],
6+
"env": {"DEBUG": "true"}
7+
},
8+
"stdio_server_with_full_command": {
9+
"command": "python -m my_server"
10+
},
11+
"stdio_server_with_full_command_and_explicit_args": {
12+
"command": "python -m my_server",
13+
"args": ["--debug"]
14+
},
15+
"streamable_http_server_with_headers": {
16+
"url": "https://api.example.com/mcp",
17+
"headers": {"Authorization": "Bearer token123"}
18+
},
19+
"stdio_server_with_explicit_type": {
20+
"type": "stdio",
21+
"command": "python",
22+
"args": ["-m", "my_server"],
23+
"env": {"DEBUG": "true"}
24+
},
25+
"streamable_http_server_with_explicit_type": {
26+
"type": "streamable_http",
27+
"url": "https://api.example.com/mcp"
28+
},
29+
"sse_server_with_explicit_type": {
30+
"type": "sse",
31+
"url": "https://api.example.com/sse"
32+
}
33+
}
34+
}

tests/client/config/test_mcp_servers_config.py

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,57 +10,14 @@
1010
MCPServersConfig,
1111
SSEServerConfig,
1212
StdioServerConfig,
13-
StreamableHttpConfig,
13+
StreamableHTTPServerConfig,
1414
)
1515

1616

1717
@pytest.fixture
18-
def mcp_config_file(tmp_path: Path) -> Path:
19-
"""Create temporary JSON config file with mixed server types"""
20-
21-
config_data = {
22-
"mcpServers": {
23-
# Servers with inferred types
24-
"stdio_server": {
25-
"command": "python",
26-
"args": ["-m", "my_server"],
27-
"env": {"DEBUG": "true"},
28-
},
29-
"stdio_server_with_full_command": {
30-
"command": "python -m my_server",
31-
},
32-
"stdio_server_with_full_command_and_explicit_args": {
33-
"command": "python -m my_server", # Two args here: -m and my_server
34-
"args": ["--debug"], # One explicit arg here: --debug
35-
},
36-
"streamable_http_server_with_headers": {
37-
"url": "https://api.example.com/mcp",
38-
"headers": {"Authorization": "Bearer token123"},
39-
},
40-
# Servers with explicit types
41-
"stdio_server_with_explicit_type": {
42-
"type": "stdio", # Explicitly specified
43-
"command": "python",
44-
"args": ["-m", "my_server"],
45-
"env": {"DEBUG": "true"},
46-
},
47-
"streamable_http_server_with_explicit_type": {
48-
"type": "streamable_http", # Explicitly specified
49-
"url": "https://api.example.com/mcp",
50-
},
51-
"sse_server_with_explicit_type": {
52-
"type": "sse", # Explicitly specified
53-
"url": "https://api.example.com/sse",
54-
},
55-
}
56-
}
57-
58-
# Write to temporary file
59-
config_file_path = tmp_path / "mcp.json"
60-
with open(config_file_path, "w") as config_file:
61-
json.dump(config_data, config_file)
62-
63-
return config_file_path
18+
def mcp_config_file() -> Path:
19+
"""Return path to the mcp.json config file with mixed server types"""
20+
return Path(__file__).parent / "mcp.json"
6421

6522

6623
def test_stdio_server(mcp_config_file: Path):
@@ -96,7 +53,7 @@ def test_streamable_http_server_with_explicit_type(mcp_config_file: Path):
9653
config = MCPServersConfig.from_file(mcp_config_file)
9754

9855
http_server = config.servers["streamable_http_server_with_explicit_type"]
99-
assert isinstance(http_server, StreamableHttpConfig)
56+
assert isinstance(http_server, StreamableHTTPServerConfig)
10057
assert http_server.type == "streamable_http"
10158

10259

@@ -144,7 +101,7 @@ def test_streamable_http_server_with_headers(mcp_config_file: Path):
144101
config = MCPServersConfig.from_file(mcp_config_file)
145102

146103
http_server = config.servers["streamable_http_server_with_headers"]
147-
assert isinstance(http_server, StreamableHttpConfig)
104+
assert isinstance(http_server, StreamableHTTPServerConfig)
148105

149106
assert http_server.url == "https://api.example.com/mcp"
150107
assert http_server.headers == {"Authorization": "Bearer token123"}

0 commit comments

Comments
 (0)