Testing Suite
Relevant source files
The following files were used as context for generating this wiki page:
The Testing Suite for the MCP Server Code Execution Mode bridge is designed to ensure the reliability and security of the sandboxed Python execution environment and its interaction with the Model Context Protocol (MCP). It encompasses unit tests for internal logic, integration tests for end-to-end tool calling, and specialized testing for the persistent memory system and documentation discovery mechanisms.
The suite utilizes unittest and unittest.IsolatedAsyncioTestCase to handle the asynchronous nature of MCP communications. It employs mocking and in-process sandbox simulations to validate core logic without requiring a full container runtime during standard test execution.
Sources: tests/test_entrypoint.py:12-14, tests/test_integration.py:12-15, tests/test_memory.py:10-12
Core Testing Components
The testing architecture is divided into specialized modules that target specific layers of the bridge.
Entrypoint Generation and Execution
Tests in test_entrypoint.py focus on the RootlessContainerSandbox._render_entrypoint method. They simulate the container's internal environment by capturing sys.__stdout__ and providing a mock stdin to verify how the generated Python script handles RPC requests and user code execution.
The diagram above shows the sequence used to validate the container's internal entrypoint script without launching a real container.
Sources: tests/test_entrypoint.py:84-125, tests/test_entrypoint.py:168-185
Integration and Stub Servers
Integration tests verify the bridge's ability to discover, load, and call tools from external MCP servers. A StubIntegrationTests class uses a stub_mcp_server.py to simulate a real stdio-based MCP server, ensuring that the MCPBridge correctly routes calls through its PersistentMCPClient.
Sources: tests/test_integration.py:136-160, tests/test_integration.py:186-218
Memory System Validation
The MemorySystemTests validate the persistent data storage layer. These tests simulate the sandbox's filesystem by creating temporary directories and verifying atomic updates, sanitization of keys, and JSON serialization.
Sources: tests/test_memory.py:17-43, tests/test_memory.py:149-166
Testing Infrastructure Summary
| Component | Test File | Primary Focus | Key Classes/Methods |
|---|---|---|---|
| Entrypoint Logic | test_entrypoint.py | Sandbox internal script generation | _run_entrypoint, EntryPointGenerationTests |
| Tool Integration | test_integration.py | End-to-end MCP server communication | InProcessSandbox, StubIntegrationTests |
| Memory System | test_memory.py | Atomic persistence and sanitization | MemorySystemTests, _save_memory, _update_memory |
| Documentation | test_tool_docs.py | Discovery and search RPC handlers | ToolDocsTests, search_tool_docs |
| MCP Resources | test_resources.py | Capability document exposure | ResourceEndpointTests, read_resource |
Sources: tests/test_entrypoint.py, tests/test_integration.py, tests/test_memory.py, tests/test_tool_docs.py, tests/test_resources.py
Sandbox Simulation Architecture
To allow testing without a full container runtime (Podman/Docker), the suite uses an InProcessSandbox. This class implements the SandboxLike protocol but executes code locally using exec() while redirecting I/O.
This sequence diagram illustrates how the InProcessSandbox mediates tool calls back to the bridge via the rpc_handler during integration tests.
Sources: tests/test_integration.py:24-91, tests/test_integration.py:186-218
Specific Feature Testing
Documentation Discovery
Tests ensure that the mcp.runtime helpers provided to the LLM are accurate. This includes verifying that fuzzy search and summary queries return the expected tool metadata.
- Fuzzy Search: Validated in
test_tool_docs.pyto ensure keyword matching across server and tool descriptions. - Detail Levels: Tests confirm that
detail='full'returns theinputSchemawhiledetail='summary'omits it.
Sources: tests/test_tool_docs.py:44-52, tests/test_entrypoint.py:190-210
Memory Persistence and Sanitization
The memory tests specifically verify that the system handles edge cases like special characters in keys and atomic updates to JSON objects.
def test_key_sanitization(self):
"""Test that special characters in keys are sanitized."""
self._save_memory("key with spaces!", "value1")
self._save_memory("key/with/slashes", "value2")
# Should be able to load using original keys
self.assertEqual(self._load_memory("key with spaces!"), "value1")
Sources: tests/test_memory.py:175-184
Resource Endpoints
The ResourceEndpointTests verify that the bridge correctly advertises its capabilities via standard MCP resources, ensuring the CAPABILITY_RESOURCE_URI returns the SANDBOX_HELPERS_SUMMARY.
Sources: tests/test_resources.py:15-30
Conclusion
The Testing Suite provides a comprehensive validation layer for the MCP Bridge, ensuring that security constraints, tool proxying, and data persistence remain stable. By utilizing in-process simulations and mock stdio streams, the suite maintains high coverage and fast execution without the overhead of container management during development.
Sources: tests/test_integration.py, tests/test_entrypoint.py