fix: use conditional import for NotRequired to support Python 3.11+

Fixes #124

The issue was that `typing_extensions.NotRequired` was always imported,
but the dependency only installed typing_extensions for Python < 3.11.
In Python 3.11+, NotRequired is available in the standard typing module.

Changes:
- Added conditional import: use `typing.NotRequired` for Python 3.11+
- Falls back to `typing_extensions.NotRequired` for Python 3.10
- This eliminates the ModuleNotFoundError on Python 3.11+ environments

🤖 Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
This commit is contained in:
majiayu000 2025-12-10 22:26:12 +08:00
parent 53482d8955
commit 39acac79c8

View file

@ -6,7 +6,11 @@ from dataclasses import dataclass, field
from pathlib import Path
from typing import TYPE_CHECKING, Any, Literal, TypedDict
from typing_extensions import NotRequired
# NotRequired was added to typing in Python 3.11
if sys.version_info >= (3, 11):
from typing import NotRequired
else:
from typing_extensions import NotRequired
if TYPE_CHECKING:
from mcp.server import Server as McpServer