v0.1.7
0.1.7 (2025-02-21)
Features
-
implement ToMessage trait (#31) (435f18b)
Details
ToMessage
Trait simplifies the construction of MCP messages, reducing the amount of code required:Example:
Before Introducing the
ToMessage
traitasync fn send_ping_request(ping_request: rust_mcp_schema::PingRequest) { let request_id = get_next_id(); // construct a ServerMessage from the ping_request , with request_id let message = ServerMessage::Request(ServerJsonrpcRequest::new( request_id, RequestFromServer::ServerRequest(ServerRequest::PingRequest(ping_request)), )); // serialize message into a valid rpcJsonrpcMessage string let rpc_message_json_str = message.to_string(); // send the ping request to the client tranport.send(rpc_message_json_str).await }
After Introducing the
ToMessage
traitasync fn send_ping_request(ping_request: rust_mcp_schema::PingRequest) { let request_id = get_next_id(); // construct a ServerMessage from the ping_request , with request_id let message: ServerMessage = ping_request .to_message(request_id) .unwrap(); // serialize message into a valid rpcJsonrpcMessage string let rpc_message_json_str = message.to_string(); // send the ping request to the client tranport.send(rpc_message_json_str).await }