Skip to main content

brainwires_agent_network/
lib.rs

1#![deny(missing_docs)]
2//! # Brainwires Agent Network
3//!
4//! Agent networking layer for the Brainwires Agent Framework.
5//!
6//! Provides an MCP server framework, middleware pipeline, agent IPC,
7//! remote bridge, and optional mesh networking support.
8//!
9//! ## Protocol-Layer Stack
10//!
11//! The networking layer is organized as a 5-layer protocol stack:
12//!
13//! 1. **Identity** — agent identity, capability advertisement, credentials
14//! 2. **Transport** — how bytes move (IPC, Remote, TCP, A2A, Pub/Sub)
15//! 3. **Routing** — where messages go (direct, topology, broadcast, content)
16//! 4. **Discovery** — how agents find each other (mDNS, registry, manual)
17//! 5. **Application** — user-facing API (NetworkManager, events)
18
19// ============================================================================
20// MCP Server Framework
21// ============================================================================
22/// WebSocket/HTTP connection types.
23pub mod connection;
24/// Error types for the agent network crate.
25pub mod error;
26/// MCP request handler trait.
27pub mod handler;
28/// MCP server transport (stdio).
29pub mod mcp_transport;
30/// Middleware pipeline (auth, logging, rate-limiting, tool filtering).
31pub mod middleware;
32/// MCP tool registry.
33pub mod registry;
34/// MCP server lifecycle.
35pub mod server;
36/// Networking transport layer — pluggable transports for agent communication.
37pub mod transport;
38
39pub use connection::{ClientInfo, RequestContext};
40pub use error::AgentNetworkError;
41pub use handler::McpHandler;
42pub use mcp_transport::{ServerTransport, StdioServerTransport};
43pub use middleware::{Middleware, MiddlewareChain, MiddlewareResult};
44pub use registry::{McpToolDef, McpToolRegistry, ToolHandler};
45pub use server::McpServer;
46
47// Re-export middleware implementations
48pub use middleware::auth::AuthMiddleware;
49pub use middleware::logging::LoggingMiddleware;
50pub use middleware::rate_limit::RateLimitMiddleware;
51pub use middleware::tool_filter::ToolFilterMiddleware;
52
53// ============================================================================
54// Agent Communication Backbone (IPC, Auth, Remote)
55// ============================================================================
56/// Authentication for agent network connections.
57pub mod auth;
58/// IPC (inter-process communication) socket protocol.
59pub mod ipc;
60/// Remote bridge and realtime protocol.
61pub mod remote;
62/// Common agent network traits.
63pub mod traits;
64
65// ============================================================================
66// Agent Management (tool registry + lifecycle trait)
67// ============================================================================
68/// Agent lifecycle management.
69pub mod agent_manager;
70/// Pre-built MCP tools for agent operations.
71pub mod agent_tools;
72
73pub use agent_manager::{AgentInfo, AgentManager, AgentResult, SpawnConfig};
74pub use agent_tools::AgentToolRegistry;
75
76// ============================================================================
77// Client
78// ============================================================================
79/// Client for connecting to a remote agent network server.
80#[cfg(feature = "client")]
81pub mod client;
82
83#[cfg(feature = "client")]
84pub use client::{AgentConfig, AgentNetworkClient, AgentNetworkClientError};
85
86// ============================================================================
87// Mesh Networking (topology, routing, discovery, federation)
88// ============================================================================
89/// Distributed agent mesh networking — topology, routing, discovery, federation.
90#[cfg(feature = "mesh")]
91pub mod mesh;
92
93// ============================================================================
94// Protocol-Layer Stack (Identity, Network Core)
95// ============================================================================
96/// Peer discovery — how agents find each other on the network.
97pub mod discovery;
98/// Agent identity, capability advertisement, and credentials.
99pub mod identity;
100/// Core network types: message envelopes, events, and errors.
101pub mod network;
102/// Message routing — direct, broadcast, and content-based routing.
103pub mod routing;
104
105pub use identity::{AgentCard, AgentIdentity, ProtocolId};
106pub use network::{
107    ConnectionState, MessageEnvelope, MessageTarget, NetworkError, NetworkEvent, NetworkManager,
108    NetworkManagerBuilder, Payload, TransportType,
109};
110pub use transport::{Transport, TransportAddress};
111
112#[cfg(feature = "ipc-transport")]
113pub use transport::IpcTransport;
114#[cfg(feature = "pubsub-transport")]
115pub use transport::PubSubTransport;
116#[cfg(feature = "remote-transport")]
117pub use transport::RemoteTransport;
118#[cfg(feature = "tcp-transport")]
119pub use transport::TcpTransport;
120#[cfg(feature = "a2a-transport")]
121pub use transport::{A2aTransport, a2a_message_to_envelope};