基本能力
产品定位
Commune是一个用于构建和管理AI代理网络的Rust库,专注于对等发现和资源利用。
核心功能
- 发现和维护对等MCP服务器列表
- 利用对等服务器上的可用工具、提示和资源
- 支持WebSocket通信(带和不带TLS加密)
- 为AWS、OpenAI等推理API提供类型转换,简化其使用
适用场景
- 构建分布式AI代理网络
- 管理和利用多个MCP服务器的资源
- 简化不同推理API的集成
工具列表
PeerBuilder
: 用于创建和配置对等MCP服务器ClientBuilder
: 用于创建Commune客户端,管理多个对等服务器all_tools()
: 获取所有对等服务器的工具all_resources()
: 获取所有对等服务器的资源all_prompts()
: 获取所有对等服务器的提示subscribe()
: 订阅资源更新
常见问题解答
- 类型转换支持哪些API?
- 目前支持AWS Bedrock,OpenAI支持即将推出。
使用教程
使用依赖
确保已安装Rust和Cargo。
安装教程
在Cargo.toml
中添加以下依赖:
toml
[dependencies]
commune = { package = "mcp-commune", version = "0.1.2" }
调试方式
使用以下代码示例进行基本调试:
```rust
use commune::prelude::*;
[tokio::main]
async fn main() -> Result<(), Box
let peer1 = PeerBuilder::new()
.with_name("everything".to_string())
.with_url("ws://localhost:8780".to_string())
.with_description("various example resources".to_string())
.build()
.await?;
let peer2 = PeerBuilder::new()
.with_name("memory".to_string())
.with_url("ws://localhost:8781".to_string())
.with_description("memory based on a knowledge graph".to_string())
.build()
.await?;
let commune_client = ClientBuilder::new()
.with_peers(vec![peer1.clone(), peer2])
.build()
.await?;
let peer_tools = commune_client.all_tools().await?;
log::info!("found {} tools", peer_tools.len());
let peer_resources = commune_client.all_resources().await?;
log::info!("found {} resources!", peer_resources.len());
let peer_prompts = commune_client.all_prompts().await?;
log::info!("found {} prompts!", peer_prompts.len());
peer1.subscribe("test://static/resource/2").await?;
Ok(())
}
```