| Crates.io | sovran-mcp |
| lib.rs | sovran-mcp |
| version | 0.3.6 |
| created_at | 2025-02-15 22:10:58.363307+00 |
| updated_at | 2025-02-15 23:17:47.895992+00 |
| description | A synchronous Rust client for the Model Context Protocol (MCP) |
| homepage | |
| repository | https://github.com/sovran-la/sovran-mcp |
| max_upload_size | |
| id | 1557145 |
| size | 141,288 |
A synchronous Rust client for the Model Context Protocol (MCP).
sovran-mcp provides a clean, synchronous interface for interacting with MCP servers. It handles:
Add to your Cargo.toml:
[dependencies]
sovran-mcp = "0.3.1"
Basic example:
use sovran_mcp::{McpClient, transport::StdioTransport};
fn main() -> Result<(), sovran_mcp::McpError> {
// Create and start client
let transport = StdioTransport::new("npx", &["-y", "@modelcontextprotocol/server-everything"])?;
let mut client = McpClient::new(transport, None, None);
client.start()?;
// List available tools
if client.supports_tools() {
let tools = client.list_tools()?;
println!("Available tools: {}", tools.tools.len());
// Call a tool
let response = client.call_tool(
"echo".to_string(),
Some(serde_json::json!({
"message": "Hello, MCP!"
}))
)?;
}
// Clean up
client.stop()?;
Ok(())
}
Support for server-initiated LLM completions:
use sovran_mcp::types::*;
struct MySamplingHandler;
impl SamplingHandler for MySamplingHandler {
fn handle_message(&self, request: CreateMessageRequest) -> Result<CreateMessageResponse, McpError> {
// Process completion request
Ok(CreateMessageResponse {
content: MessageContent::Text(TextContent {
text: "Response".to_string()
}),
model: "test-model".to_string(),
role: Role::Assistant,
stop_reason: Some("complete".to_string()),
meta: None,
})
}
}
Support for resource update notifications:
use sovran_mcp::types::*;
use url::Url;
struct MyNotificationHandler;
impl NotificationHandler for MyNotificationHandler {
fn handle_resource_update(&self, uri: &Url) -> Result<(), McpError> {
println!("Resource updated: {}", uri);
Ok(())
}
}
The crate uses McpError for comprehensive error handling, covering:
MIT License
Contributions welcome! Please feel free to submit a Pull Request.