"""Generated tests for my-mcp MCP server tools.
This file is automatically generated to test that all tools can be loaded
and executed successfully.
"""
import sys
from pathlib import Path
import pytest
# Add src to Python path
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
from core.server import DynamicMCPServer # noqa: E402
class TestToolLoading:
"""Test that all tools can be loaded successfully."""
def test_server_initialization(self) -> None:
"""Test that the server can be initialized."""
server = DynamicMCPServer(name="Test Server", tools_dir="src/tools")
assert server is not None
assert server.name == "Test Server"
def test_tool_discovery(self) -> None:
"""Test that tools can be discovered."""
server = DynamicMCPServer(name="Test Server", tools_dir="src/tools")
# Load tools without failing
try:
server.load_tools()
assert True # If we get here, loading succeeded
except SystemExit:
pytest.fail("Tool loading failed - server exited")
def test_loaded_tools_count(self) -> None:
"""Test that expected tools are loaded."""
server = DynamicMCPServer(name="Test Server", tools_dir="src/tools")
server.load_tools()
# At minimum, we should have the echo tool
assert len(server.loaded_tools) >= 1
assert "echo" in server.loaded_tools
def test_tool_functions_callable(self) -> None:
"""Test that loaded tool functions are callable."""
server = DynamicMCPServer(name="Test Server", tools_dir="src/tools")
server.load_tools()
tools = server.get_tools_sync()
for tool_name, tool in tools.items():
assert hasattr(tool, 'fn'), f"Tool {tool_name} has no fn attribute"
assert callable(tool.fn), f"Tool {tool_name} is not callable"
class TestEchoTool:
"""Test the example echo tool."""
def test_echo_tool_exists(self) -> None:
"""Test that the echo tool exists and can be loaded."""
server = DynamicMCPServer(name="Test Server", tools_dir="src/tools")
server.load_tools()
assert "echo" in server.loaded_tools
def test_echo_tool_function(self) -> None:
"""Test that the echo tool function works."""
# Get the tool from the server
server = DynamicMCPServer(name="Test Server", tools_dir="src/tools")
server.load_tools()
tools = server.get_tools_sync()
assert "echo" in tools
# Call the tool function
echo_tool = tools["echo"]
result = echo_tool.fn("Hello, World!")
assert isinstance(result, str)
assert "Hello, World!" in result