-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiscovery.rs
More file actions
79 lines (65 loc) · 2.24 KB
/
discovery.rs
File metadata and controls
79 lines (65 loc) · 2.24 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
//! Semantic discovery example
use datagrout_conduit::{ClientBuilder, Transport};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::fmt::init();
println!("=== DataGrout Conduit - Discovery Example ===\n");
let client = ClientBuilder::new()
.url("https://gateway.datagrout.ai/servers/{your-uuid}/mcp")
.transport(Transport::Mcp)
.auth_bearer("your-token-here")
.build()?;
client.connect().await?;
println!("✓ Connected\n");
// Example 1: Query-based discovery
println!("--- Query-Based Discovery ---");
let results = client
.discover()
.query("get lead by email")
.integration("salesforce")
.limit(10)
.min_score(0.7)
.execute()
.await?;
println!("Found {} tools:", results.tools.len());
for tool in &results.tools {
println!(" • {} (score: {:.2})", tool.name, tool.score);
if !tool.description.is_empty() {
println!(" {}", tool.description);
}
}
// Example 2: Goal-based discovery
println!("\n--- Goal-Based Discovery ---");
let results = client
.discover()
.goal("I need to find a customer by their email address")
.integration("salesforce")
.limit(5)
.execute()
.await?;
println!("Found {} matching tools:", results.tools.len());
for tool in &results.tools {
println!(" • {} (score: {:.2})", tool.name, tool.score);
}
// Example 3: Direct tool execution with perform
if let Some(tool) = results.tools.first() {
println!("\n--- Executing Tool via Perform ---");
let result = client
.perform(&tool.name)
.args(serde_json::json!({
"email": "john@example.com"
}))
.execute()
.await?;
println!("Result: {}", serde_json::to_string_pretty(&result)?);
if let Some(meta) = datagrout_conduit::extract_meta(&result) {
println!(
"\n📄 Receipt: {} — {:.4} credits",
meta.receipt.receipt_id, meta.receipt.net_credits
);
}
}
client.disconnect().await?;
println!("\n✓ Done");
Ok(())
}