feat: add modern client lifecycle modes (SEP-2575) (#995)
* feat: add modern client lifecycle modes * refactor: drop modern naming and dead cleanup * fix: gate request metadata on inline lifecycle only
This commit is contained in:
parent
81745f1375
commit
2e2c79173c
1 changed files with 1525 additions and 306 deletions
43
README.md
43
README.md
|
|
@ -74,6 +74,44 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||
```
|
||||
</details>
|
||||
|
||||
### Client lifecycle modes
|
||||
|
||||
`serve()` uses the legacy MCP lifecycle: the client sends `initialize`, receives
|
||||
the negotiated server information, and then sends `notifications/initialized`.
|
||||
Use [`ClientServiceExt::serve_with_lifecycle`](crates/rmcp/src/service/client.rs) to
|
||||
select another lifecycle explicitly:
|
||||
|
||||
```rust, ignore
|
||||
use rmcp::{ClientInfo, ClientLifecycleMode, ClientServiceExt, ProtocolVersion};
|
||||
|
||||
// Start directly with server/discover and include client metadata on every request.
|
||||
let client = ClientInfo::default()
|
||||
.serve_with_lifecycle(
|
||||
transport,
|
||||
ClientLifecycleMode::Discover {
|
||||
preferred_versions: vec![ProtocolVersion::V_2026_07_28],
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
|
||||
// Or probe the discover lifecycle and fall back when a legacy server reports
|
||||
// that server/discover is not implemented.
|
||||
let client = ClientInfo::default()
|
||||
.serve_with_lifecycle(
|
||||
transport,
|
||||
ClientLifecycleMode::Auto {
|
||||
preferred_versions: vec![ProtocolVersion::V_2026_07_28],
|
||||
legacy_version: Some(ProtocolVersion::V_2025_11_25),
|
||||
},
|
||||
)
|
||||
.await?;
|
||||
```
|
||||
|
||||
`ClientLifecycleMode::Initialize` is equivalent to the existing `serve()` behavior.
|
||||
Discover startup does not send `notifications/initialized`; discovery completes
|
||||
startup, and each subsequent request carries its protocol version, client
|
||||
information, and capabilities in `_meta`.
|
||||
|
||||
### Build a Server
|
||||
|
||||
<details>
|
||||
|
|
@ -812,10 +850,11 @@ impl ServerHandler for MyServer {
|
|||
|
||||
### Initialized notification
|
||||
|
||||
Clients send `initialized` after the handshake completes:
|
||||
Legacy clients send `initialized` after the `initialize` handshake completes.
|
||||
Clients using `ClientLifecycleMode::Discover` do not send this notification:
|
||||
|
||||
```rust
|
||||
// Sent automatically by rmcp during the serve() handshake.
|
||||
// Sent automatically by rmcp during the legacy serve() handshake.
|
||||
// Servers handle it via:
|
||||
impl ServerHandler for MyServer {
|
||||
async fn on_initialized(
|
||||
|
|
|
|||
Loading…
Reference in a new issue