#mcp #ai #protocols #sdk #machine-learning #client-server

mcp-commune

Rust client and server for building discoverable Model Context Protocol (MCP) networks

4 releases

new 0.1.4 Feb 12, 2025
0.1.3 Feb 6, 2025
0.1.2 Jan 24, 2025
0.1.0 Jan 24, 2025

#691 in Network programming

Download history 206/week @ 2025-01-21 20/week @ 2025-01-28 149/week @ 2025-02-04 134/week @ 2025-02-11

509 downloads per month

MIT license

37KB
675 lines

Commune

Commune is a Rust library designed to support the development of discoverable networks of AI agents. It serves as a wrapper over mcp-sdk-rs, providing enhanced functionality for peer discovery and resource utilization within Model Context Protocol (MCP) networks.

Features

  • Discover and maintain a list of peer MCP servers
  • Utilize available tools, prompts, and resources from peer servers
  • Support for WebSocket communication (with and without TLS encryption)
  • Type conversion for AWS, OpenAI, and other inference APIs, simplifying their usage

Installation

Add the following to your Cargo.toml:

[dependencies]
commune = { package = "mcp-commune", version = "0.1.2" }

Usage

use commune::prelude::*;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // 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(())
}

Type Conversion

Commune provides convenient type conversion implementations for various inference APIs, including:

  • AWS Bedrock
  • OpenAI (coming soon)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.

Dependencies

~14–27MB
~412K SLoC