Skip to content

Commit d5a72e4

Browse files
authored
fix(examples): add servers in examples's readme (#229)
Signed-off-by: jokemanfire <[email protected]>
1 parent 0ce1418 commit d5a72e4

File tree

10 files changed

+140
-18
lines changed

10 files changed

+140
-18
lines changed

examples/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ see [clients/README.md](clients/README.md)
5959

6060
# Server Examples
6161

62-
- [Server SSE](servers/src/axum.rs), using axum as web server.
63-
- [Server stdio](servers/src/std_io.rs), using tokio async io.
62+
see [servers/README.md](servers/README.md)
6463

6564
# Transport Examples
6665

examples/servers/Cargo.toml

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,35 @@ serde_urlencoded = "0.7"
2929
askama = { version = "0.14"}
3030
tower-http = { version = "0.6", features = ["cors"] }
3131

32-
# [dev-dependencies.'cfg(target_arch="linux")'.dependencies]
3332

3433
[dev-dependencies]
3534
tokio-stream = { version = "0.1" }
36-
# tokio-util = { version = "0.7", features = ["io", "codec"] }
3735
tokio-util = { version = "0.7", features = ["codec"] }
3836

3937
[[example]]
40-
name = "servers_std_io"
41-
path = "src/std_io.rs"
38+
name = "servers_counter_stdio"
39+
path = "src/counter_stdio.rs"
4240

4341
[[example]]
44-
name = "servers_axum"
45-
path = "src/axum.rs"
42+
name = "servers_counter_sse"
43+
path = "src/counter_sse.rs"
4644

4745
[[example]]
48-
name = "servers_axum_router"
49-
path = "src/axum_router.rs"
46+
name = "servers_counter_sse_directly"
47+
path = "src/counter_sse_directly.rs"
5048

5149
[[example]]
52-
name = "servers_generic_server"
53-
path = "src/generic_service.rs"
50+
name = "servers_memory_stdio"
51+
path = "src/memory_stdio.rs"
5452

5553
[[example]]
56-
name = "servers_axum_streamable_http"
57-
path = "src/axum_streamable_http.rs"
54+
name = "servers_counter_streamhttp"
55+
path = "src/counter_streamhttp.rs"
5856

5957
[[example]]
60-
name = "servers_auth_sse"
61-
path = "src/auth_sse.rs"
58+
name = "servers_complex_auth_sse"
59+
path = "src/complex_auth_sse.rs"
6260

6361
[[example]]
64-
name = "mcp_oauth_server"
65-
path = "src/mcp_oauth_server.rs"
62+
name = "servers_simple_auth_sse"
63+
path = "src/simple_auth_sse.rs"

examples/servers/README.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# MCP Server Examples
2+
3+
This directory contains Model Context Protocol (MCP) server examples implemented in Rust. These examples demonstrate how to create MCP servers using different transport methods and how to implement various server capabilities including tools, resources, prompts, and authentication.
4+
5+
## Example List
6+
7+
### Counter Standard I/O Server (`counter_stdio.rs`)
8+
9+
A basic MCP server that communicates using standard input/output transport.
10+
11+
- Provides a simple counter tool with increment, decrement, and get_value operations
12+
- Demonstrates basic tool implementation and stdio transport
13+
14+
### Counter SSE Server (`counter_sse.rs`)
15+
16+
A server that provides counter functionality using Server-Sent Events (SSE) transport.
17+
18+
- Runs on `http://127.0.0.1:8000/sse` by default
19+
- Provides the same counter tools as the stdio version
20+
- Demonstrates SSE transport setup with graceful shutdown
21+
- Can be accessed via web browsers or SSE-compatible clients
22+
23+
### Counter SSE Direct Server (`counter_sse_directly.rs`)
24+
25+
A minimal SSE server implementation showing direct SSE server usage.
26+
27+
- Simplified version of the SSE server
28+
- Demonstrates basic SSE server configuration
29+
- Provides counter functionality with minimal setup
30+
31+
### Memory Standard I/O Server (`memory_stdio.rs`)
32+
33+
A minimal server example using stdio transport.
34+
35+
- Lightweight server implementation
36+
- Demonstrates basic server setup patterns
37+
- Good starting point for custom server development
38+
39+
### Counter Streamable HTTP Server (`counter_streamhttp.rs`)
40+
41+
A server using streamable HTTP transport for MCP communication.
42+
43+
- Runs on HTTP with streaming capabilities
44+
- Provides counter tools via HTTP streaming
45+
- Demonstrates streamable HTTP transport configuration
46+
47+
### Complex OAuth SSE Server (`complex_auth_sse.rs`)
48+
49+
A comprehensive example demonstrating OAuth 2.0 integration with MCP servers.
50+
51+
- Full OAuth 2.0 authorization server implementation
52+
- Client registration and token management
53+
- User authorization flow with web interface
54+
- Token validation middleware
55+
- Integrated with MCP SSE transport
56+
- Demonstrates enterprise-grade authentication patterns
57+
58+
### Simple OAuth SSE Server (`simple_auth_sse.rs`)
59+
60+
A simplified OAuth example showing basic token-based authentication.
61+
62+
- Basic token store and validation
63+
- Authorization middleware for SSE endpoints
64+
- Token generation API
65+
- Simplified authentication flow
66+
- Good starting point for adding authentication to MCP servers
67+
68+
## How to Run
69+
70+
Each example can be run using Cargo:
71+
72+
```bash
73+
# Run the counter standard I/O server
74+
cargo run --example servers_counter_stdio
75+
76+
# Run the counter SSE server
77+
cargo run --example servers_counter_sse
78+
79+
# Run the counter SSE direct server
80+
cargo run --example servers_counter_sse_directly
81+
82+
# Run the memory standard I/O server
83+
cargo run --example servers_memory_stdio
84+
85+
# Run the counter streamable HTTP server
86+
cargo run --example servers_counter_streamhttp
87+
88+
# Run the complex OAuth SSE server
89+
cargo run --example servers_complex_auth_sse
90+
91+
# Run the simple OAuth SSE server
92+
cargo run --example servers_simple_auth_sse
93+
```
94+
95+
## Testing with MCP Inspector
96+
97+
Many of these servers can be tested using the MCP Inspector tool:
98+
See [inspector](https://github.com/modelcontextprotocol/inspector)
99+
100+
## Dependencies
101+
102+
These examples use the following main dependencies:
103+
104+
- `rmcp`: Rust implementation of the MCP server library
105+
- `tokio`: Asynchronous runtime
106+
- `serde` and `serde_json`: For JSON serialization and deserialization
107+
- `tracing` and `tracing-subscriber`: For logging
108+
- `anyhow`: Error handling
109+
- `axum`: Web framework for HTTP-based transports
110+
- `tokio-util`: Utilities for async programming
111+
- `askama`: Template engine (used in OAuth examples)
112+
- `tower-http`: HTTP middleware (used for CORS in OAuth examples)
113+
- `uuid`: UUID generation (used in OAuth examples)
114+
- `chrono`: Date and time handling (used in OAuth examples)
115+
- `rand`: Random number generation (used in OAuth examples)
116+
117+
## Common Module
118+
119+
The `common/` directory contains shared code used across examples:
120+
121+
- `counter.rs`: Counter tool implementation with MCP server traits
122+
- `calculator.rs`: Calculator tool examples
123+
- `generic_service.rs`: Generic service implementations
124+
125+
This modular approach allows for code reuse and demonstrates how to structure larger MCP server applications.

0 commit comments

Comments
 (0)