Skip to content

Commit 723770d

Browse files
author
Raed Lazreg
committed
fix: import ContentBlock under TYPE_CHECKING to avoid circular import
exceptions.py is imported during mcp package init (before mcp.types is registered), so a top-level 'from mcp.types import ContentBlock' fails with ModuleNotFoundError. content is only used as an annotation, so guard the import with TYPE_CHECKING and add 'from __future__ import annotations'.
1 parent 411b164 commit 723770d

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎src/mcp/server/mcpserver/exceptions.py‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
"""Custom exceptions for MCPServer."""
22

3-
from mcp.types import ContentBlock
3+
from __future__ import annotations
4+
5+
from typing import TYPE_CHECKING
6+
7+
if TYPE_CHECKING:
8+
# Imported under TYPE_CHECKING to avoid a circular import: this module is
9+
# pulled in during `mcp` package initialization (before `mcp.types` is
10+
# registered), and `content` only needs `ContentBlock` as an annotation.
11+
from mcp.types import ContentBlock
412

513

614
class MCPServerError(Exception):

0 commit comments

Comments
 (0)