Skip to content

feat: introduce FromMessage trait #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 20, 2025

Conversation

hashemix
Copy link
Member

📌 Summary

Introduced a new trait named FromMessage, this is useful for transforming mcp messages into another Type that could be serialized into a JsonrpcMessage.

For example, a ServerMessage can be constructed from a rust_mcp_schema::PingRequest by attaching a RequestId.
Eventually, the ServerMessage can be serialized into a valid JsonrpcMessage for transmission over the transport.

Example:

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::from_message(
        MessageFromServer::RequestFromServer(ping_request.into()),
        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

}

@hashemix hashemix self-assigned this Feb 20, 2025
@hashemix hashemix merged commit cc46100 into main Feb 20, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant