Skip to content

Commit d5aeca6

Browse files
committed
Remove as_dict method
1 parent 27c63e6 commit d5aeca6

File tree

2 files changed

+86
-4
lines changed

2 files changed

+86
-4
lines changed

src/mcp/client/config/mcp_servers_config.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ class MCPServerConfig(BaseModel):
3232
description: str | None = None
3333
isActive: bool = True
3434

35-
def as_dict(self) -> dict[str, Any]:
36-
"""Return the server configuration as a dictionary."""
37-
return self.model_dump(exclude_none=True)
38-
3935

4036
class StdioServerConfig(MCPServerConfig):
4137
"""Configuration for stdio-based MCP servers."""

tests/client/config/test_mcp_servers_config.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ def test_input_substitution():
202202
"command": "python -m ${input:module-name}",
203203
"args": ["--config", "${input:config-file}"],
204204
"env": {"API_KEY": "${input:api-key}", "ENV": "${input:environment}"},
205+
"isActive": True,
205206
},
206207
}
207208
}
@@ -415,6 +416,21 @@ def test_get_required_inputs_no_inputs_defined():
415416
assert required_inputs == []
416417

417418

419+
def test_get_required_inputs_empty_inputs_list():
420+
"""Test getting required inputs when inputs is explicitly set to an empty list."""
421+
config_data = {
422+
"inputs": [], # Explicitly empty list
423+
"servers": {"test_server": {"type": "stdio", "command": "python test.py"}}
424+
}
425+
426+
config = MCPServersConfig.model_validate(config_data)
427+
required_inputs = config.get_required_inputs()
428+
assert config.validate_inputs({}) == []
429+
430+
assert required_inputs == []
431+
assert config.inputs == [] # Verify inputs is actually an empty list, not None
432+
433+
418434
def test_validate_inputs_all_provided():
419435
"""Test input validation when all required inputs are provided."""
420436
config_data = {
@@ -743,3 +759,73 @@ def test_jsonc_multiline_strings_with_comments():
743759
test2 = config.servers["test2"]
744760
assert isinstance(test2, SSEServerConfig)
745761
assert test2.url == "https://example.com"
762+
763+
764+
def test_sse_type_inference():
765+
"""Test that servers with 'url' field (and SSE mention) are inferred as sse type."""
766+
config_data = {
767+
"servers": {
768+
"api_server": {
769+
"url": "https://api.example.com/sse"
770+
# No explicit type - should be inferred as sse
771+
# because "sse" is in the url
772+
},
773+
"webhook_server": {
774+
"url": "https://webhook.example.com/mcp/api",
775+
"description": "A simple SSE server",
776+
"headers": {"X-API-Key": "secret123"}
777+
# No explicit type - should be inferred as sse
778+
# because "SSE" is in the description
779+
}
780+
}
781+
}
782+
783+
config = MCPServersConfig.model_validate(config_data)
784+
785+
# Verify first server
786+
api_server = config.servers["api_server"]
787+
assert isinstance(api_server, SSEServerConfig)
788+
assert api_server.type == "sse" # Should be auto-inferred
789+
assert api_server.url == "https://api.example.com/sse"
790+
assert api_server.headers is None
791+
792+
# Verify second server
793+
webhook_server = config.servers["webhook_server"]
794+
assert isinstance(webhook_server, SSEServerConfig)
795+
assert webhook_server.type == "sse" # Should be auto-inferred
796+
assert webhook_server.url == "https://webhook.example.com/mcp/api"
797+
assert webhook_server.headers == {"X-API-Key": "secret123"}
798+
799+
800+
def test_streamable_http_type_inference():
801+
"""Test that servers with 'url' field (but no SSE mention) are inferred as streamable_http type."""
802+
config_data = {
803+
"servers": {
804+
"api_server": {
805+
"url": "https://api.example.com/mcp"
806+
# No explicit type - should be inferred as streamable_http
807+
# No mention of 'sse' in url, name, or description
808+
},
809+
"webhook_server": {
810+
"url": "https://webhook.example.com/mcp/api",
811+
"headers": {"X-API-Key": "secret123"}
812+
# No explicit type - should be inferred as streamable_http
813+
}
814+
}
815+
}
816+
817+
config = MCPServersConfig.model_validate(config_data)
818+
819+
# Verify first server
820+
api_server = config.servers["api_server"]
821+
assert isinstance(api_server, StreamableHTTPServerConfig)
822+
assert api_server.type == "streamable_http" # Should be auto-inferred
823+
assert api_server.url == "https://api.example.com/mcp"
824+
assert api_server.headers is None
825+
826+
# Verify second server
827+
webhook_server = config.servers["webhook_server"]
828+
assert isinstance(webhook_server, StreamableHTTPServerConfig)
829+
assert webhook_server.type == "streamable_http" # Should be auto-inferred
830+
assert webhook_server.url == "https://webhook.example.com/mcp/api"
831+
assert webhook_server.headers == {"X-API-Key": "secret123"}

0 commit comments

Comments
 (0)