mcp-tools 0.1.0

Rust MCP tools library
Documentation
//! # MCP Tools - Unified MCP Tools Crate
//!
//! A comprehensive collection of MCP (Model Context Protocol) servers and clients
//! built on top of the powerful CoderLib library. This crate provides standalone
//! MCP servers that can be used with any MCP-compatible client (Claude Desktop, etc.)
//! and clients for testing and development.
//!
//! ## Features
//!
//! ### MCP Servers
//! - **File Operations Server** - File system operations with security
//! - **Git Tools Server** - Git repository management and analysis
//! - **Code Analysis Server** - Language-aware code analysis and refactoring
//! - **Web Tools Server** - Web scraping and HTTP operations
//! - **System Tools Server** - System information and process management
//!
//! ### MCP Clients
//! - **CLI Client** - Command-line MCP client for testing
//! - **Desktop Client** - GUI client for interactive use
//!
//! ## Quick Start
//!
//! ### Running a File Operations Server
//! ```bash
//! cargo run --bin mcp-file-server -- --port 3000
//! ```
//!
//! ### Using the CLI Client
//! ```bash
//! cargo run --bin mcp-cli -- connect ws://localhost:3000
//! ```
//!
//! ## Architecture
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────────┐
//! │                    MCP Tools Crate                         │
//! ├─────────────────────────────────────────────────────────────┤
//! │  Servers          │  Clients         │  Examples           │
//! │  ├─ file-ops      │  ├─ cli          │  ├─ basic-client    │
//! │  ├─ git-tools     │  ├─ desktop      │  ├─ advanced-server │
//! │  ├─ code-analysis │  └─ ...          │  └─ ...             │
//! │  ├─ web-tools     │                  │                     │
//! │  └─ system-tools  │                  │                     │
//! ├─────────────────────────────────────────────────────────────┤
//! │                      CoderLib                               │
//! │  ┌─ Core ─┐ ┌─ Tools ─┐ ┌─ MCP ─┐ ┌─ Permission ─┐        │
//! │  │ Session│ │ File   │ │ SDK  │ │ Security     │        │
//! │  │ LLM    │ │ Git    │ │ Proto│ │ Validation   │        │
//! │  │ Storage│ │ Code   │ │ Tools│ │ Session Mgmt │        │
//! │  └────────┘ └────────┘ └──────┘ └──────────────┘        │
//! └─────────────────────────────────────────────────────────────┘
//! ```

pub mod clients;
pub mod common;
pub mod config;
pub mod servers;
pub mod utils;

// TODO: Re-export core types for convenience when coderlib is available
// pub use coderlib::{
//     CoderLib, CoderLibConfig, Session, Tool, ToolResponse, ToolError,
//     Permission, PermissionService, PermissionRequest, PermissionResponse,
//     Provider, Model, Storage, Message
// };

// Re-export RMCP types for MCP protocol
pub use rmcp::{model::*, Error as McpError};

// Common types used across servers and clients
pub use common::*;

/// MCP Tools version
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

/// Default MCP server configuration
pub const DEFAULT_HOST: &str = "127.0.0.1";
pub const DEFAULT_PORT: u16 = 3000;

/// Error types for MCP Tools
#[derive(Debug, thiserror::Error)]
pub enum McpToolsError {
    #[error("CoderLib error: {0}")]
    CoderLib(String),

    #[error("MCP SDK error: {0}")]
    McpSdk(String),

    #[error("Configuration error: {0}")]
    Config(String),

    #[error("Initialization error: {0}")]
    InitializationError(String),

    #[error("IO error: {0}")]
    Io(#[from] std::io::Error),

    #[error("Serialization error: {0}")]
    Serialization(#[from] serde_json::Error),

    #[error("Git error: {0}")]
    Git(#[from] git2::Error),

    #[error("Network error: {0}")]
    Network(#[from] reqwest::Error),

    #[error("Server error: {0}")]
    Server(String),

    #[error("Client error: {0}")]
    Client(String),
}

/// Result type for MCP Tools operations
pub type Result<T> = std::result::Result<T, McpToolsError>;

/// Initialize logging for MCP Tools
pub fn init_logging() -> Result<()> {
    tracing_subscriber::fmt()
        .with_env_filter(
            tracing_subscriber::EnvFilter::try_from_default_env()
                .unwrap_or_else(|_| "mcp_tools=info,coderlib=info".into()),
        )
        .init();
    Ok(())
}

/// Get MCP Tools information
pub fn info() -> McpToolsInfo {
    McpToolsInfo {
        name: "MCP Tools".to_string(),
        version: VERSION.to_string(),
        description: "Unified MCP Tools Crate powered by CoderLib".to_string(),
        coderlib_version: "0.1.0".to_string(), // TODO: Get from coderlib when available
        features: get_enabled_features(),
    }
}

/// Information about MCP Tools
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct McpToolsInfo {
    pub name: String,
    pub version: String,
    pub description: String,
    pub coderlib_version: String,
    pub features: Vec<String>,
}

/// Get list of enabled features
fn get_enabled_features() -> Vec<String> {
    let mut features = Vec::new();

    #[cfg(feature = "file-server")]
    features.push("file-server".to_string());

    #[cfg(feature = "git-server")]
    features.push("git-server".to_string());

    #[cfg(feature = "code-server")]
    features.push("code-server".to_string());

    #[cfg(feature = "web-server")]
    features.push("web-server".to_string());

    #[cfg(feature = "system-server")]
    features.push("system-server".to_string());

    #[cfg(feature = "cli-client")]
    features.push("cli-client".to_string());

    #[cfg(feature = "desktop-client")]
    features.push("desktop-client".to_string());

    features
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_version() {
        assert!(!VERSION.is_empty());
    }

    #[test]
    fn test_info() {
        let info = info();
        assert_eq!(info.name, "MCP Tools");
        assert!(!info.version.is_empty());
        assert!(!info.description.is_empty());
    }

    #[test]
    fn test_features() {
        let features = get_enabled_features();
        // Should have at least one feature enabled in tests
        assert!(!features.is_empty());
    }
}