Skip to content

cmd-ipc

A polyglot IPC library for running typed Commands across processes and services. Same protocol in TypeScript and Rust.

Building applications that span multiple processes, workers, or services often means dealing with complex message passing, type mismatches, and boilerplate code. cmd-ipc solves this by providing a unified, type-safe command system that works across any boundary — in TypeScript, Rust, or both at once over the same wire protocol.

Type-Safe Commands

Full TypeScript inference via Valibot, or compile-time-checked Rust types via schemars. Same guarantees across process boundaries.

Polyglot

TypeScript and Rust implementations share a byte-identical wire protocol. Call a Rust command from Node.js or vice versa.

Universal Channels

MessagePort, HTTP, MCP, in-memory — same API regardless of transport. Plug in custom channels for anything else.

Event Broadcasting

Fire-and-forget events propagate across all connected processes with automatic deduplication.

import { CommandRegistry, Command, registerCommands } from '@coralstack/cmd-ipc'
import * as v from 'valibot'
const CommandSchema = {
'math.add': {
request: v.object({ a: v.number(), b: v.number() }),
response: v.number(),
},
} as const
class MathService {
@Command('math.add')
add({ a, b }: { a: number; b: number }): number {
return a + b
}
}
const registry = new CommandRegistry({
id: 'main',
schemas: { commands: CommandSchema },
})
registerCommands([new MathService()], registry)
const result = await registry.executeCommand('math.add', { a: 5, b: 3 })
// result is typed as number = 8

Electron Apps

Communicate between main and renderer processes with type safety. No more IPC message mismatches.

Web Workers

Offload heavy computation to workers while maintaining a clean, typed API.

Microservices

Build type-safe HTTP APIs with automatic schema validation via HTTPChannel.

AI Agents

Expose commands as MCP tools for AI agents with automatic schema generation.

  • Hybrid Tree-Mesh Architecture - Commands route intelligently across connected registries
  • Schema Validation - Runtime validation with Valibot, compile-time types with TypeScript
  • CLI Tools - Generate schemas from remote services, validate configurations
  • Event System - Broadcast events with automatic deduplication
  • Private Commands - Keep internal commands hidden from other processes
  • Flexible Channels - MessagePort, HTTP, WebSocket, or build your own

Ready to get started? Check out the installation guide or explore the examples. For the Rust crate, see the Rust API.