Index
Public testing helpers for MADA and extension packages.
The objects re-exported here are intended to be stable import targets for test
code outside the core repository. They package up the server-state assertions,
tool-discovery helpers, and AI-driven end-to-end runner used by the MADA test
suite so extension packages can reuse the same utilities instead of copying
them into their own tests/ directories.
AgentTestRunner
Async test harness for starting MCP servers and querying them through an agent.
The runner accepts explicit paths to a server configuration and an agent configuration. During startup it randomizes server ports, rewrites matching MCP URLs in the agent config, launches the configured servers, validates the observed server state, and then initializes the requested agent class.
The default agent class is MultiServerAgent, but tests may substitute any
compatible implementation that accepts config_path=..., exposes an async
initialize(stack) method, and supports process_query(...).
Source code in mada_tools/testing/agent_runner.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
__aenter__()
async
__aexit__(exc_type, exc, tb)
async
__init__(servers_config_path, agent_config_path, agent_cls=MultiServerAgent)
Initialize the test runner.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
servers_config_path
|
Path
|
Path to the MCP server configuration JSON. |
required |
agent_config_path
|
Path
|
Path to the agent configuration JSON. |
required |
agent_cls
|
type[AgentProtocol]
|
Agent implementation to instantiate after servers are
running. Defaults to |
MultiServerAgent
|
Source code in mada_tools/testing/agent_runner.py
close()
async
Tear down the agent, servers, and temporary config files.
Cleanup is best-effort so tests do not leak background servers or randomized config files even when startup or prompt execution fails.
Source code in mada_tools/testing/agent_runner.py
process_query(prompt)
async
Process one prompt against the initialized agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
Natural-language prompt to send through the managed agent. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Agent response including tool-context annotations. |
Source code in mada_tools/testing/agent_runner.py
start()
async
Prepare randomized configs, start servers, and initialize the agent.
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If either input configuration path does not exist. |
Exception
|
Propagates any server-startup or agent-initialization error after best-effort cleanup. |
Source code in mada_tools/testing/agent_runner.py
collect_server_tools(active_servers, expected_tools)
async
Collect tools exposed by each active server and optionally assert on them.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
active_servers
|
dict[str, Any]
|
Active server objects keyed by server name. |
required |
expected_tools
|
dict[str, set[str]]
|
Optional expected tool-name sets keyed by server name. When a server name is present, the discovered tool set must match exactly. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
dict[str, dict[str, Any]]: Per-server connection information and the set |
dict[str, dict[str, Any]]
|
of discovered tool names. |
Source code in mada_tools/testing/server_checks.py
get_server_env_vars(config_path, server_key)
Return the environment-variable mapping for one configured server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path
|
Path
|
Path to the server configuration JSON file. |
required |
server_key
|
str
|
Key identifying the server entry inside the |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Environment-variable mapping for the requested server, |
dict[str, Any]
|
or an empty dictionary when the server has no |
Raises:
| Type | Description |
|---|---|
KeyError
|
If |
Source code in mada_tools/testing/server_checks.py
load_server_config(config_path)
Load and parse a server configuration JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path
|
Path
|
Path to a JSON file containing a top-level |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Parsed configuration dictionary. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the configuration file does not exist. |
Source code in mada_tools/testing/server_checks.py
validate_server_state(expected_servers, active_servers)
Validate that active servers match the expected server configuration.
The checks cover presence, host, port, running status, and configured environment variables. The function raises assertion failures directly so it reads naturally inside tests.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expected_servers
|
dict[str, Any]
|
Expected server definitions from the config file. |
required |
active_servers
|
dict[str, Any]
|
Actual server objects returned by the server-state manager, keyed by server name. |
required |