| Crates.io | mxp |
| lib.rs | mxp |
| version | 0.3.0 |
| created_at | 2025-11-01 12:35:18.147642+00 |
| updated_at | 2025-12-20 21:46:44.509612+00 |
| description | MXP (Mesh eXchange Protocol) - High-performance protocol for agent-to-agent communication |
| homepage | https://getmxp.xyz |
| repository | https://github.com/yafatek/mxp-protocol |
| max_upload_size | |
| id | 1911953 |
| size | 1,187,754 |
The High-Performance Protocol for AI Agent Communication
17x faster than JSON • A2A Compatible • Production Ready • Open Source
Website • Whitepaper • Specification • Cookbook • A2A Guide
┌────────────────────────────────────────────────────────────────────────────┐
│ MXP vs JSON (256B payload) │
├────────────────────────────────────────────────────────────────────────────┤
│ │
│ MXP ████ 466ns │
│ Bincode ████████ 887ns │
│ MsgPack ████████████████████ 3.9μs │
│ JSON ████████████████████████████████████████ 7.9μs │
│ │
│ MXP is 17x faster than JSON, 8x faster than MessagePack │
│ │
└────────────────────────────────────────────────────────────────────────────┘
| Metric | Target | Achieved | Status |
|---|---|---|---|
| Encoding (256B) | < 1μs | 266ns | ✅ 3.7x better |
| Decoding (256B) | < 1μs | 172ns | ✅ 5.8x better |
| Throughput | 100K msg/s | 116K msg/s | ✅ Exceeded |
| vs JSON | Faster | 17x faster | ✅ Verified |
MXP (Mesh eXchange Protocol) is a high-performance binary protocol designed for AI agent-to-agent communication. It provides:
MXP doesn't compete with existing standards—it makes them faster:
┌─────────────────────────────────────────────────────┐
│ Your Agent Framework / A2A │
│ (Keep your existing semantics) │
└─────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────┐
│ MXP Protocol Layer │
│ (High-performance encoding, built-in tracing) │
└─────────────────────────────────────────────────────┘
↓
┌─────────────────────────────────────────────────────┐
│ MXP Transport Layer │
│ (Custom UDP, encryption, reliability, streaming) │
└─────────────────────────────────────────────────────┘
cargo add mxp
use mxp::{Message, MessageType};
// Create a message
let message = Message::new(MessageType::Call, b"Hello, agent!");
// Encode to bytes (17x faster than JSON)
let bytes = mxp::protocol::encode(&message);
// Decode from bytes
let decoded = mxp::protocol::decode(bytes.into())?;
// Built-in trace context - no instrumentation needed
println!("Trace ID: {}", decoded.trace_id());
cargo add mxp --features a2a
use mxp::a2a::{Message, to_mxp, from_mxp};
// Create an A2A message
let msg = Message::user_text("Search for Rust tutorials");
// Convert to MXP for high-performance transport
let mxp_msg = to_mxp(&msg)?;
// Send over MXP transport (17x faster than JSON-RPC)
transport.send(mxp_msg).await?;
use mxp::transport::{Transport, Endpoint, PrivateKey};
let transport = Transport::default();
let handle = transport.bind("127.0.0.1:9000".parse()?)?;
// Establish encrypted connection
let private_key = PrivateKey::generate();
let (mut endpoint, session_keys) = Endpoint::connect(
handle,
peer_addr,
connection_id,
private_key,
peer_public_key
)?;
// Send encrypted datagrams
endpoint.send_datagram(b"Hello, secure world!".to_vec())?;
┌─────────────────────────────────────────────────────────────────────────────┐
│ Encoding Time by Payload Size │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ Empty (40B) ██ 97ns │
│ Small (104B) ████ 240ns │
│ Typical (296B) █████ 265ns │
│ Medium (1KB) ████ 211ns │
│ Large (4KB) ███████ 377ns │
│ XLarge (16KB) ██████████████████████████████ 1.5μs │
│ │
│ Throughput: 4.7 - 10.2 GiB/s │
│ │
└─────────────────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────────────────┐
│ Decoding Time by Payload Size │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ Empty (40B) █ 37ns │
│ Small (104B) ███ 114ns │
│ Typical (296B) ████ 172ns │
│ Medium (1KB) ████ 180ns │
│ Large (4KB) ████████ 350ns │
│ XLarge (16KB) ██████████████████████████████ 1.3μs │
│ │
│ Throughput: 1.0 - 12.0 GiB/s │
│ │
└─────────────────────────────────────────────────────────────────────────────┘
| Protocol | Time | vs MXP | Size Overhead |
|---|---|---|---|
| MXP | 466ns | baseline | 40 bytes |
| Bincode | 887ns | 1.9x slower | ~280 bytes |
| MessagePack | 3.9μs | 8.4x slower | ~300 bytes |
| JSON | 7.9μs | 17x slower | 400+ bytes |
# Codec benchmarks
cargo bench --bench codec
# Protocol comparison
cargo bench --bench comparison --features serde
# Production validation
cargo bench --bench production_validation --features serde
# View HTML reports
open target/criterion/report/index.html
First-class support for agent communication patterns:
| Type | Code | Description |
|---|---|---|
AgentRegister |
0x01 |
Register agent with mesh |
AgentDiscover |
0x02 |
Discover agents by capability |
AgentHeartbeat |
0x03 |
Keep-alive / health check |
Call |
0x10 |
Synchronous RPC |
Response |
0x11 |
Response to Call |
Event |
0x12 |
Async event (fire-and-forget) |
StreamOpen |
0x20 |
Open stream (LLM tokens) |
StreamChunk |
0x21 |
Stream data chunk |
StreamClose |
0x22 |
Close stream |
[dependencies]
mxp = { version = "0.2", features = ["a2a", "async-reactor"] }
| Feature | Description |
|---|---|
real-crypto |
Real cryptographic primitives (default) |
a2a |
Google A2A protocol compatibility |
async-reactor |
Tokio async support |
async-std-reactor |
async-std support |
aes-gcm |
AES-256-GCM cipher support |
compression |
zstd payload compression |
# Basic ping-pong
cargo run --example ping_pong
# A2A chat between agents
cargo run --example a2a_chat
# LLM token streaming
cargo run --example a2a_streaming
# Agent health monitoring
cargo run --example agent_health
# Secure datagram transport
cargo run --example datagram_secure
MXP uses property-based testing to ensure correctness:
# Run all tests (235+ tests)
cargo test
# Run property-based tests
cargo test --test stream_properties
cargo test --test connection_properties
cargo test --test security_properties
cargo test --test performance_properties
# Run integration tests
cargo test --test integration_tests
| Category | Tests | Properties Validated |
|---|---|---|
| Stream Management | 6 | Creation, delivery, ordering, flow control |
| Connection Management | 6 | Handshake, keepalive, reconnection |
| Packet Engine | 6 | Processing, security, ACK handling |
| Security | 6 | Crypto, replay protection, key rotation |
| Performance | 6 | Encoding, decoding, throughput |
| Production Readiness | 5 | Error handling, metrics, memory |
| Async Runtime | 6 | Tokio, async-std, cancellation |
| Integration | 20+ | End-to-end scenarios |
| Property | Value |
|---|---|
| Magic Number | 0x4D585031 ("MXP1") |
| Header Size | 32 bytes (cache-aligned) |
| Checksum | XXHash3 (64-bit) |
| Transport | UDP with reliability layer |
| Encryption | ChaCha20-Poly1305 / AES-GCM |
| Default Port | 9000 |
| Max Payload | 16 MB |
See SPEC.md for the complete wire format specification.
We welcome contributions! See CONTRIBUTING.md for guidelines.
For enterprise adoption, partnerships, and support:
MXP: Making AI agents communicate at the speed of thought
Open Source • High Performance • Production Ready