feat(models): Add MCP configuration models and loading logic
This commit is contained in:
53
tests/test_mcp_config.py
Normal file
53
tests/test_mcp_config.py
Normal file
@@ -0,0 +1,53 @@
|
||||
import os
|
||||
import json
|
||||
import pytest
|
||||
from src import models
|
||||
|
||||
def test_mcp_server_config_to_from_dict():
|
||||
data = {
|
||||
"command": "node",
|
||||
"args": ["server.js"],
|
||||
"auto_start": True
|
||||
}
|
||||
cfg = models.MCPServerConfig.from_dict("test-server", data)
|
||||
assert cfg.name == "test-server"
|
||||
assert cfg.command == "node"
|
||||
assert cfg.args == ["server.js"]
|
||||
assert cfg.auto_start is True
|
||||
|
||||
assert cfg.to_dict() == data
|
||||
|
||||
def test_mcp_configuration_to_from_dict():
|
||||
data = {
|
||||
"mcpServers": {
|
||||
"server1": {
|
||||
"command": "python",
|
||||
"args": ["-m", "mcp_server"],
|
||||
"auto_start": False
|
||||
},
|
||||
"server2": {
|
||||
"url": "http://localhost:8080/sse",
|
||||
"auto_start": True
|
||||
}
|
||||
}
|
||||
}
|
||||
cfg = models.MCPConfiguration.from_dict(data)
|
||||
assert len(cfg.mcpServers) == 2
|
||||
assert cfg.mcpServers["server1"].command == "python"
|
||||
assert cfg.mcpServers["server2"].url == "http://localhost:8080/sse"
|
||||
assert cfg.to_dict() == data
|
||||
|
||||
def test_load_mcp_config(tmp_path):
|
||||
config_file = tmp_path / "mcp_config.json"
|
||||
data = {
|
||||
"mcpServers": {
|
||||
"test": {"command": "echo", "args": ["hello"]}
|
||||
}
|
||||
}
|
||||
config_file.write_text(json.dumps(data))
|
||||
|
||||
# We'll need a way to load from a specific path
|
||||
# Maybe models.load_mcp_config(path)
|
||||
cfg = models.load_mcp_config(str(config_file))
|
||||
assert "test" in cfg.mcpServers
|
||||
assert cfg.mcpServers["test"].command == "echo"
|
||||
Reference in New Issue
Block a user