-
Notifications
You must be signed in to change notification settings - Fork 478
Expand file tree
/
Copy patheverything_stdio.rs
More file actions
92 lines (78 loc) · 2.88 KB
/
everything_stdio.rs
File metadata and controls
92 lines (78 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use anyhow::Result;
use rmcp::{
ServiceExt,
model::{CallToolRequestParams, GetPromptRequestParams, ReadResourceRequestParams},
object,
transport::{ConfigureCommandExt, TokioChildProcess},
};
use tokio::process::Command;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
#[tokio::main]
async fn main() -> Result<()> {
// Initialize logging
tracing_subscriber::registry()
.with(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| format!("info,{}=debug", env!("CARGO_CRATE_NAME")).into()),
)
.with(tracing_subscriber::fmt::layer())
.init();
let client = ()
.serve(TokioChildProcess::new(Command::new("npx").configure(
|cmd| {
cmd.arg("-y").arg("@modelcontextprotocol/server-everything");
},
))?)
.await?;
// Initialize
let server_info = client.peer_info();
tracing::info!("Connected to server: {server_info:#?}");
// List tools
let tools = client.list_all_tools().await?;
tracing::info!("Available tools: {tools:#?}");
// Call tool echo
let tool_result = client
.call_tool(
CallToolRequestParams::new("echo")
.with_arguments(object!({ "message": "hi from rmcp" })),
)
.await?;
tracing::info!("Tool result for echo: {tool_result:#?}");
// Call tool longRunningOperation
let tool_result = client
.call_tool(
CallToolRequestParams::new("longRunningOperation")
.with_arguments(object!({ "duration": 3, "steps": 1 })),
)
.await?;
tracing::info!("Tool result for longRunningOperation: {tool_result:#?}");
// List resources
let resources = client.list_all_resources().await?;
tracing::info!("Available resources: {resources:#?}");
// Read resource
let resource = client
.read_resource(ReadResourceRequestParams::new("test://static/resource/3"))
.await?;
tracing::info!("Resource: {resource:#?}");
// List prompts
let prompts = client.list_all_prompts().await?;
tracing::info!("Available prompts: {prompts:#?}");
// Get simple prompt
let prompt = client
.get_prompt(GetPromptRequestParams::new("simple_prompt"))
.await?;
tracing::info!("Prompt - simple: {prompt:#?}");
// Get complex prompt (returns text & image)
let prompt = client
.get_prompt(
GetPromptRequestParams::new("complex_prompt")
.with_arguments(object!({ "temperature": "0.5", "style": "formal" })),
)
.await?;
tracing::info!("Prompt - complex: {prompt:#?}");
// List resource templates
let resource_templates = client.list_all_resource_templates().await?;
tracing::info!("Available resource templates: {resource_templates:#?}");
client.cancel().await?;
Ok(())
}