Skip to content

Commit 53a46e6

Browse files
committed
Construct DEFAULT_CLIENT_INFO without building the Implementation model
The default Implementation instance was validated at import, which force-built the deferred Implementation model on every client import (~0.7 ms). The two literals are trusted, so model_construct produces an equal instance (same dict, same fields set) without touching the validator; the model now builds on the first real message instead.
1 parent 7fae576 commit 53a46e6

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

‎src/mcp/client/session.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@
6363
# `attrs`/`referencing` tree) in at module scope costs every client that never validates.
6464
from jsonschema.protocols import Validator
6565

66-
DEFAULT_CLIENT_INFO = types.Implementation(name="mcp", version="0.1.0")
66+
# Trusted literal: `model_construct` skips validation so importing this module does not
67+
# force-build the deferred `Implementation` model; equal to the validated instance.
68+
DEFAULT_CLIENT_INFO = types.Implementation.model_construct(name="mcp", version="0.1.0")
6769
DISCOVER_TIMEOUT_SECONDS = 10.0
6870
_NOTIFICATION_QUEUE_SIZE: Final = 256
6971

0 commit comments

Comments
 (0)