You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[<imgalt="Hello World MCP Server"src="https://img.shields.io/badge/Example-Hello%20World%20MCP-0286ba?style=for-the-badge&logo=rust"height="22">
12
12
](examples/hello-world-mcp-server)
13
13
14
-
A high-performance, asynchronous toolkit for building MCP servers and clients.
14
+
A high-performance, asynchronous toolkit for building MCP servers and clients.
15
15
Focus on your app's logic while **rust-mcp-sdk** takes care of the rest!
16
16
17
-
**rust-mcp-sdk** provides the necessary components for developing both servers and clients in the MCP ecosystem.
17
+
**rust-mcp-sdk** provides the necessary components for developing both servers and clients in the MCP ecosystem.
18
18
Leveraging the [rust-mcp-schema](https://github.com/rust-mcp-stack/rust-mcp-schema) crate simplifies the process of building robust and reliable MCP servers and clients, ensuring consistency and minimizing errors in data handling and message processing.
19
19
20
-
**⚠️WARNING**: This project only supports Standard Input/Output (stdio) transport at this time, with support for SSE (Server-Sent Events) transport still in progress and not yet available. Project is currently under development and should be used at your own risk.
20
+
This project currently supports **stdio** (Standard Input/Output) and **sse**(Server-Sent Events) transports.
21
21
22
-
## Projects using `rust-mcp-sdk`
23
22
24
-
Below is a list of projects that utilize the `rust-mcp-sdk`, showcasing their name, description, and links to their repositories or project pages.
23
+
🚀 SSE transport works over HTTP/HTTPS. The `rust-mcp-sdk` includes a lightweight Axum-based server that handles all core functionality seamlessly. Switching between `stdio`and `sse` is straightforward, requiring minimal code changes. The server is designed to efficiently handle multiple concurrent client connections and offers built-in support for SSL and custom middleware.
25
24
26
-
| Icon | Name | Description | Link |
27
-
|------|------|-------------|------|
28
-
| <ahref="https://rust-mcp-stack.github.io/rust-mcp-filesystem"><imgsrc="https://raw.githubusercontent.com/rust-mcp-stack/rust-mcp-filesystem/refs/heads/main/docs/_media/rust-mcp-filesystem.png"width="64"/></a> |[Rust MCP Filesystem](https://rust-mcp-stack.github.io/rust-mcp-filesystem)| Fast, asynchronous MCP server for seamless filesystem operations offering enhanced capabilities, improved performance, and a robust feature set tailored for modern filesystem interactions. |[GitHub](https://github.com/rust-mcp-stack/rust-mcp-filesystem)|
29
-
| <ahref="https://rust-mcp-stack.github.io/mcp-discovery"><imgsrc="https://raw.githubusercontent.com/rust-mcp-stack/mcp-discovery/refs/heads/main/docs/_media/mcp-discovery-logo.png"width="64"/></a> |[MCP Discovery](https://rust-mcp-stack.github.io/mcp-discovery)| A lightweight command-line tool for discovering and documenting MCP Server capabilities. |[GitHub](https://github.com/rust-mcp-stack/mcp-discovery)|
25
+
**⚠️****Streamable HTTP** transport and authentication still in progress and not yet available. Project is currently under development and should be used at your own risk.
26
+
27
+
## Table of Contents
28
+
-[Usage Examples](#usage-examples)
29
+
-[MCP Server (stdio)](#mcp-server-stdio)
30
+
-[MCP Server (sse)](#mcp-server-sse)
31
+
-[MCP Client (stdio)](#mcp-client-stdio)
32
+
-[MCP Client (sse)](#mcp-client-sse)
33
+
-[Cargo features](#cargo-features)
34
+
-[Available Features](#available-features)
35
+
-[Default Features](#default-features)
36
+
-[Using Only the server Features](#using-only-the-server-features)
37
+
-[Using Only the client Features](#using-only-the-client-features)
38
+
-[Choosing Between Standard and Core Handlers traits](#choosing-between-standard-and-core-handlers-traits)
39
+
-[Choosing Between **ServerHandler** and **ServerHandlerCore**](#choosing-between-serverhandler-and-serverhandlercore)
40
+
-[Choosing Between **ClientHandler** and **ClientHandlerCore**](#choosing-between-clienthandler-and-clienthandlercore)
41
+
-[Projects using Rust MCP SDK](#projects-using-rust-mcp-sdk)
42
+
-[Contributing](#contributing)
43
+
-[Development](#development)
44
+
-[License](#license)
30
45
31
46
## Usage Examples
32
47
33
-
### MCP Server
48
+
### MCP Server (stdio)
34
49
35
50
Create a MCP server with a `tool` that will print a `Hello World!` message:
The implementation of `MyServerHandler` is the same regardless of the transport used and could be as simple as the following:
74
133
75
134
```rust
76
135
@@ -122,7 +181,7 @@ See hello-world-mcp-server example running in [MCP Inspector](https://modelconte
122
181
123
182
---
124
183
125
-
### MCP Client
184
+
### MCP Client (stdio)
126
185
127
186
Create an MCP client that starts the [@modelcontextprotocol/server-everything](https://www.npmjs.com/package/@modelcontextprotocol/server-everything) server, displays the server's name, version, and list of tools, then uses the add tool provided by the server to sum 120 and 28, printing the result.
128
187
@@ -203,23 +262,38 @@ Here is the output :
203
262
204
263
> your results may vary slightly depending on the version of the MCP Server in use when you run it.
205
264
265
+
### MCP Client (sse)
266
+
Creating an MCP client using the `rust-mcp-sdk` with the SSE transport is almost identical, with one exception at `step 3`. Instead of creating a `StdioTransport`, you simply create a `ClientSseTransport`. The rest of the code remains the same:
267
+
268
+
```diff
269
+
- let transport = StdioTransport::create_with_server_launch(
+ let transport = ClientSseTransport::new(MCP_SERVER_URL, ClientSseTransportOptions::default())?;
275
+
```
276
+
277
+
206
278
## Getting Started
207
279
208
280
If you are looking for a step-by-step tutorial on how to get started with `rust-mcp-sdk` , please see : [Getting Started MCP Server](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/doc/getting-started-mcp-server.md)
209
281
210
-
## Features
282
+
## Cargo Features
211
283
212
-
The `rust-mcp-sdk` crate provides three optional features: `server` , `client` and `macros`. By default, all features are enabled for maximum functionality. You can customize which features to include based on your project's needs.
284
+
The `rust-mcp-sdk` crate provides several features that can be enabled or disabled. By default, all features are enabled to ensure maximum functionality, but you can customize which ones to include based on your project's requirements.
213
285
214
286
### Available Features
215
287
216
-
-`server`: Activates MCP server capabilities in `rust-mcp-sdk`, providing modules and APIs for building and managing MCP services.
288
+
-`server`: Activates MCP server capabilities in `rust-mcp-sdk`, providing modules and APIs for building and managing MCP servers.
217
289
-`client`: Activates MCP client capabilities, offering modules and APIs for client development and communicating with MCP servers.
290
+
-`hyper-server`: This feature enables the **sse** transport for MCP servers, supporting multiple simultaneous client connections out of the box.
291
+
-`ssl`: This feature enables TLS/SSL support for the **sse** transport when used with the `hyper-server`.
218
292
-`macros`: Provides procedural macros for simplifying the creation and manipulation of MCP Tool structures.
219
293
220
-
### Default Behavior
294
+
### Default Features
221
295
222
-
All features (server, client, and macros) are enabled by default. When you include rust-mcp-sdk as a dependency without specifying features, all will be included:
296
+
All features are enabled by default. When you include rust-mcp-sdk as a dependency without specifying features, all will be included:
223
297
224
298
<!-- x-release-please-start-version -->
225
299
@@ -230,7 +304,7 @@ rust-mcp-sdk = "0.2.0"
230
304
231
305
<!-- x-release-please-end -->
232
306
233
-
### Using Only the server Feature
307
+
### Using Only the server Features
234
308
235
309
If you only need the MCP Server functionality, you can disable the default features and explicitly enable the server feature. Add the following to your Cargo.toml:
236
310
@@ -240,10 +314,11 @@ If you only need the MCP Server functionality, you can disable the default featu
240
314
[dependencies]
241
315
rust-mcp-sdk = { version = "0.2.0", default-features = false, features = ["server","macros"] }
242
316
```
317
+
Optionally add `hyper-server` for **sse** transport, and `ssl` feature for tls/ssl support of the `hyper-server`
243
318
244
319
<!-- x-release-please-end -->
245
320
246
-
### Using Only the client Feature
321
+
### Using Only the client Features
247
322
248
323
If you only need the MCP Client functionality, you can disable the default features and explicitly enable the client feature. Add the following to your Cargo.toml:
249
324
@@ -256,28 +331,59 @@ rust-mcp-sdk = { version = "0.2.0", default-features = false, features = ["clien
256
331
257
332
<!-- x-release-please-end -->
258
333
259
-
### Choosing Between `mcp_server_handler` and `mcp_server_handler_core`
334
+
## Choosing Between Standard and Core Handlers traits
335
+
Learn when to use the `mcp_*_handler` traits versus the lower-level `mcp_*_handler_core` traits for both server and client implementations. This section helps you decide based on your project's need for simplicity versus fine-grained control.
336
+
337
+
### Choosing Between `ServerHandler` and `ServerHandlerCore`
260
338
261
339
[rust-mcp-sdk](https://github.com/rust-mcp-stack/rust-mcp-sdk) provides two type of handler traits that you can chose from:
262
340
263
-
-**mcp_server_handler**: This is the recommended trait for your MCP project, offering a default implementation for all types of MCP messages. It includes predefined implementations within the trait, such as handling initialization or responding to ping requests, so you only need to override and customize the handler functions relevant to your specific needs.
341
+
-**ServerHandler**: This is the recommended trait for your MCP project, offering a default implementation for all types of MCP messages. It includes predefined implementations within the trait, such as handling initialization or responding to ping requests, so you only need to override and customize the handler functions relevant to your specific needs.
264
342
Refer to [examples/hello-world-mcp-server/src/handler.rs](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/examples/hello-world-mcp-server/src/handler.rs) for an example.
265
343
266
-
-**mcp_server_handler_core**: If you need more control over MCP messages, consider using `mcp_server_handler_core`. It offers three primary methods to manage the three MCP message types: `request`, `notification`, and `error`. While still providing type-safe objects in these methods, it allows you to determine how to handle each message based on its type and parameters.
344
+
-**ServerHandlerCore**: If you need more control over MCP messages, consider using `ServerHandlerCore`. It offers three primary methods to manage the three MCP message types: `request`, `notification`, and `error`. While still providing type-safe objects in these methods, it allows you to determine how to handle each message based on its type and parameters.
267
345
Refer to [examples/hello-world-mcp-server-core/src/handler.rs](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/examples/hello-world-mcp-server-core/src/handler.rs) for an example.
268
346
269
347
---
270
348
271
-
**👉 Note:** Depending on your choice between `mcp_server_handler` and `mcp_server_handler_core`, you must use either `server_runtime::create_server()` or `server_runtime_core::create_server()` , respectively.
349
+
**👉 Note:** Depending on whether you choose `ServerHandler` or `ServerHandlerCore`, you must use the `create_server()` function from the appropriate module:
350
+
351
+
- For `ServerHandler`:
352
+
- Use `server_runtime::create_server()` for servers with stdio transport
353
+
- Use `hyper_server::create_server()` for servers with sse transport
354
+
355
+
- For `ServerHandlerCore`:
356
+
- Use `server_runtime_core::create_server()` for servers with stdio transport
357
+
- Use `hyper_server_core::create_server()` for servers with sse transport
272
358
273
359
---
274
360
275
-
### Choosing Between `mcp_client_handler` and `mcp_client_handler_core`
276
361
277
-
The same principles outlined above apply to the client-side handlers, `mcp_client_handler` and `mcp_client_handler_core`.
278
-
Use `client_runtime::create_client()` or `client_runtime_core::create_client()` , respectively.
362
+
### Choosing Between `ClientHandler` and `ClientHandlerCore`
363
+
364
+
The same principles outlined above apply to the client-side handlers, `ClientHandler` and `ClientHandlerCore`.
365
+
366
+
- Use `client_runtime::create_client()` when working with `ClientHandler`
367
+
368
+
- Use `client_runtime_core::create_client()` when working with `ClientHandlerCore`
369
+
370
+
Both functions create an MCP client instance.
371
+
372
+
373
+
279
374
Check out the corresponding examples at: [examples/simple-mcp-client](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/examples/simple-mcp-client) and [examples/simple-mcp-client-core](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/examples/simple-mcp-client-core).
280
375
376
+
377
+
## Projects using Rust MCP SDK
378
+
379
+
Below is a list of projects that utilize the `rust-mcp-sdk`, showcasing their name, description, and links to their repositories or project pages.
380
+
381
+
| Icon | Name | Description | Link |
382
+
|------|------|-------------|------|
383
+
| <ahref="https://rust-mcp-stack.github.io/rust-mcp-filesystem"><imgsrc="https://raw.githubusercontent.com/rust-mcp-stack/rust-mcp-filesystem/refs/heads/main/docs/_media/rust-mcp-filesystem.png"width="64"/></a> |[Rust MCP Filesystem](https://rust-mcp-stack.github.io/rust-mcp-filesystem)| Fast, asynchronous MCP server for seamless filesystem operations offering enhanced capabilities, improved performance, and a robust feature set tailored for modern filesystem interactions. |[GitHub](https://github.com/rust-mcp-stack/rust-mcp-filesystem)|
384
+
| <ahref="https://rust-mcp-stack.github.io/mcp-discovery"><imgsrc="https://raw.githubusercontent.com/rust-mcp-stack/mcp-discovery/refs/heads/main/docs/_media/mcp-discovery-logo.png"width="64"/></a> |[MCP Discovery](https://rust-mcp-stack.github.io/mcp-discovery)| A lightweight command-line tool for discovering and documenting MCP Server capabilities. |[GitHub](https://github.com/rust-mcp-stack/mcp-discovery)|
385
+
386
+
281
387
## Contributing
282
388
283
389
We welcome everyone who wishes to contribute! Please refer to the [contributing](CONTRIBUTING.md) guidelines for more details.
0 commit comments