From b89cabc7df5dfa48f893775a07872729532201b5 Mon Sep 17 00:00:00 2001 From: Allen Porter Date: Thu, 2 Jan 2025 09:30:18 +0000 Subject: [PATCH] fix: Add constructor for McpError to allow setting field Backport of #116 by @allenporter to v1.1.x branch. Fixes an issue where exception handling code fails with AttributeError when accessing the error field of McpError. --- src/mcp/shared/exceptions.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/mcp/shared/exceptions.py b/src/mcp/shared/exceptions.py index d8855b8..97a1c09 100644 --- a/src/mcp/shared/exceptions.py +++ b/src/mcp/shared/exceptions.py @@ -7,3 +7,8 @@ class McpError(Exception): """ error: ErrorData + + def __init__(self, error: ErrorData): + """Initialize McpError.""" + super().__init__(error.message) + self.error = error