MCPcopy Index your code
hub / github.com/bytecodealliance/wrpc

github.com/bytecodealliance/wrpc @v0.17.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.17.0 ↗ · + Follow
1,339 symbols 4,409 edges 178 files 153 documented · 11%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

wRPC

<strong>
<a href="https://component-model.bytecodealliance.org/">Component-native</a>
transport-agnostic RPC protocol and framework based on
<a href="https://component-model.bytecodealliance.org/design/wit.html">WebAssembly Interface Types (WIT)</a>
</strong>

A Bytecode Alliance hosted project

<a href="https://github.com/bytecodealliance/wrpc/actions?query=workflow%3Awrpc"><img src="https://github.com/bytecodealliance/wrpc/actions/workflows/wrpc.yml/badge.svg" alt="build status" /></a>
<a href="https://docs.rs/wrpc"><img src="https://docs.rs/wrpc/badge.svg" alt="Documentation Status" /></a>

About

wRPC facilitates execution of arbitrary functionality defined in WIT over network or other means of communication.

Main use cases for wRPC are: - out-of-tree WebAssembly runtime plugins - distributed WebAssembly component communication

Even though wRPC is designed for Wasm components first and foremost, it is fully usable outside of WebAssembly context and can serve as a general-purpose RPC framework.

wRPC uses component model value definiton encoding on the wire.

wRPC supports both dynamic (based on e.g. runtime WebAssembly component type introspection) and static use cases.

For static use cases, wRPC provides WIT binding generators for: - Rust - Go

wRPC fully supports the unreleased native WIT stream and future data types along with all currently released WIT functionality.

See specification for more info.

Installation

  • Using cargo:

    sh cargo install wrpc

  • Using nix:

    sh nix profile install github:bytecodealliance/wrpc

    or, without installing: nix shell github:bytecodealliance/wrpc

  • You can also download individual binaries from the release page

Quickstart

wRPC usage examples for different programming languages can be found at examples.

There are 2 different kinds of examples: - Native wRPC applications, tied to a particular wRPC transport (like Unix Domain Sockets, TCP, QUIC or NATS.io) - Generic Wasm components, that need to run in a Wasm runtime. Those can be executed, for example, using wrpc-wasmtime, to polyfill imports at runtime and serve exports using wRPC.

Requirements

  • For Rust components and wRPC applications: rust >= 1.82

  • For NATS.io transport: nats-server >= 2.10.20 or docker >= 24.0.6 (or any other OCI runtime)

Nix users can run nix develop anywhere in the repository to get all dependencies correctly set up

hello example

In this example we will serve and invoke a simple hello application.

Rust components

We will use the following two Rust components: - examples/rust/hello-component-client - examples/rust/hello-component-server

We will have to build these components first:

  • Build Wasm hello client:

    sh cargo build --release -p hello-component-client --target wasm32-wasip2

    Output is in target/wasm32-wasip2/release/hello-component-client.wasm

  • Build Wasm hello server:

    sh cargo build --release -p hello-component-server --target wasm32-wasip2

    Output is in target/wasm32-wasip2/release/hello_component_server.wasm

    NB: Rust uses _ separators in the filename, because a component is built as a reactor-style library

Using TCP transport

We will use the following two Rust wRPC applications using TCP transport: - examples/rust/hello-tcp-client - examples/rust/hello-tcp-server

[::1]:7761 is used as the default address

  1. Serve Wasm hello server via TCP

    sh wrpc-wasmtime tcp serve ./target/wasm32-wasip2/release/hello_component_server.wasm

    • Sample output:

      INFO wrpc_wasmtime_cli: serving instance function name="hello"

  2. Call Wasm hello server using a Wasm hello client via TCP:

    sh wrpc-wasmtime tcp run ./target/wasm32-wasip2/release/hello-component-client.wasm

    • Sample output in the client:

      hello from Rust

    • Sample output in the server:

      INFO wrpc_wasmtime_cli: serving instance function invocation

      INFO wrpc_wasmtime_cli: successfully served instance function invocation

  3. Call the Wasm hello server using a native wRPC hello client via TCP:

    sh cargo run -p hello-tcp-client

  4. Serve native wRPC hello server via TCP:

    sh cargo run -p hello-tcp-server [::1]:7762

  5. Call native wRPC hello server using native wRPC hello client via TCP:

    sh cargo run -p hello-tcp-client [::1]:7762

  6. Call native wRPC hello server using Wasm hello client via TCP:

    sh wrpc-wasmtime tcp run --import [::1]:7762 ./target/wasm32-wasip2/release/hello-component-client.wasm

Using NATS.io transport

We will use the following two Rust wRPC applications using NATS.io transport: - examples/rust/hello-nats-client - examples/rust/hello-nats-server

  1. Run NATS.io (more thorough documentation available here):

    • using standalone binary: sh nats-server

    • using Docker: sh docker run --rm -it --name nats-server -p 4222:4222 nats:2.10.20-alpine3.20

  2. Serve Wasm hello server via NATS.io

    sh wrpc-wasmtime nats serve --export rust ./target/wasm32-wasip2/release/hello_component_server.wasm

    • Sample output:

      INFO async_nats: event: connected

      INFO wrpc_wasmtime_cli: serving instance function name="hello"

  3. Call Wasm hello server using a Wasm hello client via NATS.io:

    sh wrpc-wasmtime nats run --import rust ./target/wasm32-wasip2/release/hello-component-client.wasm

    • Sample output in the client:

      INFO async_nats: event: connected

      hello from Rust

    • Sample output in the server:

      INFO wrpc_wasmtime_cli: serving instance function invocation

      INFO wrpc_wasmtime_cli: successfully served instance function invocation

  4. Call the Wasm hello server using a native wRPC hello client via NATS.io:

    sh cargo run -p hello-nats-client rust

  5. Serve native wRPC hello server via NATS.io:

    sh cargo run -p hello-nats-server native

  6. Call both the native wRPC hello server and Wasm hello server using native wRPC hello client via NATS.io:

    sh cargo run -p hello-nats-client rust native

  7. Call native wRPC hello server using Wasm hello client via NATS.io:

    sh wrpc-wasmtime nats run --import native ./target/wasm32-wasip2/release/hello-component-client.wasm

Repository structure

This repository contains (for all supported languages): - core libraries and abstractions - binding generators - WebAssembly runtime integrations - wRPC transport implementations

wit-bindgen-wrpc aims to closely match UX of [wit-bindgen] and therefore includes a subtree merge of the project, which is occasionally merged into this tree. - wRPC binding generators among other tests, are tested using the [wit-bindgen] test suite - [wit-bindgen] documentation is reused where applicable

Contributing

👋 Welcome, new contributors!

Whether you're a seasoned developer or just getting started, your contributions are valuable to us. Don't hesitate to jump in, explore the project, and make an impact. To start contributing, please check out our Contribution Guidelines.

Extension points exported contracts — how you extend this code

Index (Interface)
Index represents entities, which can be indexed by concrete `uint32` paths, for example transport streams. [6 implementers]
go/wrpc.go
Deferred (Interface)
Handles async processing state for codecs [20 implementers]
crates/transport/src/value.rs
ClientOpt (FuncType)
ClientOpt is option client configuration option passed to NewClient
go/nats/client.go
Bucket (Interface)
A bucket is a collection of key-value pairs. Each key-value pair is stored as a entry in the bucket, and the bucket itse
examples/go/wasi-keyvalue-client/bindings/wasi/keyvalue/store/bindings.wrpc.go
WrpcView (Interface)
(no doc) [2 implementers]
crates/runtime-wasmtime/src/lib.rs
Server (Interface)
Server is the server-side transport handle [3 implementers]
go/wrpc.go
Encode (Interface)
Defines value encoding [33 implementers]
crates/transport/src/value.rs
Bucket (Interface)
A bucket is a collection of key-value pairs. Each key-value pair is stored as a entry in the bucket, and the bucket itse
examples/go/wasi-keyvalue-server/bindings/exports/wasi/keyvalue/store/bindings.wrpc.go

Core symbols most depended-on inside this repo

Ok
called by 514
go/result.go
context
called by 423
crates/wasmtime-cli/src/lib.rs
push_str
called by 338
crates/wit-bindgen-go/src/interface.rs
push_str
called by 277
crates/wit-bindgen-rust/src/interface.rs
Err
called by 139
go/result.go
clone
called by 120
crates/transport/src/value.rs
iter
called by 116
crates/wit-bindgen-rust/src/lib.rs
Ok
called by 96
examples/go/wasi-keyvalue-server/app.go

Shape

Method 608
Function 452
Class 151
Struct 58
Interface 37
Enum 26
TypeAlias 5
FuncType 2

Languages

Rust73%
Go27%

Modules by API surface

crates/wit-bindgen-go/src/interface.rs95 symbols
crates/transport/src/value.rs55 symbols
crates/wit-bindgen-go/src/lib.rs48 symbols
crates/wit-bindgen-rust/src/lib.rs45 symbols
crates/wit-bindgen-rust/src/interface.rs42 symbols
crates/transport-nats/src/lib.rs42 symbols
crates/wave/src/core/encode.rs40 symbols
go/wrpc.go38 symbols
crates/wave/src/core/decode.rs37 symbols
go/nats/client.go35 symbols
crates/runtime-wasmtime/src/lib.rs30 symbols
crates/wave/src/pack.rs28 symbols

For agents

$ claude mcp add wrpc \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact