rust-mcp-playground

rust-mcp-playground is an environment designed for experimenting with machine learning and automation projects using the Rust programming language. Users can easily execute code and observe results, making it ideal for learning and experimentation. Notably, it leverages Rust's performance for high-speed processing.

GitHub Stars

0

User Rating

Not Rated

Favorites

0

Views

25

Forks

0

Issues

0

README
Rust MCP Playground

A complete working implementation of the Model Context Protocol (MCP) in Rust, featuring both client and server components with full tool integration.

๐Ÿš€ Quick Start

Run the interactive calculator chat client:

cd projects/client
cargo run

This will:

  • Automatically start the calculator server
  • Connect to Claude via Anthropic API
  • Provide a chat interface for mathematical operations

Example usage:

You: add 15 to 27
๐Ÿค– Assistant: 15 + 27 = 42

You: what's the square root of 144?
๐Ÿค– Assistant: โˆš144 = 12
๐Ÿ“ Project Structure
rust-mcp-playground/
โ”œโ”€โ”€ projects/                     # ๐ŸŽฏ Main implementations
โ”‚   โ”œโ”€โ”€ client/                   # Chat client with Anthropic integration
โ”‚   โ”‚   โ”œโ”€โ”€ .env                  # ANTHROPIC_API_KEY configuration
โ”‚   โ”‚   โ””โ”€โ”€ src/main.rs           # Full MCP client implementation
โ”‚   โ””โ”€โ”€ servers/calculator/       # Calculator MCP server
โ”‚       โ””โ”€โ”€ src/main.rs           # 6 mathematical tools
โ”œโ”€โ”€ references/                   # ๐Ÿ“š Official examples
โ”‚   โ””โ”€โ”€ rust-mcp-sdk-examples/    # Complete SDK reference implementations
โ””โ”€โ”€ CLAUDE.md                     # Development guidance
โœจ Features
๐Ÿงฎ Calculator Server
  • 6 Mathematical Tools: add, subtract, multiply, divide, square, sqrt
  • Error Handling: Division by zero, negative square roots, invalid inputs
  • Input Validation: NaN and infinity checks
  • MCP Protocol: Latest rmcp 0.2.1 with #[tool_router] macros
  • Comprehensive Testing: Unit tests for all operations
๐Ÿ’ฌ Chat Client
  • Natural Language Interface: Ask questions in plain English
  • Tool Discovery: Automatically finds and uses server capabilities
  • Anthropic Integration: Uses Claude for intelligent responses
  • STDIO Transport: Manages server process lifecycle
  • Environment Configuration: API key from .env file
๐Ÿ› ๏ธ Technical Implementation

Built with the official Rust MCP SDK:

  • rmcp 0.2.1 - Latest MCP implementation
  • Protocol Version: 2024-11-05 (current MCP standard)
  • Transport: STDIO (standard for MCP integrations)
  • Tool Registration: Declarative macros for clean implementation

Architecture:

// Server tool registration
#[tool_router]
impl Calculator {
    #[tool(description = "Add two numbers together")]
    fn add(&self, Parameters(AddRequest { a, b }): Parameters<AddRequest>) 
        -> Result<CallToolResult, McpError> { /* ... */ }
}

// Client spawns server and discovers tools automatically
let transport = TokioChildProcess::new(command)?;
let client = ().serve(transport).await?;
let tools = client.list_all_tools().await?; // Discovers all 6 calculator tools
๐Ÿ“‹ Prerequisites
  1. Rust (edition 2024)

  2. Anthropic API Key - Add to projects/client/.env:

    ANTHROPIC_API_KEY=your_key_here
    
๐Ÿงช Development

Run tests:

cd projects/servers/calculator
cargo test

Build components independently:

# Server only
cd projects/servers/calculator
cargo build

# Client only  
cd projects/client
cargo build

Debug server separately:

cd projects/servers/calculator
cargo run  # Waits for STDIO input
๐Ÿ“– Learning Resources
๐ŸŽฏ What Makes This Special

This isn't just example code - it's a fully functional MCP system that demonstrates:

โœ… Real-world MCP integration with working tool discovery and execution
โœ… Production-ready patterns with proper error handling and validation
โœ… Modern Rust MCP development using the latest SDK features
โœ… Complete client-server architecture with automatic process management
โœ… Natural language interface powered by Claude's intelligence

Perfect for learning MCP concepts, building new MCP tools, or integrating MCP into existing applications!