Skip to content

Commit 75c84bf

Browse files
committed
fix: prevent MCPError from marking data as set when None
MCPError.__init__ always passed data=data to ErrorData(), even when data was None (the default). This marked data as 'set' in Pydantic's model_fields_set, causing exclude_unset=True to emit 'data': null on the wire. Fix by only passing data when non-None.
1 parent 43ee2d9 commit 75c84bf

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/mcp/shared/exceptions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ class MCPError(Exception):
1212

1313
def __init__(self, code: int, message: str, data: Any = None):
1414
super().__init__(code, message, data)
15-
self.error = ErrorData(code=code, message=message, data=data)
15+
if data is not None:
16+
self.error = ErrorData(code=code, message=message, data=data)
17+
else:
18+
self.error = ErrorData(code=code, message=message)
1619

1720
@property
1821
def code(self) -> int:

0 commit comments

Comments
 (0)