Commit b48657b
Add methods to query health endpoints (#29)
* Add methods to query health endpoints
* Add the cachetools library
* Cache server health results
* Fix test assertions for cacheable exceptions
* Move assertions outside pytest.raises() context to ensure execution
* Fix assertion to check exception type instead of ExceptionInfo instance
* Add length check to ensure test covers all cacheable exceptions
* Make patching consistent with rest of file using @patch.object decorator
* Add mock reset between test iterations
* Extract cache maxsize to private constant
* Add _SERVER_HEALTH_CACHE_MAXSIZE constant for maintainability
* Add proper docstrings for both class constants
* Add test to verify constant value
* Follows same pattern as _CACHEABLE_EXCEPTIONS
* Add missing test and usage example for HealthStatus.is_transient()
* Add comprehensive test coverage for is_transient() method
* Test both transient (timeout, unknown) and non-transient (ok, unreachable) states
* Also improve test coverage for is_healthy() method
* Add usage example in server_health() docstring showing retry logic pattern
* Improve docstrings for key private methods
* Add complete docstring for _raise_for_server_health() with Args and Raises sections
* Enhance _get_server_health() docs with reference to public API
* Improve _get_tool_definitions() with comprehensive exception documentation
* Helps developers working on public APIs understand private method contracts
* Make is_server_healthy() error handling more specific
* Only catch ServerUnhealthyError and ServerNotFoundError as 'not healthy'
* Let connection/auth/timeout errors propagate to caller
* Update docstring to document which exceptions can be raised
* Update test to verify new error propagation behavior
This improves error visibility - infrastructure issues (connection, auth) are
now distinguishable from server health status issues.
* Add thread safety to health check caching
* Add threading.RLock to protect cache access
* Pass lock to cached decorator for synchronized operations
* Wrap cache.clear() and cache.pop() operations with lock
* Document thread safety in class docstring
The performance impact is negligible since network I/O dominates
execution time. Cache stampede risk is minimal due to 10-second TTL
and typically small number of MCP servers.
* Add one more test case for test_is_healthy_error
---------
Co-authored-by: Peter Wilson <[email protected]>1 parent c95cf31 commit b48657b
File tree
8 files changed
+734
-8
lines changed- src/mcpd
- tests/unit
8 files changed
+734
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| |||
121 | 121 | | |
122 | 122 | | |
123 | 123 | | |
124 | | - | |
| 124 | + | |
| 125 | + | |
125 | 126 | | |
126 | 127 | | |
127 | 128 | | |
| |||
140 | 141 | | |
141 | 142 | | |
142 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
143 | 150 | | |
144 | 151 | | |
145 | 152 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
25 | | - | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| 35 | + | |
33 | 36 | | |
34 | 37 | | |
35 | 38 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
132 | 132 | | |
133 | 133 | | |
134 | 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 | + | |
135 | 170 | | |
136 | 171 | | |
137 | 172 | | |
| |||
0 commit comments