use openrouter_api::{mcp_types::*, MCPClient, Result};
use serde_json::json;
#[tokio::main]
async fn main() -> Result<()> {
let client = MCPClient::new("https://mcp-server.example.com/mcp")?;
println!("Initializing MCP client...");
let server_capabilities = client
.initialize(ClientCapabilities {
protocol_version: MCP_PROTOCOL_VERSION.to_string(),
supports_sampling: Some(true),
})
.await?;
println!(
"Connected to MCP server with capabilities: {:?}",
server_capabilities
);
let resource_id = "document-123".to_string();
println!("\nAttempting to get resource: {}", resource_id);
match client
.get_resource(GetResourceParams {
id: resource_id,
parameters: None,
})
.await
{
Ok(resource) => println!("Retrieved resource: {:?}", resource.contents),
Err(e) => println!("Failed to get resource: {}", e),
}
let tool_id = "search-tool".to_string();
println!("\nAttempting to call tool: {}", tool_id);
match client
.tool_call(ToolCallParams {
id: tool_id,
parameters: json!({
"query": "Rust programming"
}),
})
.await
{
Ok(result) => println!("Tool call result: {:?}", result.result),
Err(e) => println!("Failed to call tool: {}", e),
}
Ok(())
}