chore: move examples out of various places into a top-level dir (#10)
This commit is contained in:
parent
b24e912543
commit
6609aa6aa8
11 changed files with 163 additions and 1 deletions
|
|
@ -1,5 +1,10 @@
|
|||
[workspace]
|
||||
members = ["crates/*"]
|
||||
members = [
|
||||
"crates/*",
|
||||
"examples/clients",
|
||||
"examples/servers",
|
||||
"examples/macros"
|
||||
]
|
||||
resolver = "2"
|
||||
|
||||
[workspace.dependencies]
|
||||
|
|
|
|||
84
examples/README.md
Normal file
84
examples/README.md
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
# Model Context Protocol Examples
|
||||
|
||||
This directory contains examples demonstrating how to use the Model Context Protocol (MCP) Rust SDK.
|
||||
|
||||
## Structure
|
||||
|
||||
- `clients/`: Examples of MCP clients
|
||||
- `servers/`: Examples of MCP servers
|
||||
- `macros/`: Examples of MCP macros
|
||||
|
||||
## Running Client Examples
|
||||
|
||||
The client examples demonstrate different ways to connect to MCP servers.
|
||||
|
||||
### Available Examples
|
||||
|
||||
You can run the examples in two ways:
|
||||
|
||||
#### Option 1: From the examples/clients directory
|
||||
|
||||
```bash
|
||||
cd examples/clients
|
||||
cargo run --example clients
|
||||
cargo run --example sse
|
||||
cargo run --example stdio
|
||||
cargo run --example stdio_integration
|
||||
```
|
||||
|
||||
#### Option 2: From the root directory
|
||||
|
||||
```bash
|
||||
cargo run -p mcp-client-examples --example clients
|
||||
cargo run -p mcp-client-examples --example sse
|
||||
cargo run -p mcp-client-examples --example stdio
|
||||
cargo run -p mcp-client-examples --example stdio_integration
|
||||
```
|
||||
|
||||
## Running Server Examples
|
||||
|
||||
The server examples demonstrate how to implement MCP servers.
|
||||
|
||||
### Available Examples
|
||||
|
||||
You can run the server examples in two ways:
|
||||
|
||||
#### Option 1: From the examples/servers directory
|
||||
|
||||
```bash
|
||||
cd examples/servers
|
||||
cargo run --example counter-server
|
||||
```
|
||||
|
||||
#### Option 2: From the root directory
|
||||
|
||||
```bash
|
||||
cargo run -p mcp-server-examples --example counter-server
|
||||
```
|
||||
|
||||
## Running Macros Examples
|
||||
|
||||
The macros examples demonstrate how to use the MCP macros to create tools.
|
||||
|
||||
### Available Examples
|
||||
|
||||
You can run the macros examples in two ways:
|
||||
|
||||
#### Option 1: From the examples/macros directory
|
||||
|
||||
```bash
|
||||
cd examples/macros
|
||||
cargo run --example calculator
|
||||
```
|
||||
|
||||
#### Option 2: From the root directory
|
||||
|
||||
```bash
|
||||
cargo run -p mcp-macros-examples --example calculator
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
- Some examples may require additional setup or running both client and server components.
|
||||
- The server examples use standard I/O for communication, so they can be connected to client examples using stdio transport.
|
||||
- For SSE examples, you may need to run a separate SSE server or use a compatible MCP server implementation.
|
||||
33
examples/clients/Cargo.toml
Normal file
33
examples/clients/Cargo.toml
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
[package]
|
||||
name = "mcp-client-examples"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
mcp-client = { path = "../../crates/mcp-client" }
|
||||
mcp-core = { path = "../../crates/mcp-core" }
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||
rand = "0.8"
|
||||
futures = "0.3"
|
||||
anyhow = "1.0"
|
||||
|
||||
[[example]]
|
||||
name = "clients"
|
||||
path = "src/clients.rs"
|
||||
|
||||
[[example]]
|
||||
name = "sse"
|
||||
path = "src/sse.rs"
|
||||
|
||||
[[example]]
|
||||
name = "stdio"
|
||||
path = "src/stdio.rs"
|
||||
|
||||
[[example]]
|
||||
name = "stdio_integration"
|
||||
path = "src/stdio_integration.rs"
|
||||
18
examples/macros/Cargo.toml
Normal file
18
examples/macros/Cargo.toml
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
[package]
|
||||
name = "mcp-macros-examples"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
mcp-core = { path = "../../crates/mcp-core" }
|
||||
mcp-macros = { path = "../../crates/mcp-macros" }
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
async-trait = "0.1"
|
||||
schemars = "0.8"
|
||||
|
||||
[[example]]
|
||||
name = "calculator"
|
||||
path = "src/calculator.rs"
|
||||
22
examples/servers/Cargo.toml
Normal file
22
examples/servers/Cargo.toml
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
[package]
|
||||
name = "mcp-server-examples"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
mcp-server = { path = "../../crates/mcp-server" }
|
||||
mcp-core = { path = "../../crates/mcp-core" }
|
||||
mcp-macros = { path = "../../crates/mcp-macros" }
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
anyhow = "1.0"
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||
tracing-appender = "0.2"
|
||||
futures = "0.3"
|
||||
|
||||
[[example]]
|
||||
name = "counter-server"
|
||||
path = "src/counter_server.rs"
|
||||
Loading…
Reference in a new issue