Skip to content

v0.1.7

Compare
Choose a tag to compare
@hashemix hashemix released this 21 Feb 10:53
8de4f4d

0.1.7 (2025-02-21)

Features

  • add message_type to MCPMessage trait (#26) (aca2336)

  • 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 trait

    async 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 trait

    async 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
    }
  • introduce FromMessage trait (#30) (cc46100)