MCPcopy Index your code
hub / github.com/modelcontextprotocol/python-sdk / from_envelope

Method from_envelope

src/mcp/server/connection.py:156–181  ·  view source on GitHub ↗

A born-ready connection populated from a request's `_meta` envelope. `initialized` is set and the envelope's client info/capabilities (when both supplied) are recorded as `client_params` so capability checks work. `outbound` defaults to the no-channel sentinel for the

(
        cls,
        protocol_version: str,
        client_info: Implementation | None,
        client_capabilities: ClientCapabilities | None,
        *,
        outbound: Outbound = _NO_CHANNEL,
    )

Source from the content-addressed store, hash-verified

154
155 @classmethod
156 def from_envelope(
157 cls,
158 protocol_version: str,
159 client_info: Implementation | None,
160 client_capabilities: ClientCapabilities | None,
161 *,
162 outbound: Outbound = _NO_CHANNEL,
163 ) -> Connection:
164 """A born-ready connection populated from a request's `_meta` envelope.
165
166 `initialized` is set and the envelope's client info/capabilities (when
167 both supplied) are recorded as `client_params` so capability checks
168 work. `outbound` defaults to the no-channel sentinel for the
169 single-exchange HTTP path; duplex modern transports (e.g. stdio) pass
170 the dispatcher so server-initiated messages have a back-channel.
171 """
172 client_params = None
173 if client_info is not None and client_capabilities is not None:
174 client_params = InitializeRequestParams(
175 protocol_version=protocol_version,
176 capabilities=client_capabilities,
177 client_info=client_info,
178 )
179 connection = cls(outbound, protocol_version=protocol_version, client_params=client_params)
180 connection.initialized.set()
181 return connection
182
183 @classmethod
184 def for_loop(

Calls 1