docs: format and fix typo (#72)

This commit is contained in:
Todsaporn Banjerdkit 2025-03-31 15:13:17 +07:00 • committed by GitHub
commit 59c975887e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 29 additions and 11 deletions

View file

@ -3,6 +3,7 @@
</div> </div>
# RMCP # RMCP
[![Crates.io Version](https://img.shields.io/crates/v/rmcp)](https://crates.io/crates/rmcp) [![Crates.io Version](https://img.shields.io/crates/v/rmcp)](https://crates.io/crates/rmcp)
![Release status](https://github.com/modelcontextprotocol/rust-sdk/actions/workflows/release.yml/badge.svg) ![Release status](https://github.com/modelcontextprotocol/rust-sdk/actions/workflows/release.yml/badge.svg)
[![docs.rs](https://img.shields.io/docsrs/rmcp)](https://docs.rs/rmcp/latest/rmcp) [![docs.rs](https://img.shields.io/docsrs/rmcp)](https://docs.rs/rmcp/latest/rmcp)
@ -12,6 +13,7 @@ An official rust Model Context Protocol SDK implementation with tokio async runt
## Usage ## Usage
### Import ### Import
```toml ```toml
rmcp = { version = "0.1", features = ["server"] } rmcp = { version = "0.1", features = ["server"] }
## or dev channel ## or dev channel
@ -19,7 +21,9 @@ rmcp = { git = "https://github.com/modelcontextprotocol/rust-sdk", branch = "mai
``` ```
### Quick start ### Quick start
Start a client in one line: Start a client in one line:
```rust ```rust
use rmcp::{ServiceExt, transport::TokioChildProcess}; use rmcp::{ServiceExt, transport::TokioChildProcess};
use tokio::process::Command; use tokio::process::Command;
@ -47,14 +51,16 @@ For client, the sink item is [`ClientJsonRpcMessage`](crate::model::ClientJsonRp
For server, the sink item is [`ServerJsonRpcMessage`](crate::model::ServerJsonRpcMessage) and stream item is [`ClientJsonRpcMessage`](crate::model::ClientJsonRpcMessage) For server, the sink item is [`ServerJsonRpcMessage`](crate::model::ServerJsonRpcMessage) and stream item is [`ClientJsonRpcMessage`](crate::model::ClientJsonRpcMessage)
##### These types is automatically implemented [`IntoTransport`](crate::transport::IntoTransport) trait ##### These types is automatically implemented [`IntoTransport`](crate::transport::IntoTransport) trait
1. The types that already implement both [`Sink`](futures::Sink) and [`Stream`](futures::Stream) trait. 1. The types that already implement both [`Sink`](futures::Sink) and [`Stream`](futures::Stream) trait.
2. A tuple of sink `Tx` and stream `Rx`: `(Tx, Rx)`. 2. A tuple of sink `Tx` and stream `Rx`: `(Tx, Rx)`.
3. The type that implement both [`tokio::io::AsyncRead`] and [`tokio::io::AsyncWrite`] trait. 3. The type that implement both [`tokio::io::AsyncRead`] and [`tokio::io::AsyncWrite`] trait.
4. A tuple of [`tokio::io::AsyncRead`] `R `and [`tokio::io::AsyncWrite`] `W`: `(R, W)`. 4. A tuple of [`tokio::io::AsyncRead`] `R `and [`tokio::io::AsyncWrite`] `W`: `(R, W)`.
For example, you can see how we build a transport through TCP stream or http upgrade so easily. [examples](examples/README.md) For example, you can see how we build a transport through TCP stream or http upgrade so easily. [examples](examples/README.md)
#### 2. Build a service #### 2. Build a service
You can easily build a service by using [`ServerHandler`](crates/rmcp/src/handler/server.rs) or [`ClientHandler`](crates/rmcp/src/handler/client.rs). You can easily build a service by using [`ServerHandler`](crates/rmcp/src/handler/server.rs) or [`ClientHandler`](crates/rmcp/src/handler/client.rs).
```rust, ignore ```rust, ignore
@ -62,12 +68,14 @@ let service = common::counter::Counter::new();
``` ```
#### 3. Serve them together #### 3. Serve them together
```rust, ignore ```rust, ignore
// this call will finish the initialization process // this call will finish the initialization process
let server = service.serve(transport).await?; let server = service.serve(transport).await?;
``` ```
#### 4. Interact with the server #### 4. Interact with the server
Once the server is initialized, you can send requests or notifications: Once the server is initialized, you can send requests or notifications:
```rust, ignore ```rust, ignore
@ -79,6 +87,7 @@ server.notify_cancelled(...).await?;
``` ```
#### 5. Waiting for service shutdown #### 5. Waiting for service shutdown
```rust, ignore ```rust, ignore
let quit_reason = server.waiting().await?; let quit_reason = server.waiting().await?;
// or cancel it // or cancel it
@ -86,9 +95,11 @@ let quit_reason = server.cancel().await?;
``` ```
### Use marcos to declaring tool ### Use marcos to declaring tool
Use `toolbox` and `tool` macros to create tool quickly. Use `toolbox` and `tool` macros to create tool quickly.
Check this [file](examples/servers/src/common/calculator.rs). Check this [file](examples/servers/src/common/calculator.rs).
```rust, ignore ```rust, ignore
use rmcp::{ServerHandler, model::ServerInfo, schemars, tool}; use rmcp::{ServerHandler, model::ServerInfo, schemars, tool};
@ -141,6 +152,7 @@ impl ServerHandler for Calculator {
} }
``` ```
The only thing you should do is to make the function's return type implement `IntoCallToolResult`. The only thing you should do is to make the function's return type implement `IntoCallToolResult`.
And you can just implement `IntoContents`, and the return value will be marked as success automatically. And you can just implement `IntoContents`, and the return value will be marked as success automatically.
@ -148,26 +160,31 @@ And you can just implement `IntoContents`, and the return value will be marked a
If you return a type of `Result<T, E>` where `T` and `E` both implemented `IntoContents`, it's also OK. If you return a type of `Result<T, E>` where `T` and `E` both implemented `IntoContents`, it's also OK.
### Manage Multi Services ### Manage Multi Services
For many cases you need to manage several service in a collection, you can call `into_dyn` to convert services into the same type. For many cases you need to manage several service in a collection, you can call `into_dyn` to convert services into the same type.
```rust, ignore ```rust, ignore
let service = service.into_dyn(); let service = service.into_dyn();
``` ```
### Examples ### Examples
See [examples](examples/README.md) See [examples](examples/README.md)
### Features ### Features
- `client`: use client side sdk - `client`: use client side sdk
- `server`: use server side sdk - `server`: use server side sdk
- `macros`: macros default - `macros`: macros default
#### Transports #### Transports
- `transport-io`: Server stdio transport - `transport-io`: Server stdio transport
- `transport-sse-server`: Server SSE transport - `transport-sse-server`: Server SSE transport
- `transport-child-process`: Client stdio transport - `transport-child-process`: Client stdio transport
- `transport-sse`: Client sse transport - `transport-sse`: Client sse transport
## Related Resources ## Related Resources
- [MCP Specification](https://spec.modelcontextprotocol.io/specification/2024-11-05/)
- [MCP Specification](https://spec.modelcontextprotocol.io/specification/2024-11-05/)
- [Schema](https://github.com/modelcontextprotocol/specification/blob/main/schema/2024-11-05/schema.ts) - [Schema](https://github.com/modelcontextprotocol/specification/blob/main/schema/2024-11-05/schema.ts)

View file

@ -10,7 +10,6 @@
- [Server SSE](servers/src/axum.rs), using axum as web server. - [Server SSE](servers/src/axum.rs), using axum as web server.
- [Server stdio](servers/src/std_io.rs), using tokio async io. - [Server stdio](servers/src/std_io.rs), using tokio async io.
# Transport Examples # Transport Examples
- [Tcp](transport/src/tcp.rs) - [Tcp](transport/src/tcp.rs)
@ -18,14 +17,16 @@
- [Unix Socket](transport/src/unix_socket.rs) - [Unix Socket](transport/src/unix_socket.rs)
- [Websocket](transport/src/websocket.rs) - [Websocket](transport/src/websocket.rs)
# Integration
# Intergration
- [Rig](examples/rig-integration) A stream chatbot with rig - [Rig](examples/rig-integration) A stream chatbot with rig
# WASI # WASI
- [WASI-P2 runtime](examples/wasi) How it works with wasip2 - [WASI-P2 runtime](examples/wasi) How it works with wasip2
## Use Mcp Inspector ## Use Mcp Inspector
```sh ```sh
npx @modelcontextprotocol/inspector npx @modelcontextprotocol/inspector
``` ```

View file

@ -1,4 +1,4 @@
```sh ```sh
cargo build -p wasi --target wasm32-wasip2 cargo build -p wasi --target wasm32-wasip2
npx @modelcontextprotocol/inspector wasmtime target/wasm32-wasip2/debug/wasi.wasm npx @modelcontextprotocol/inspector wasmtime target/wasm32-wasip2/debug/wasi.wasm
``` ```