mcp-probe-core 0.3.0

Core MCP (Model Context Protocol) types, traits, and transport implementations
Documentation

mcp-core

Crates.io Documentation License: MIT

Core MCP (Model Context Protocol) types, traits, and transport implementations for Rust.

Overview

mcp-core provides the fundamental building blocks for implementing MCP clients and servers in Rust. It includes:

  • Protocol Types: All MCP message types, including initialization, tools, resources, and prompts
  • Transport Layer: Pluggable transport implementations (stdio, HTTP SSE, HTTP streaming)
  • Client Implementation: High-level MCP client with automatic session management
  • Error Handling: Comprehensive error types for robust MCP implementations

Features

  • 🚀 High Performance: Built on Tokio for async I/O
  • 🔌 Pluggable Transports: Support for stdio, HTTP SSE, and HTTP streaming
  • 🛡️ Type Safety: Fully typed MCP protocol implementation
  • 🔄 Session Management: Automatic session handling and reconnection
  • 📝 Comprehensive Logging: Detailed tracing for debugging

Quick Start

Add this to your Cargo.toml:

[dependencies]
mcp-core = "0.1.0"

Basic Client Usage

use mcp_core::{
    client::McpClient,
    transport::TransportConfig,
    messages::Implementation,
};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Configure transport (stdio example)
    let config = TransportConfig::stdio("my-mcp-server", &["--arg1", "value1"]);

    // Create client
    let mut client = McpClient::with_defaults(config).await?;

    // Connect with client info
    let client_info = Implementation {
        name: "my-client".to_string(),
        version: "1.0.0".to_string(),
        metadata: Default::default(),
    };

    let _server_info = client.connect(client_info).await?;

    // List available tools
    let tools = client.list_tools().await?;
    println!("Available tools: {}", tools.len());

    // Call a tool
    if let Some(tool) = tools.first() {
        let params = serde_json::json!({"param": "value"});
        let result = client.call_tool(&tool.name, params).await?;
        println!("Tool result: {:?}", result);
    }

    Ok(())
}

Transport Configuration

Stdio Transport

let config = TransportConfig::stdio("python", &["-m", "my_mcp_server"]);

HTTP SSE Transport

let config = TransportConfig::http_sse("http://localhost:3000/sse")?;

HTTP Stream Transport

let config = TransportConfig::http_stream("http://localhost:3000/stream")?;

Architecture

The crate is organized into several modules:

  • client: High-level MCP client implementation
  • messages: All MCP protocol message types and serialization
  • transport: Transport layer abstractions and implementations
  • error: Error types and handling

Transport Layer

The transport layer uses a trait-based design for extensibility:

#[async_trait]
pub trait Transport: Send + Sync {
    async fn send_request(&mut self, request: JsonRpcRequest) -> Result<JsonRpcResponse>;
    async fn start_session(&mut self, client_info: Implementation) -> Result<TransportInfo>;
    // ... other methods
}

This allows for easy implementation of custom transports while maintaining a consistent interface.

Contributing

Contributions are welcome! Please see the main repository for contribution guidelines.

License

This project is licensed under the MIT License - see the LICENSE file for details.