-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasic.rs
More file actions
70 lines (54 loc) · 1.89 KB
/
basic.rs
File metadata and controls
70 lines (54 loc) · 1.89 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
//! Basic Conduit SDK usage example
use datagrout_conduit::{ClientBuilder, Transport};
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Initialize logging
tracing_subscriber::fmt::init();
println!("=== DataGrout Conduit - Basic Example ===\n");
// Create client
let client = ClientBuilder::new()
.url("https://gateway.datagrout.ai/servers/{your-uuid}/mcp")
.transport(Transport::Mcp) // or Transport::JsonRpc
.auth_bearer("your-token-here")
.max_retries(3)
.build()?;
println!("✓ Client created");
// Connect and initialize
client.connect().await?;
println!("✓ Connected and initialized");
// Get server info
if let Some(info) = client.server_info().await {
println!("\nServer: {} v{}", info.name, info.version);
}
// List tools
println!("\n--- Listing Tools ---");
let tools = client.list_tools().await?;
println!("Found {} tools", tools.len());
for tool in tools.iter().take(5) {
println!(
" • {} - {}",
tool.name,
tool.description.as_deref().unwrap_or("")
);
}
// Call a tool
if !tools.is_empty() {
let tool_name = &tools[0].name;
println!("\n--- Calling Tool: {} ---", tool_name);
let result = client.call_tool(tool_name, json!({})).await?;
println!("Result: {}", serde_json::to_string_pretty(&result)?);
}
// List resources
println!("\n--- Listing Resources ---");
let resources = client.list_resources().await?;
println!("Found {} resources", resources.len());
// List prompts
println!("\n--- Listing Prompts ---");
let prompts = client.list_prompts().await?;
println!("Found {} prompts", prompts.len());
// Disconnect
client.disconnect().await?;
println!("\n✓ Disconnected");
Ok(())
}