公社
特性
- 发现并维护对等MCP服务器列表
- 利用对等服务器上的可用工具、提示和资源
- 支持WebSocket通信(有和没有TLS加密)
- AWS、OpenAI和其他推理API的类型转换,简化了它们的使用
安装
将以下内容添加到您的 Cargo.toml:
[dependencies]
commune = { package = "mcp-commune", version = "0.1.2" }用法
use commune::prelude::*;
#[tokio::main]
async fn main() -> Result> {
// Create a peer for each MCP server
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?;
// Optionally create a commune client
let commune_client = ClientBuilder::new()
.with_peers(vec![peer1.clone(), peer2])
.build()
.await?;
// Use the client to aggregate resources
// Get all tools
let peer_tools = commune_client.all_tools().await?;
log::info!("found {} tools", peer_tools.len());
// Get all resources
let peer_resources = commune_client.all_resources().await?;
log::info!("found {} resources!", peer_resources.len());
// Get all prompts
let peer_prompts = commune_client.all_prompts().await?;
log::info!("found {} prompts!", peer_prompts.len());
// Use peers to utilize them, subscribe to notifications etc
// Subscribe to resource updates
peer1.subscribe("test://static/resource/2").await?;
Ok(())
}类型转换
Commune为各种推理API提供了方便的类型转换实现,包括:
- AWS基岩
- OpenAI(即将推出)
贡献
欢迎投稿!请随时提交拉取请求。
许可证
该项目根据 MIT许可证.
