Skip to content

Add Typescript bindings crate, FFI, workflow, and examples for RMCP Rust SDK #183

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


[workspace]
members = ["crates/rmcp", "crates/rmcp-macros", "examples/*"]
members = [ "bindings/python", "bindings/typescript", "crates/rmcp", "crates/rmcp-macros", "examples/*"]
resolver = "2"

[workspace.dependencies]
Expand Down
29 changes: 29 additions & 0 deletions bindings/typescript/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# TypeScript/Node ignores
node_modules/
dist/
build/
*.tsbuildinfo
.env
.env.*
coverage/

# napi-rs ignores
*.node
index.node
*.d.ts
artifacts/
.napi/

# Rust ignores
target/
Cargo.lock

# IDE ignores
.vscode/
.idea/
*.swp
*.swo

# OS ignores
.DS_Store
Thumbs.db
1 change: 1 addition & 0 deletions bindings/typescript/.placeholder
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

29 changes: 29 additions & 0 deletions bindings/typescript/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "rmcp_typescript"
edition.workspace = true
version.workspace = true
authors.workspace = true
license.workspace = true
repository.workspace = true
description.workspace = true
keywords.workspace = true
homepage.workspace = true
categories.workspace = true
readme.workspace = true

[dependencies]
rmcp = { path = "../../crates/rmcp", features = ["transport-sse", "client"] }
napi = { version = "2", features = ["serde-json", "tokio_rt"] }
napi-derive = "2"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
reqwest = { version = "0.12", features = ["json"] }
sse-stream = "0.1.3"
url = "2.4"
tokio = { version = "1.0", features = ["full"] }
tokio-util = { version = "0.7", features = ["full"] }
[lib]
crate-type = ["cdylib"]

[build-dependencies]
napi-build = "2"
52 changes: 52 additions & 0 deletions bindings/typescript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# TypeScript Bindings Setup & Example Usage

## Prerequisites
- Rust (latest stable, with cargo)
- Node.js (latest LTS, with npm)
- TypeScript (install via `npm install -g typescript`)

## Build the TypeScript Bindings
1. Navigate to the TypeScript bindings directory:
```bash
cd bindings/typescript
```
2. Install dependencies and build the project:
```bash
npm install
npm run build
```
## Note on Cargo.toml
If you encounter an error indicating that the `Cargo.toml` of `bindings/python` is not present in the root `Cargo.toml`, and you don't want to build Python and TypeScript together, you can edit the root `Cargo.toml` to remove the Python bindings (bindings/python) entry.

## Run the Rust Server
In a separate terminal, start the Rust SDK server (example using the rmcp crate):
```bash
cd examples/servers
cargo run --example servers_axum
```

## Link the Module Locally
If the `rmcp-typescript` module is not published to npm, you can link it locally:
1. Navigate to the TypeScript bindings directory:
```bash
cd bindings/typescript
```
2. Link the module:
```bash
npm link
```
3. Navigate to the examples/clients directory and link the module:
```bash
cd examples/clients
npm link rmcp-typescript
```

## Run the TypeScript SSE Client Example
With the server running, in another terminal:
```bash
cd bindings/typescript/examples/clients/src
npx tsx sse.ts
```

This will connect to the running Rust server and demonstrate the SSE client functionality.

3 changes: 3 additions & 0 deletions bindings/typescript/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
napi_build::setup();
}
Loading