MCPcopy Index your code
hub / github.com/chatmail/yerpc

github.com/chatmail/yerpc @v0.6.4

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.6.4 ↗ · + Follow
203 symbols 341 edges 39 files 18 documented · 9%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

yerpc

docs.rs Crates.io

A JSON-RPC 2.0 server handler for Rust, with automatic generation of a TypeScript client.

yerpc includes (optional) integration with axum and tokio-tungstenite for easy setup and usage. Enable the support-axum and support-tungstenite feature flags for these integrations.

Example

use axum::{
    extract::ws::WebSocketUpgrade, http::StatusCode, response::Response, routing::get, Router,
};
use std::net::SocketAddr;
use yerpc::{rpc, RpcClient, RpcSession};
use yerpc::axum::handle_ws_rpc;

struct Api;

#[rpc(all_positional, ts_outdir = "typescript/generated", openrpc_outdir = "./")]
impl Api {
    async fn shout(&self, msg: String) -> String {
        msg.to_uppercase()
    }
    async fn add(&self, a: f32, b: f32) -> f32 {
        a + b
    }
}

#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
    let api = Api {}
    let app = Router::new()
        .route("/rpc", get(handler))
        .layer(Extension(api));
    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
    eprintln!("listening on {}", addr);
    axum::Server::bind(&addr)
        .serve(app.into_make_service())
        .await
        .unwrap();

    Ok(())
}

async fn handler(
    ws: WebSocketUpgrade,
    Extension(api): Extension<Api>,
) -> Response {
    let (client, out_channel) = RpcClient::new();
    let session = RpcSession::new(client, api);
    handle_ws_rpc(ws, out_channel, session).await
}

Now you can connect any JSON-RPC client to ws://localhost:3000/rpc and call the shout and add methods.

After running cargo test you will find an autogenerated TypeScript client in the typescript/generated folder and an openrpc.json file in the root fo your project. See examples/axum for a full usage example with Rust server and TypeScript client for a chat server.

Extension points exported contracts — how you extend this code

RpcServer (Interface)
(no doc) [1 implementers]
yerpc/src/lib.rs
Transport (Interface)
(no doc)
yerpc-derive/src/client.ts
Transport (Interface)
(no doc)
typescript/client.ts
WebsocketEvents (Interface)
(no doc)
typescript/websocket.ts

Core symbols most depended-on inside this repo

to_string
called by 21
yerpc/src/typescript.rs
clone
called by 19
yerpc/src/requests.rs
on
called by 11
typescript/util/emitter.ts
handle_incoming
called by 8
yerpc/src/requests.rs
emit
called by 7
typescript/util/emitter.ts
send
called by 6
examples/tide/src/webserver.rs
tx
called by 4
yerpc/src/requests.rs
send_request
called by 3
yerpc/src/requests.rs

Shape

Method 100
Class 45
Function 41
Enum 10
Interface 7

Languages

Rust69%
TypeScript31%

Modules by API surface

yerpc/src/lib.rs26 symbols
yerpc/src/requests.rs24 symbols
typescript/websocket.ts17 symbols
examples/axum/src/webserver.rs14 symbols
examples/tide/src/webserver.rs12 symbols
yerpc-derive/src/parse.rs10 symbols
typescript/util/emitter.ts9 symbols
yerpc/src/openrpc.rs8 symbols
typescript/client.ts7 symbols
yerpc/typescript/generated/client.ts6 symbols
yerpc/tests/axum.rs6 symbols
yerpc/src/version.rs6 symbols

For agents

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

⬇ download graph artifact