Commit fd53853
committed
fix: don't JSON pre-parse string args whose annotation only accepts str or None
pre_parse_json decided whether to json.loads a string argument with
'field_info.annotation is not str', which treats 'str | None' like a
non-string annotation. A valid string value that happens to parse as a
JSON object or array (e.g. a JSON-serialized template body) was silently
replaced with a dict/list and then failed model validation.
Only skip pre-parsing when every union member is str or None, so a plain
string is already fully valid. Unions with non-str members such as
'str | list[str]' keep the existing stringified-JSON handling.
Fixes #30551 parent 53117cb commit fd53853
2 files changed
Lines changed: 62 additions & 1 deletion
File tree
- src/mcp/server/mcpserver/utilities
- tests/server/mcpserver
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
36 | 55 | | |
37 | 56 | | |
38 | 57 | | |
| |||
169 | 188 | | |
170 | 189 | | |
171 | 190 | | |
172 | | - | |
| 191 | + | |
173 | 192 | | |
174 | 193 | | |
175 | 194 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
207 | 249 | | |
208 | 250 | | |
209 | 251 | | |
| |||
0 commit comments