Commit 75d2d11
committed
fix: make Context logging methods spec-compliant by accepting Any data type
Per the MCP specification, the data field in LoggingMessageNotificationParams
allows any JSON serializable type, not just strings. The Context.log() and
convenience methods (debug, info, warning, error) were typed as message: str,
which prevented users from logging structured data like dicts, lists, numbers, etc.
Changes:
- Change message: str to data: Any in Context.log() and all convenience methods
- Remove the extra parameter (structured data can now be passed directly as data)
- Update docstrings to document that any JSON serializable type is accepted
- Update class docstring with examples of structured data logging
- Add test for logging structured data (dict, list, number, boolean, None)
Fixes #3971 parent 62575ed commit 75d2d11
File tree
2 files changed
+68
-24
lines changed- src/mcp/server/mcpserver
- tests/server/mcpserver
2 files changed
+68
-24
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1122 | 1122 | | |
1123 | 1123 | | |
1124 | 1124 | | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
1125 | 1130 | | |
1126 | 1131 | | |
1127 | 1132 | | |
| |||
1272 | 1277 | | |
1273 | 1278 | | |
1274 | 1279 | | |
1275 | | - | |
| 1280 | + | |
1276 | 1281 | | |
1277 | 1282 | | |
1278 | | - | |
1279 | 1283 | | |
1280 | 1284 | | |
1281 | 1285 | | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
1282 | 1290 | | |
1283 | 1291 | | |
1284 | | - | |
| 1292 | + | |
1285 | 1293 | | |
1286 | | - | |
1287 | 1294 | | |
1288 | 1295 | | |
1289 | | - | |
1290 | | - | |
1291 | | - | |
1292 | | - | |
1293 | | - | |
1294 | 1296 | | |
1295 | 1297 | | |
1296 | | - | |
| 1298 | + | |
1297 | 1299 | | |
1298 | 1300 | | |
1299 | 1301 | | |
| |||
1346 | 1348 | | |
1347 | 1349 | | |
1348 | 1350 | | |
1349 | | - | |
1350 | | - | |
1351 | | - | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
1352 | 1354 | | |
1353 | | - | |
1354 | | - | |
1355 | | - | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
1356 | 1358 | | |
1357 | | - | |
1358 | | - | |
1359 | | - | |
1360 | | - | |
1361 | | - | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
1362 | 1362 | | |
1363 | | - | |
1364 | | - | |
1365 | | - | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1070 | 1070 | | |
1071 | 1071 | | |
1072 | 1072 | | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
1073 | 1117 | | |
1074 | 1118 | | |
1075 | 1119 | | |
| |||
0 commit comments