cnctd_ai
A Rust abstraction layer for AI/LLM providers (Anthropic Claude, OpenAI) with integrated MCP (Model Context Protocol) support.
Features
- Multi-Provider Support: Unified interface for Anthropic Claude and OpenAI
- Streaming & Non-Streaming: Support for both regular completions and streaming responses
- Tool Calling: Full support for function/tool calling with both providers
- MCP Integration: Native support for MCP servers (stdio and HTTP gateway)
- Error Handling: Comprehensive error types with provider-specific handling
- Type Safety: Strong typing with proper error handling throughout
Installation
Add to your Cargo.toml:
[]
= "0.1.5"
Quick Start
Basic Completion
use ;
let client = anthropic?;
let request = CompletionRequest ;
let response = client.complete.await?;
println!;
Streaming
use ;
let mut stream = client.complete_stream.await?;
while let Some = stream.next.await
Tool Calling
use ;
use json;
// Create a tool using the helper function
let weather_tool = create_tool?;
let mut request = CompletionRequest ;
request.add_tool;
let response = client.complete.await?;
// Check if model wants to use a tool
if let Some = response.tool_use
MCP Gateway Integration
use McpGateway;
let gateway = new;
// List available servers
let servers = gateway.list_servers.await?;
// List tools from a specific server
let tools = gateway.list_tools.await?;
// Execute a tool
let result = gateway.call_tool.await?;
Examples
The repository includes several examples:
basic_completion.rs- Simple completion examplestreaming.rs- Streaming responsestool_calling.rs- Function/tool callingtool_calling_streaming.rs- Tool calling with streamingconversation.rs- Multi-turn conversationserror_handling.rs- Error handling patternsmcp_gateway.rs- MCP gateway integration
Run examples with:
Environment Variables
Set these for the examples:
ANTHROPIC_API_KEY=your-anthropic-key
OPENAI_API_KEY=your-openai-key
GATEWAY_URL=https://mcp.cnctd.world # Optional
GATEWAY_TOKEN=your-token # Optional
Tool Creation Helpers
The library provides helper functions for easier tool creation:
use ;
// For owned strings (runtime data)
let tool = create_tool?;
// For static strings (compile-time constants)
let tool = create_tool_borrowed?;
Error Handling
The library provides comprehensive error types:
use Error;
match client.complete.await
License
MIT License - see LICENSE file for details.