@@ -40,8 +40,8 @@ use rmcp::{
4040} ;
4141use serde_json:: json;
4242
43- /// A stable, high-entropy secret. In a real deployment, load this from your
44- /// secret manager and keep it out of clients' reach. It must stay constant for
43+ /// A fixed key for this example. Real deployments should load at least 32 bytes
44+ /// of random secret key material from a secret manager and keep it stable for
4545/// the lifetime of any in-flight MRTR exchange.
4646const REQUEST_STATE_KEY : & [ u8 ] = b"example-request-state-signing-key-32b!" ;
4747
@@ -51,12 +51,11 @@ struct WeatherServer {
5151 codec : RequestStateCodec ,
5252}
5353
54- impl Default for WeatherServer {
55- fn default ( ) -> Self {
56- Self {
57- codec : RequestStateCodec :: try_new ( REQUEST_STATE_KEY )
58- . expect ( "example request-state key meets the minimum length" ) ,
59- }
54+ impl WeatherServer {
55+ fn new ( key : impl Into < Vec < u8 > > ) -> Result < Self , RequestStateError > {
56+ Ok ( Self {
57+ codec : RequestStateCodec :: try_new ( key) ?,
58+ } )
6059 }
6160}
6261
@@ -153,18 +152,19 @@ impl ClientHandler for InteractiveClient {
153152#[ tokio:: main]
154153async fn main ( ) -> anyhow:: Result < ( ) > {
155154 let ( server_transport, client_transport) = tokio:: io:: duplex ( 8192 ) ;
155+ let server = WeatherServer :: new ( REQUEST_STATE_KEY ) ?;
156156
157157 // Spin up the server side.
158158 tokio:: spawn ( async move {
159- let server = WeatherServer :: default ( )
159+ let server = server
160160 . serve ( server_transport)
161161 . await
162162 . expect ( "server should start" ) ;
163163 let _ = server. waiting ( ) . await ;
164164 } ) ;
165165
166166 // Connect the client (this performs the initialize handshake).
167- let client = InteractiveClient :: default ( ) . serve ( client_transport) . await ?;
167+ let client = InteractiveClient . serve ( client_transport) . await ?;
168168
169169 // 1. High-level auto mode: the SDK fulfils the elicitation and retries for us.
170170 println ! ( "== auto mode (call_tool) ==" ) ;
0 commit comments