Skip to content

Commit 001bd31

Browse files
authored
fix: refactor examples and update documentation (#122)
* chore: move stdio server example projects into examples folder under rust-mcp_sdk crate * chore: move all examples * chore: update documents * chore: tool icons * chore: update examples and screen recordings * chore: fix ci cache issue * chore: use bash on windows * chore: fix typo
1 parent 93e349f commit 001bd31

85 files changed

Lines changed: 535 additions & 2834 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,18 @@ jobs:
2828
uses: actions/cache@v4
2929
with:
3030
path: |
31-
~/.rustup/toolchains
3231
~/.cargo/registry
3332
~/.cargo/git
3433
target
3534
key: ${{ matrix.os }}-rust-${{ hashFiles('Cargo.lock') }}
3635
restore-keys: ${{ matrix.os }}-rust-
3736

37+
- name: Clear rustup cache (avoid conflict errors)
38+
shell: bash
39+
run: |
40+
rm -rf ~/.rustup/toolchains
41+
rm -rf ~/.rustup/downloads
42+
3843
- name: Install Rust Toolchain
3944
uses: dtolnay/rust-toolchain@master
4045
with:

Cargo.lock

Lines changed: 2 additions & 163 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,6 @@ members = [
55
"crates/rust-mcp-sdk",
66
"crates/rust-mcp-transport",
77
"crates/rust-mcp-extra",
8-
"examples/simple-mcp-client-stdio",
9-
"examples/simple-mcp-client-stdio-core",
10-
"examples/hello-world-mcp-server-stdio",
11-
"examples/hello-world-mcp-server-stdio-core",
12-
"examples/hello-world-server-streamable-http",
13-
"examples/hello-world-server-streamable-http-core",
14-
"examples/simple-mcp-client-sse",
15-
"examples/simple-mcp-client-sse-core",
16-
"examples/simple-mcp-client-streamable-http",
17-
"examples/simple-mcp-client-streamable-http-core",
18-
"examples/auth/server-oauth-remote"
19-
208
]
219

2210
[workspace.package]

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,14 @@ async fn main() -> SdkResult<()> {
303303

304304
## Usage Examples
305305

306-
👉 For full examples (stdio, Streamable HTTP, clients, auth, etc.), see the [examples/](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/examples) directory.
306+
👉 For more examples (stdio, Streamable HTTP, clients, auth, etc.), see the [examples/](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/crates/rust-mcp-sdk/examples) directory.
307307

308308
👉 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)
309309

310-
See [hello-world-mcp-server-stdio](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/examples/hello-world-mcp-server-stdio) example running in [MCP Inspector](https://modelcontextprotocol.io/docs/tools/inspector) :
310+
See [hello-world-mcp-server-stdio](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/crates/rust-mcp-sdk/examples/hello-world-mcp-server-stdio.rs) example running in [MCP Inspector](https://modelcontextprotocol.io/docs/tools/inspector) :
311+
312+
<img src="assets/examples/hello-world-mcp-server.gif" alt="hello world mcp server in rust" width="800" />
311313

312-
![mcp-server in rust](assets/examples/hello-world-mcp-server.gif)
313314

314315

315316
## Macros
@@ -522,10 +523,10 @@ Learn when to use the `mcp_*_handler` traits versus the lower-level `mcp_*_hand
522523
[rust-mcp-sdk](https://github.com/rust-mcp-stack/rust-mcp-sdk) provides two type of handler traits that you can chose from:
523524

524525
- **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.
525-
Refer to [examples/hello-world-mcp-server-stdio/src/handler.rs](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/examples/hello-world-mcp-server-stdio/src/handler.rs) for an example.
526+
Refer to [examples/common/example_server_handler.rs](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/crates/rust-mcp-sdk/examples/common/example_server_handler.rs) for an example.
526527

527528
- **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.
528-
Refer to [examples/hello-world-mcp-server-stdio-core/src/handler.rs](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/examples/hello-world-mcp-server-stdio-core/src/handler.rs) for an example.
529+
Refer to [examples/common/example_server_handler_core.rs](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/crates/rust-mcp-sdk/examples/common/example_server_handler_core.rs) for an example.
529530

530531
---
531532

@@ -554,7 +555,7 @@ Both functions create an MCP client instance.
554555

555556

556557

557-
Check out the corresponding examples at: [examples/simple-mcp-client-stdio](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/examples/simple-mcp-client-stdio) and [examples/simple-mcp-client-stdio-core](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/examples/simple-mcp-client-stdio-core).
558+
Check out the corresponding examples at: [examples/simple-mcp-client-stdio.rs](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/crates/rust-mcp-sdk/examples/simple-mcp-client-stdio.rs) and [examples/simple-mcp-client-stdio-core.rs](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/crates/rust-mcp-sdk/examples/simple-mcp-client-stdio-core.rs).
558559

559560

560561
## Projects using Rust MCP SDK
52.1 KB
Loading
-266 KB
Binary file not shown.
-504 KB
Binary file not shown.
-71.1 KB
Loading

crates/rust-mcp-sdk/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ time = {version="0.3.0", features = ["formatting", "local-offset"]}
5151
[dev-dependencies]
5252
wiremock = "0.5"
5353
tempfile = "3.23.0"
54+
colored = "3.0.0"
5455
tokio = { workspace=true, features = ["full", "test-util"] }
56+
rust-mcp-extra={path="../rust-mcp-extra"}
5557
tracing-subscriber = { workspace = true, features = [
5658
"env-filter",
5759
"std",
@@ -84,6 +86,7 @@ tls-no-provider = ["axum-server/tls-rustls-no-provider"]
8486
macros = ["rust-mcp-macros/sdk"]
8587

8688

89+
8790
[lints]
8891
workspace = true
8992

crates/rust-mcp-sdk/README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,14 @@ async fn main() -> SdkResult<()> {
303303

304304
## Usage Examples
305305

306-
👉 For full examples (stdio, Streamable HTTP, clients, auth, etc.), see the [examples/](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/examples) directory.
306+
👉 For more examples (stdio, Streamable HTTP, clients, auth, etc.), see the [examples/](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/crates/rust-mcp-sdk/examples) directory.
307307

308308
👉 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)
309309

310-
See [hello-world-mcp-server-stdio](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/examples/hello-world-mcp-server-stdio) example running in [MCP Inspector](https://modelcontextprotocol.io/docs/tools/inspector) :
310+
See [hello-world-mcp-server-stdio](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/crates/rust-mcp-sdk/examples/hello-world-mcp-server-stdio.rs) example running in [MCP Inspector](https://modelcontextprotocol.io/docs/tools/inspector) :
311+
312+
<img src="assets/examples/hello-world-mcp-server.gif" alt="hello world mcp server in rust" width="800" />
311313

312-
![mcp-server in rust](assets/examples/hello-world-mcp-server.gif)
313314

314315

315316
## Macros
@@ -522,10 +523,10 @@ Learn when to use the `mcp_*_handler` traits versus the lower-level `mcp_*_hand
522523
[rust-mcp-sdk](https://github.com/rust-mcp-stack/rust-mcp-sdk) provides two type of handler traits that you can chose from:
523524

524525
- **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.
525-
Refer to [examples/hello-world-mcp-server-stdio/src/handler.rs](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/examples/hello-world-mcp-server-stdio/src/handler.rs) for an example.
526+
Refer to [examples/common/example_server_handler.rs](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/crates/rust-mcp-sdk/examples/common/example_server_handler.rs) for an example.
526527

527528
- **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.
528-
Refer to [examples/hello-world-mcp-server-stdio-core/src/handler.rs](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/examples/hello-world-mcp-server-stdio-core/src/handler.rs) for an example.
529+
Refer to [examples/common/example_server_handler_core.rs](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/crates/rust-mcp-sdk/examples/common/example_server_handler_core.rs) for an example.
529530

530531
---
531532

@@ -554,7 +555,7 @@ Both functions create an MCP client instance.
554555

555556

556557

557-
Check out the corresponding examples at: [examples/simple-mcp-client-stdio](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/examples/simple-mcp-client-stdio) and [examples/simple-mcp-client-stdio-core](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/examples/simple-mcp-client-stdio-core).
558+
Check out the corresponding examples at: [examples/simple-mcp-client-stdio.rs](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/crates/rust-mcp-sdk/examples/simple-mcp-client-stdio.rs) and [examples/simple-mcp-client-stdio-core.rs](https://github.com/rust-mcp-stack/rust-mcp-sdk/tree/main/crates/rust-mcp-sdk/examples/simple-mcp-client-stdio-core.rs).
558559

559560

560561
## Projects using Rust MCP SDK

0 commit comments

Comments
 (0)