Skip to main content

lifecycle_response

Function lifecycle_response 

Source
pub fn lifecycle_response(
    req: &Request,
    server_info: &Value,
    capabilities: &Value,
) -> Option<Response>
Expand description

Answer the three lifecycle methods every MCP server must handle, in ONE place, version-aware across both eras — the server-side mirror of the client’s version negotiation. Returns Some(response) for initialize / server/discover / ping, or None if req.method is a domain method the Handler must route.

  • initialize (legacy handshake): negotiate the protocol version — echo the peer’s requested version when it’s supported, else fall back to our latest legacy PROTOCOL_VERSION.
  • server/discover (modern, stateless): advertise the full SUPPORTED_PROTOCOL_VERSIONS list + capabilities in one call, so a modern client needn’t fall back to the legacy handshake. Answering both is what makes the embedder a dual-era server: a peer of either era completes its lifecycle unaided.
  • ping: an empty result.

server_info is the {name, version} object and capabilities the advertised capability object; both are echoed verbatim into the two lifecycle replies. When the crate gains support for a new protocol version, both replies pick it up here without the embedder changing anything.