Commit dbcccb3
fix: catch fastmcp 3.4.3's wrapped ValidationError in arg-validation middleware (#1757)
fastmcp 3.4.3 (tools/function_tool.py) re-raises an argument-validation
pydantic.ValidationError as fastmcp.exceptions.ValidationError, chained via
`from e`. ValidationErrorMiddleware only caught pydantic.ValidationError, so
under 3.4.3 the raw wrapped error propagated instead of ha-mcp's structured,
actionable ToolError (3 tests in test_validation_middleware.py failed once
fastmcp was bumped in #1753).
Catch both exception shapes and recover the pydantic errors from the
FastMCPValidationError's __cause__; re-raise any fastmcp ValidationError with no
pydantic cause (e.g. a return-value failure) unchanged. Cross-version safe: a
bare pydantic.ValidationError on older fastmcp is still handled directly.
Adds a version-independent regression test that synthesises the wrapped error so
the 3.4.3 path is exercised on the current (3.4.2) CI, not only once #1753 lands.
Co-authored-by: kingpanther13 <kingpanther13@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 8284017 commit dbcccb3
2 files changed
Lines changed: 54 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
6 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| 16 | + | |
14 | 17 | | |
15 | 18 | | |
16 | 19 | | |
| |||
40 | 43 | | |
41 | 44 | | |
42 | 45 | | |
43 | | - | |
44 | | - | |
45 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
46 | 60 | | |
47 | 61 | | |
48 | 62 | | |
| |||
73 | 87 | | |
74 | 88 | | |
75 | 89 | | |
| 90 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 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 | + | |
35 | 68 | | |
36 | 69 | | |
37 | 70 | | |
| |||
0 commit comments