Skip to content

Commit 6609aa6

Browse files
authored
chore: move examples out of various places into a top-level dir (#10)
1 parent b24e912 commit 6609aa6

File tree

11 files changed

+163
-1
lines changed

11 files changed

+163
-1
lines changed

Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
[workspace]
2-
members = ["crates/*"]
2+
members = [
3+
"crates/*",
4+
"examples/clients",
5+
"examples/servers",
6+
"examples/macros"
7+
]
38
resolver = "2"
49

510
[workspace.dependencies]

examples/README.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Model Context Protocol Examples
2+
3+
This directory contains examples demonstrating how to use the Model Context Protocol (MCP) Rust SDK.
4+
5+
## Structure
6+
7+
- `clients/`: Examples of MCP clients
8+
- `servers/`: Examples of MCP servers
9+
- `macros/`: Examples of MCP macros
10+
11+
## Running Client Examples
12+
13+
The client examples demonstrate different ways to connect to MCP servers.
14+
15+
### Available Examples
16+
17+
You can run the examples in two ways:
18+
19+
#### Option 1: From the examples/clients directory
20+
21+
```bash
22+
cd examples/clients
23+
cargo run --example clients
24+
cargo run --example sse
25+
cargo run --example stdio
26+
cargo run --example stdio_integration
27+
```
28+
29+
#### Option 2: From the root directory
30+
31+
```bash
32+
cargo run -p mcp-client-examples --example clients
33+
cargo run -p mcp-client-examples --example sse
34+
cargo run -p mcp-client-examples --example stdio
35+
cargo run -p mcp-client-examples --example stdio_integration
36+
```
37+
38+
## Running Server Examples
39+
40+
The server examples demonstrate how to implement MCP servers.
41+
42+
### Available Examples
43+
44+
You can run the server examples in two ways:
45+
46+
#### Option 1: From the examples/servers directory
47+
48+
```bash
49+
cd examples/servers
50+
cargo run --example counter-server
51+
```
52+
53+
#### Option 2: From the root directory
54+
55+
```bash
56+
cargo run -p mcp-server-examples --example counter-server
57+
```
58+
59+
## Running Macros Examples
60+
61+
The macros examples demonstrate how to use the MCP macros to create tools.
62+
63+
### Available Examples
64+
65+
You can run the macros examples in two ways:
66+
67+
#### Option 1: From the examples/macros directory
68+
69+
```bash
70+
cd examples/macros
71+
cargo run --example calculator
72+
```
73+
74+
#### Option 2: From the root directory
75+
76+
```bash
77+
cargo run -p mcp-macros-examples --example calculator
78+
```
79+
80+
## Notes
81+
82+
- Some examples may require additional setup or running both client and server components.
83+
- The server examples use standard I/O for communication, so they can be connected to client examples using stdio transport.
84+
- For SSE examples, you may need to run a separate SSE server or use a compatible MCP server implementation.

examples/clients/Cargo.toml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[package]
2+
name = "mcp-client-examples"
3+
version = "0.1.0"
4+
edition = "2021"
5+
publish = false
6+
7+
[dependencies]
8+
mcp-client = { path = "../../crates/mcp-client" }
9+
mcp-core = { path = "../../crates/mcp-core" }
10+
tokio = { version = "1", features = ["full"] }
11+
serde = { version = "1.0", features = ["derive"] }
12+
serde_json = "1.0"
13+
tracing = "0.1"
14+
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
15+
rand = "0.8"
16+
futures = "0.3"
17+
anyhow = "1.0"
18+
19+
[[example]]
20+
name = "clients"
21+
path = "src/clients.rs"
22+
23+
[[example]]
24+
name = "sse"
25+
path = "src/sse.rs"
26+
27+
[[example]]
28+
name = "stdio"
29+
path = "src/stdio.rs"
30+
31+
[[example]]
32+
name = "stdio_integration"
33+
path = "src/stdio_integration.rs"
File renamed without changes.

examples/macros/Cargo.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[package]
2+
name = "mcp-macros-examples"
3+
version = "0.1.0"
4+
edition = "2021"
5+
publish = false
6+
7+
[dependencies]
8+
mcp-core = { path = "../../crates/mcp-core" }
9+
mcp-macros = { path = "../../crates/mcp-macros" }
10+
tokio = { version = "1", features = ["full"] }
11+
serde = { version = "1.0", features = ["derive"] }
12+
serde_json = "1.0"
13+
async-trait = "0.1"
14+
schemars = "0.8"
15+
16+
[[example]]
17+
name = "calculator"
18+
path = "src/calculator.rs"

examples/servers/Cargo.toml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[package]
2+
name = "mcp-server-examples"
3+
version = "0.1.0"
4+
edition = "2021"
5+
publish = false
6+
7+
[dependencies]
8+
mcp-server = { path = "../../crates/mcp-server" }
9+
mcp-core = { path = "../../crates/mcp-core" }
10+
mcp-macros = { path = "../../crates/mcp-macros" }
11+
tokio = { version = "1", features = ["full"] }
12+
serde = { version = "1.0", features = ["derive"] }
13+
serde_json = "1.0"
14+
anyhow = "1.0"
15+
tracing = "0.1"
16+
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
17+
tracing-appender = "0.2"
18+
futures = "0.3"
19+
20+
[[example]]
21+
name = "counter-server"
22+
path = "src/counter_server.rs"

0 commit comments

Comments
 (0)