Skip to content

Commit 924efcf

Browse files
committed
fix: chain exceptions with 'from' in missed raise sites
Follow-up to #2564 which fixed 12 sites. These 4 were missed: - resources/templates.py: add 'from e' to preserve exception chain - in_memory_task_store.py: add 'from None' (same type, better message) - prompts/base.py: add 'from None' and 'from e' to two raise sites
1 parent 161834d commit 924efcf

3 files changed

Lines changed: 4 additions & 4 deletions

File tree

src/mcp/server/mcpserver/prompts/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ async def render(
182182
content = pydantic_core.to_json(msg, fallback=str, indent=2).decode()
183183
messages.append(Message(role="user", content=content))
184184
except Exception: # pragma: no cover
185-
raise ValueError(f"Could not convert prompt result to message: {msg}")
185+
raise ValueError(f"Could not convert prompt result to message: {msg}") from None
186186

187187
return messages
188188
except Exception as e: # pragma: no cover
189-
raise ValueError(f"Error rendering prompt {self.name}: {e}")
189+
raise ValueError(f"Error rendering prompt {self.name}: {e}") from e

src/mcp/server/mcpserver/resources/templates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,4 @@ async def create_resource(
130130
fn=lambda: result, # Capture result in closure
131131
)
132132
except Exception as e:
133-
raise ValueError(f"Error creating resource from template: {e}")
133+
raise ValueError(f"Error creating resource from template: {e}") from e

src/mcp/shared/experimental/tasks/in_memory_task_store.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ async def list_tasks(
169169
cursor_index = all_task_ids.index(cursor)
170170
start_index = cursor_index + 1
171171
except ValueError:
172-
raise ValueError(f"Invalid cursor: {cursor}")
172+
raise ValueError(f"Invalid cursor: {cursor}") from None
173173

174174
page_task_ids = all_task_ids[start_index : start_index + self._page_size]
175175
tasks = [Task(**self._tasks[tid].task.model_dump()) for tid in page_task_ids]

0 commit comments

Comments
 (0)