Thanks to visit codestin.com
Credit goes to docs.rhi.zone

Skip to content

Server-lessComposable Derive Macros for Rust

Write your implementation once, project it into multiple protocols

Quick Example

rust
use server_less::prelude::*;

struct UserService { /* ... */ }

#[http(prefix = "/api")]
#[cli(name = "users")]
#[mcp(namespace = "users")]
#[ws(path = "/ws")]
impl UserService {
    /// Create a new user
    pub async fn create_user(&self, name: String, email: String) -> Result<User, UserError> {
        // your implementation
    }

    /// Get user by ID
    pub async fn get_user(&self, id: String) -> Option<User> {
        // your implementation
    }
}

This generates:

  • HTTP: Axum router with POST /api/users, GET /api/users/{id} + OpenAPI spec
  • CLI: Clap commands: users create-user --name X --email Y
  • MCP: Model Context Protocol tools: users_create_user, users_get_user
  • WebSocket: JSON-RPC 2.0 over WebSocket

Available Macros

Runtime Protocols (6)

Generate working server implementations:

  • #[http] - REST/HTTP with Axum + OpenAPI ✅ Production Ready
  • #[cli] - Command-line with Clap ✅ Production Ready
  • #[mcp] - Model Context Protocol ✅ Production Ready
  • #[ws] - WebSocket JSON-RPC 2.0 ✅ Stable
  • #[jsonrpc] - Standalone JSON-RPC ✅ Stable
  • #[graphql] - GraphQL schema + resolvers ✅ Working*

Schema Generators (5)

Generate IDL/schema files:

  • #[grpc] - Protocol Buffers .proto files
  • #[capnp] - Cap'n Proto .capnp schemas
  • #[thrift] - Apache Thrift .thrift IDL
  • #[smithy] - AWS Smithy .smithy models
  • #[connect] - Connect RPC schemas

Specification Generators (4)

Generate API documentation:

  • #[openrpc] - OpenRPC specs (JSON-RPC docs)
  • #[asyncapi] - AsyncAPI specs (WebSocket/messaging)
  • #[jsonschema] - JSON Schema definitions
  • #[markdown] - Human-readable API docs

Blessed Presets (4)

Batteries-included shortcuts:

  • #[server]#[http] + #[serve(http)]
  • #[rpc]#[jsonrpc] + #[openrpc] + #[serve(jsonrpc)]
  • #[tool]#[mcp] + #[jsonschema]
  • #[program]#[cli] + #[markdown]

Utilities

  • #[derive(ServerlessError)] - Error code inference + HTTP status mapping
  • #[serve] - Compose multiple protocol routers
  • #[route] - Per-method HTTP overrides
  • #[param] - Per-parameter cross-protocol customization

Project Status

Current: v0.2.0 ✅

  • 18 macros implemented across 6 crates
  • 466 tests passing, 0 failures
  • Blessed presets: #[server], #[rpc], #[tool], #[program]
  • Mount points for nested subcommand composition
  • CLI output formatting with --json, --jq, --output-schema
  • Published on crates.io

See TODO.md for the backlog.

Design Philosophy

Server-less follows four core principles:

  1. Minimize Barrier to Entry - The simple case should be trivial: #[derive(Server)]
  2. Progressive Disclosure - Complexity appears only when you need it
  3. Gradual Refinement - Start simple, incrementally add control
  4. Not Here to Judge - Support multiple workflows, don't prescribe

Read more: Impl-First Design

Part of RHI

Server-less is part of the RHI ecosystem - tools for building composable systems.

Related projects:

  • Lotus - Object store (uses Server-less for server setup)
  • Spore - Lua runtime with LLM integration
  • Hypha - Async runtime primitives

Getting Started

  1. REST API Tutorial - Build a blog API in 30 minutes
  2. Multi-Protocol Tutorial - Expose one service over HTTP, CLI, MCP, and more
  3. Design Philosophy - Understand the impl-first approach
  4. Param Attributes - #[param] cross-protocol customization

Installation

toml
[dependencies]
# Get everything (recommended for getting started)
server-less = "0.2"

# Or select specific features
server-less = { version = "0.2", default-features = false, features = ["http", "cli", "mcp"] }

Contributing

Contributions welcome! See CLAUDE.md for development guidelines.

License

MIT License - see LICENSE for details.