-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexternal_mcp.rs
More file actions
114 lines (102 loc) · 4.05 KB
/
Copy pathexternal_mcp.rs
File metadata and controls
114 lines (102 loc) · 4.05 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//! External MCP servers — configure external MCP server connections.
//!
//! This example demonstrates the `.mcp_servers()` configuration for connecting
//! to external MCP servers (filesystem, database, API servers, etc.).
//!
//! **Note:** `McpServerConfig` is currently a placeholder struct — the full
//! configuration API (command, args, env, URL) is planned for a future release.
//! This example documents the intended usage pattern.
//!
//! For SDK-hosted MCP tools (Rust functions), see the `custom_tool` example instead.
//!
//! ## Run
//! ```sh
//! cargo run -p examples --example external_mcp
//! ```
use rusty_claw::prelude::*;
use std::collections::HashMap;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::fmt()
.with_env_filter(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| "rusty_claw=warn".parse().unwrap()),
)
.with_target(false)
.init();
println!("=== External MCP Server Configuration ===\n");
// --- Current API (placeholder) ---
// McpServerConfig is currently an empty struct. The CLI's --mcp-config
// flag expects a JSON config file, but the SDK doesn't yet populate it
// with server connection details.
let mut mcp_servers = HashMap::new();
// TODO: Once McpServerConfig is fully implemented, these will include:
// command: "npx",
// args: ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"],
// env: { "KEY": "value" },
// url: "http://localhost:3000/mcp",
use rusty_claw::options::{McpServerConfig, McpStdioServerConfig};
use std::collections::HashMap as EnvMap;
mcp_servers.insert(
"filesystem".to_string(),
McpServerConfig::Stdio(McpStdioServerConfig {
command: "npx".to_string(),
args: vec![
"-y".to_string(),
"@modelcontextprotocol/server-filesystem".to_string(),
"/tmp".to_string(),
],
env: EnvMap::new(),
}),
);
mcp_servers.insert(
"database".to_string(),
McpServerConfig::Stdio(McpStdioServerConfig {
command: "npx".to_string(),
args: vec![
"-y".to_string(),
"@modelcontextprotocol/server-database".to_string(),
],
env: EnvMap::new(),
}),
);
let options = ClaudeAgentOptions::builder()
.max_turns(3)
.permission_mode(PermissionMode::AcceptEdits)
.mcp_servers(mcp_servers)
.build();
println!(
"Configured {} external MCP server(s):",
options.mcp_servers.len()
);
for name in options.mcp_servers.keys() {
println!(" - {}", name);
}
// --- SDK-hosted MCP tools (working API) ---
println!("\n=== SDK-Hosted MCP Comparison ===\n");
println!("For Rust-native tools, use SdkMcpServerImpl instead:");
println!();
println!(" let mut server = SdkMcpServerImpl::new(\"my_tools\", \"1.0.0\");");
println!(" server.register_tool(my_tool);");
println!(" let registry = SdkMcpServerRegistry::new(vec![server]);");
println!(" client.register_mcp_message_handler(Arc::new(registry));");
println!();
println!("See the `custom_tool` example for a complete working demo.\n");
// --- Intended future usage ---
println!("=== Intended Future API ===\n");
println!("When McpServerConfig is fully implemented:");
println!();
println!(" let mut servers = HashMap::new();");
println!(" servers.insert(\"filesystem\".to_string(), McpServerConfig {{");
println!(" command: \"npx\".to_string(),");
println!(" args: vec![\"-y\", \"@modelcontextprotocol/server-filesystem\", \"/tmp\"],");
println!(" env: HashMap::new(),");
println!(" }});");
println!();
println!(" let options = ClaudeAgentOptions::builder()");
println!(" .mcp_servers(servers)");
println!(" .build();");
println!();
println!("Done — documented external MCP server configuration.");
Ok(())
}