mxp

Crates.iomxp
lib.rsmxp
version0.3.0
created_at2025-11-01 12:35:18.147642+00
updated_at2025-12-20 21:46:44.509612+00
descriptionMXP (Mesh eXchange Protocol) - High-performance protocol for agent-to-agent communication
homepagehttps://getmxp.xyz
repositoryhttps://github.com/yafatek/mxp-protocol
max_upload_size
id1911953
size1,187,754
Feras Alawadi (ferasawadi)

documentation

README

MXP Logo

MXP Protocol

The High-Performance Protocol for AI Agent Communication

17x faster than JSON • A2A Compatible • Production Ready • Open Source

Crates.io Documentation License CI

WebsiteWhitepaperSpecificationCookbookA2A Guide


⚡ Performance at a Glance

┌────────────────────────────────────────────────────────────────────────────┐
│                         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

🎯 What is MXP?

MXP (Mesh eXchange Protocol) is a high-performance binary protocol designed for AI agent-to-agent communication. It provides:

  • 🚀 Blazing Fast — Sub-microsecond encoding/decoding with zero-copy design
  • 🔗 A2A Compatible — Works with Google's Agent-to-Agent protocol semantics
  • 🔒 Secure by Default — ChaCha20-Poly1305/AES-GCM encryption, X25519 key exchange
  • 📊 Built-in Observability — Every message includes trace context automatically
  • 🌊 Native Streaming — Optimized for LLM token streams
  • 📦 Minimal Overhead — 32-byte cache-aligned headers

The Enabler Philosophy

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)  │
└─────────────────────────────────────────────────────┘

🚀 Quick Start

Installation

cargo add mxp

Basic Usage

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());

With A2A Compatibility

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?;

With Secure Transport

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())?;

📊 Benchmarks

Encoding Performance

┌─────────────────────────────────────────────────────────────────────────────┐
│                        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 Performance

┌─────────────────────────────────────────────────────────────────────────────┐
│                        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 Comparison (256B Payload Roundtrip)

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

Run Benchmarks Yourself

# 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

🔧 Features

Message Types

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

Security

  • Handshake: Noise IK-inspired with X25519 key exchange
  • Encryption: ChaCha20-Poly1305 (default) or AES-256-GCM
  • Anti-Replay: Packet number tracking with sliding window
  • Key Rotation: Seamless key updates without interruption
  • Session Resumption: Fast reconnection with tickets

Feature Flags

[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

📖 Examples

# 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

🧪 Testing

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

Test Coverage

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

📋 Protocol Specification

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.


🗺️ Roadmap

✅ Completed (v0.2)

  • Core protocol with sub-microsecond encoding/decoding
  • Secure transport with encryption and reliability
  • A2A compatibility layer
  • Comprehensive test suite (235+ tests)
  • Production readiness validation

🚧 In Progress

  • JavaScript/TypeScript SDK
  • HTTP/WebSocket gateway for gradual adoption

📅 Planned

  • Python SDK (Q2 2026)
  • Go SDK (Q3 2026)
  • MXP Stack (one-command deployment)
  • Foundation governance

🤝 Contributing

We welcome contributions! See CONTRIBUTING.md for guidelines.

  • 🌍 SDK implementations in other languages
  • 🔧 Protocol enhancements
  • 📖 Documentation improvements
  • 🐛 Bug reports and test cases

📄 License

  • Protocol Specification: Public Domain (CC0)
  • Reference Implementation: MIT OR Apache-2.0

🔗 Links


🏢 Enterprise

For enterprise adoption, partnerships, and support:


MXP: Making AI agents communicate at the speed of thought

Open Source • High Performance • Production Ready

Commit count: 0

cargo fmt