### Run HTTP Server Example Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/examples/README.md Starts an HTTP server for MCP communication. This example requires the 'http' feature to be enabled. ```bash cargo run --example http_server --features http ``` -------------------------------- ### Unit Test Mock Server Setup Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/CONTRIBUTING.md Example of setting up a mock server for unit testing, expecting a tool call with specific parameters and returning a result. ```rust #[cfg(test)] mod tests { use super::*; use mcp_protocol_sdk::testing::*; #[tokio::test] async fn test_tool_execution() { let mut server = MockServer::new(); server.expect_tool_call("test_tool") .with_params(json!({"param": "value"})) .return_result(json!({"result": "success"})); // Test your code here } } ``` -------------------------------- ### Start an MCP Server with STDIO Transport Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/index.md Quickly set up an MCP server using the STDIO transport. This example demonstrates adding a tool and starting the server. Ensure you have the necessary dependencies and `tokio` runtime. ```rust use mcp_protocol_sdk:: server::McpServer, transport::stdio::StdioServerTransport, core::tool::ToolHandler, }; #[tokio::main] async fn main() -> Result<(), Box> { let mut server = McpServer::new("my-server".to_string(), "1.0.0".to_string()); // Add your tools, resources, and prompts server.add_tool("echo".to_string(), None, json!({}), EchoTool).await?; // Start with any transport let transport = StdioServerTransport::new(); server.start(transport).await?; Ok(()) } ``` -------------------------------- ### Run WebSocket Server Example Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/examples/README.md Starts a WebSocket server for real-time MCP communication. This requires the 'websocket' feature. ```bash cargo run --example websocket_server --features websocket ``` -------------------------------- ### Complete Client Example Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/api/README.md An example of setting up an MCP client and connecting to a server using the STDIO transport. ```APIDOC ### Complete Client Example This example demonstrates how to create an `McpClient` and connect to a server using the STDIO transport. ```rust use mcp_protocol_sdk::prelude::*; use mcp_protocol_sdk::client::McpClient; use serde_json::json; #[tokio::main] async fn main() -> McpResult<()> { // Create client let mut client = McpClient::new("my-client".to_string(), "1.0.0".to_string()); // Connect with STDIO transport use mcp_protocol_sdk::transport::stdio::StdioClientTransport; let transport = StdioClientTransport::new("./calculator-server".to_string()).await?; // Connect and initialize let init_result = client.connect(transport).await?; println!("Connected to: {} vdistinguish{} " init_result.server_info.name, init_result.server_info.version ); // Check capabilities if let Some(capabilities) = client.server_capabilities().await { if capabilities.tools.is_some() { println!("✅ Server supports tools"); } } Ok(()) } ``` ``` -------------------------------- ### Run Echo Server Example Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/examples/README.md Starts the echo server using stdio transport and tracing subscriber features. Ensure this is run in a separate terminal before the client. ```bash cargo run --example echo_server --features "stdio,tracing-subscriber" ``` -------------------------------- ### Run Basic MCP Protocol SDK Examples Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/examples.md Instructions for cloning the repository and running basic server and client examples using Cargo. ```bash # Clone the repository git clone https://github.com/rishirandhawa/mcp-protocol-sdk.git cd mcp-protocol-sdk # Run basic examples cargo run --example simple_server cargo run --example echo_server cargo run --example client_example ``` -------------------------------- ### Complete Server Example Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/api/README.md A full example of setting up an MCP server with a calculator tool, demonstrating how to use the ParameterExt trait within a tool handler. ```APIDOC ## Usage Examples ### Complete Server Example This example demonstrates how to implement a `ToolHandler` for a calculator tool and integrate it into an `McpServer`. ```rust use mcp_protocol_sdk::prelude::*; use async_trait::async_trait; use std::collections::HashMap; use serde_json::{json, Value}; // Tool handler implementation struct CalculatorHandler; #[async_trait] impl ToolHandler for CalculatorHandler { async fn call(&self, arguments: HashMap) -> McpResult { let a = arguments.get_number("a")?; let b = arguments.get_number("b")?; let operation = arguments.get_string("operation")?; let result = match operation { "add" => a + b, "subtract" => a - b, "multiply" => a * b, "divide" => { if b == 0.0 { return Ok(ToolResult { content: vec![Content::text("Error: Division by zero")], is_error: Some(true), structured_content: None, meta: None, }); } a / b } _ => return Err(McpError::validation("Invalid operation")), }; Ok(ToolResult { content: vec![Content::text(result.to_string())], is_error: None, structured_content: Some(json!({ "operation": operation, "operands": [a, b], "result": result })), meta: None, }) } } #[tokio::main] async fn main() -> McpResult<()> { // Create server let mut server = McpServer::new("calculator".to_string(), "1.0.0".to_string()); // Add calculator tool server.add_tool( "calculate".to_string(), Some("Perform arithmetic calculations".to_string()), json!({ "type": "object", "properties": { "operation": { "type": "string", "enum": ["add", "subtract", "multiply", "divide"] }, "a": {"type": "number"}, "b": {"type": "number"} }, "required": ["operation", "a", "b"] }), CalculatorHandler, ).await?; // Start with STDIO transport use mcp_protocol_sdk::transport::stdio::StdioServerTransport; let transport = StdioServerTransport::new(); server.start(transport).await?; Ok(()) } ``` ``` -------------------------------- ### Utility Example Template Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/examples/utilities/README.md A template for creating new utility examples. It includes basic setup for tracing and a main async function. ```rust //! My Utility Example //! //! Description of what this utility does. use mcp_protocol_sdk::*; use tracing::{info, error}; #[tokio::main] async fn main() -> Result<(), Box> { // Initialize tracing tracing_subscriber::fmt::init(); info!("Starting my utility..."); // Your utility logic here info!("Utility completed successfully"); Ok(()) } ``` -------------------------------- ### Run Production MCP Protocol SDK Examples Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/examples.md Instructions for running microservice examples with specific logging configurations and release builds, and how to run tests. ```bash # Run with specific configurations RUST_LOG=info cargo run --example microservice_server --features "http,websocket" --release # Run tests cargo test cargo test --example simple_server ``` -------------------------------- ### Implement WebSocket Server for Real-time Applications Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/implementation-guide.md Set up a WebSocket server for real-time applications. This example shows how to add a custom tool handler for streaming data and start the server. ```rust use mcp_protocol_sdk::prelude::*; use async_trait::async_trait; use serde_json::{json, Value}; use std::collections::HashMap; // Real-time data handler struct StreamHandler; #[async_trait] impl ToolHandler for StreamHandler { async fn call(&self, _arguments: HashMap) -> McpResult { // Simulate real-time data streaming Ok(ToolResult { content: vec![Content::text("Streaming data...".to_string())], is_error: None, structured_content: Some(json!({ "stream": "data", "timestamp": chrono::Utc::now().to_rfc3339() })), meta: None, }) } } #[cfg(feature = "websocket")] #[tokio::main] async fn main() -> Result<(), Box> { use mcp_protocol_sdk::transport::websocket::WebSocketServerTransport; let mut server = McpServer::new("realtime-server".to_string(), "1.0.0".to_string()); // Add real-time capabilities server.add_tool( "stream_data".to_string(), Some("Stream real-time data".to_string()), json!({ "type": "object", "properties": {{}}, "additionalProperties": false }), StreamHandler, ).await?; let transport = WebSocketServerTransport::new("0.0.0.0:8080".to_string()); server.start(transport).await?; Ok(()) } ``` -------------------------------- ### STDIO Transport - Server Setup Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/transports.md Example of setting up an MCP server using the STDIO transport. This is suitable for CLI tools and single-client scenarios. ```APIDOC ## STDIO Transport - Server ### Description Sets up an MCP server that communicates over standard input and output. This is ideal for command-line interfaces and scenarios where a single client connects to a server process. ### Language Rust ### Code Example ```rust use mcp_protocol_sdk::\n server::McpServer,\n transport::stdio::StdioServerTransport,\n; #[tokio::main] async fn main() -> Result<(), Box> { let mut server = McpServer::new("stdio-server".to_string(), "1.0.0".to_string()); // Add your tools, resources, and prompts let transport = StdioServerTransport::new(); server.start(transport).await?; Ok(()) } ``` ``` -------------------------------- ### HTTP MCP Server Setup in Rust Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/examples/server/README.md Demonstrates how to initialize and start an MCP server using the HTTP transport. This requires the `http` feature and sets up the server to listen on `0.0.0.0:3000`. ```rust use mcp_protocol_sdk::{ server::McpServer, transport::http::HttpServerTransport, }; #[tokio::main] async fn main() -> Result<(), Box> { let mut server = McpServer::new("http-server".to_string(), "1.0.0".to_string()); // Add tools... let transport = HttpServerTransport::new("0.0.0.0:3000"); server.start(transport).await?; println!("HTTP server running on http://localhost:3000"); println!("API endpoint: http://localhost:3000/mcp"); println!("SSE events: http://localhost:3000/mcp/events"); tokio::signal::ctrl_c().await?; server.stop().await?; Ok(()) } ``` -------------------------------- ### Run Project Tests and Examples Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/CONTRIBUTING.md Commands to run all tests and execute example applications with specific features. ```bash cargo test --all-features cargo run --example echo_server --features stdio,tracing-subscriber ``` -------------------------------- ### Run Echo Server Example Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/implementation-guide.md Execute the echo server example using Cargo. Ensure you have the necessary features enabled. ```bash cargo run --example echo_server --features stdio,tracing-subscriber ``` -------------------------------- ### Run Advanced MCP Protocol SDK Examples Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/examples.md Examples for advanced use cases like database integration, multi-client chat, and file management. ```bash # Database integration cargo run --example database_server # Multi-client chat cargo run --example websocket_server --features websocket # File management cargo run --example http_server --features http ``` -------------------------------- ### Basic STDIO Server Implementation (Rust) Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/implementation-guide.md Implement a basic STDIO server for Claude Desktop using the MCP Protocol SDK. This example demonstrates creating a tool handler, adding a tool to the server, and starting the server with the STDIO transport. ```rust use mcp_protocol_sdk::prelude::*; use async_trait::async_trait; use serde_json::{json, Value}; use std::collections::HashMap; // Step 1: Create a tool handler (required by API) struct CalculatorHandler; #[async_trait] impl ToolHandler for CalculatorHandler { async fn call(&self, arguments: HashMap) -> McpResult { let a = arguments .get("a") .and_then(|v| v.as_f64()) .ok_or_else(|| McpError::Validation("Missing 'a' parameter".to_string()))?; let b = arguments .get("b") .and_then(|v| v.as_f64()) .ok_or_else(|| McpError::Validation("Missing 'b' parameter".to_string()))?; Ok(ToolResult { content: vec![Content::text((a + b).to_string())], is_error: None, structured_content: Some(json!({ "result": a + b })), meta: None, }) } } #[tokio::main] async fn main() -> Result<(), Box> { // Create server (note: requires String parameters) let mut server = McpServer::new("calculator".to_string(), "1.0.0".to_string()); // Add tool using the actual API server.add_tool( "add".to_string(), Some("Add two numbers".to_string()), json!({ "type": "object", "properties": { "a": {"type": "number", "description": "First number"}, "b": {"type": "number", "description": "Second number"} }, "required": ["a", "b"] }), CalculatorHandler, ).await?; use mcp_protocol_sdk::transport::stdio::StdioServerTransport; let transport = StdioServerTransport::new(); server.start(transport).await?; Ok(()) } ``` -------------------------------- ### HTTP Transport - Server Setup Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/transports.md Example of setting up an MCP server using the HTTP transport. This enables RESTful API endpoints and Server-Sent Events. ```APIDOC ## HTTP Transport - Server ### Description Initializes an MCP server that exposes a RESTful API over HTTP. It also supports Server-Sent Events for real-time notifications. ### Language Rust ### Code Example ```rust use mcp_protocol_sdk::\n server::McpServer,\n transport::http::HttpServerTransport,\n; #[tokio::main] async fn main() -> Result<(), Box> { let mut server = McpServer::new("http-server".to_string(), "1.0.0".to_string()); // Add your tools, resources, and prompts let transport = HttpServerTransport::new("0.0.0.0:3000"); server.start(transport).await?; println!("HTTP server running on http://localhost:3000"); println!("API endpoint: http://localhost:3000/mcp"); println!("SSE events: http://localhost:3000/mcp/events"); // Keep running until interrupted tokio::signal::ctrl_c().await?; server.stop().await?; Ok(()) } ``` ``` -------------------------------- ### Run Basic Client Example Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/examples/README.md Connects to the echo server using stdio transport. This client example requires the server to be running. ```bash cargo run --example basic_client --features stdio ``` -------------------------------- ### Configure and Start Microservice Server Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/examples.md Sets up a microservice server with production configurations, adds HTTP request and database query tools, and starts the server on a specified address. Includes configuration for allowed hosts and tool schemas. ```rust #[tokio::main] async fn main() -> Result<(), Box> { // Configure server for production use let config = ServerConfig { max_concurrent_requests: 100, request_timeout_ms: 60000, validate_requests: true, enable_logging: true, }; let mut server = McpServer::with_config( "microservice-server".to_string(), "1.0.0".to_string(), config, ); // Define allowed external hosts let allowed_hosts = vec![ "api.github.com".to_string(), "httpbin.org".to_string(), "jsonplaceholder.typicode.com".to_string(), ]; // Add HTTP request tool server.add_tool( "http_request".to_string(), Some("Make HTTP requests to external APIs".to_string()), json!({ "type": "object", "properties": { "url": {"type": "string", "description": "Request URL"}, "method": {"type": "string", "enum": ["GET", "POST", "PUT", "DELETE"], "default": "GET"}, "headers": {"type": "object", "description": "Request headers"}, "body": {"type": "string", "description": "Request body"} }, "required": ["url"] }), HttpRequestTool::new(allowed_hosts), ).await?; // Add database query tool server.add_tool( "database_query".to_string(), Some("Execute database queries".to_string()), json!({ "type": "object", "properties": { "query": {"type": "string", "description": "SQL query to execute"} }, "required": ["query"] }), DatabaseQueryTool::new("postgresql://localhost/mydb".to_string()), ).await?; let transport = HttpServerTransport::new("0.0.0.0:8080"); server.start(transport).await?; println!("Microservice integration server running on http://localhost:8080"); println!("Endpoints:"); println!(" - POST /mcp (MCP JSON-RPC)"); println!(" - GET /mcp/events (Server-Sent Events)"); println!(" - GET /health (Health check)"); tokio::signal::ctrl_c().await?; server.stop().await?; Ok(()) } ``` -------------------------------- ### Basic Server Setup Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/configuration.md Create a new MCP server with a name and version. ```rust use mcp_protocol_sdk::prelude::*; use mcp_protocol_sdk::server::mcp_server::ServerConfig; // Basic server let mut server = McpServer::new("my-server".to_string(), "1.0.0".to_string()); ``` -------------------------------- ### Running MCP Server Examples with Cargo Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/examples/server/README.md Command-line instructions for compiling and running various MCP server examples using Cargo. Each command specifies the example to run and the necessary features. ```bash # Run simple server example cargo run --example simple_server --features "stdio,tracing-subscriber" # Run echo server example cargo run --example echo_server --features "stdio,tracing-subscriber" # Run database server example cargo run --example database_server --features "stdio,tracing-subscriber" # Run HTTP server example cargo run --example http_server --features http # Run WebSocket server example cargo run --example websocket_server --features websocket ``` -------------------------------- ### Basic Client Setup Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/configuration.md Create a new MCP client with a name and version. ```rust use mcp_protocol_sdk::prelude::*; let client = McpClient::new("my-client".to_string(), "1.0.0".to_string()); ``` -------------------------------- ### Simple Server Example (STDIO) Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/README.md Example of a simple server using STDIO transport, suitable for Claude Desktop integration. ```rust use mcp_protocol_sdk::server::run_server; #[tokio::main] async fn main() { run_server().await; } ``` -------------------------------- ### Start STDIO Server Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/transports.md Initializes and starts an MCP server using the STDIO transport. Ensure to add your tools, resources, and prompts before starting. ```rust use mcp_protocol_sdk:: server::McpServer, transport::stdio::StdioServerTransport, }; #[tokio::main] async fn main() -> Result<(), Box> { let mut server = McpServer::new("stdio-server".to_string(), "1.0.0".to_string()); // Add your tools, resources, and prompts let transport = StdioServerTransport::new(); server.start(transport).await?; Ok(()) } ``` -------------------------------- ### Run HTTP Transport Examples Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/examples.md Commands to run HTTP server and client examples, requiring the 'http' feature to be enabled. ```bash # HTTP examples (requires http feature) cargo run --example http_server --features http cargo run --example http_client --features http ``` -------------------------------- ### Run WebSocket Transport Examples Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/examples.md Commands to run WebSocket server and client examples, requiring the 'websocket' feature to be enabled. ```bash # WebSocket examples (requires websocket feature) cargo run --example websocket_server --features websocket cargo run --example websocket_client --features websocket ``` -------------------------------- ### Create a Simple MCP Calculator Server Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/getting-started.md Implement a basic MCP server in Rust that exposes a calculator tool. This example demonstrates tool handler creation, tool registration, and starting the server with STDIO transport. ```rust use mcp_protocol_sdk::prelude::*; use async_trait::async_trait; use serde_json::{json, Value}; use std::collections::HashMap; // Step 1: Create a tool handler (required by the API) struct CalculatorHandler; #[async_trait] impl ToolHandler for CalculatorHandler { async fn call(&self, arguments: HashMap) -> McpResult { let expression = arguments .get("expression") .and_then(|v| v.as_str()) .ok_or_else(|| McpError::Validation("Missing expression parameter".to_string()))?; // Simple calculator logic (use a real math parser in production) let result = match expression { expr if expr.contains('+') => { let parts: Vec<&str> = expr.split('+').collect(); if parts.len() == 2 { let a: f64 = parts[0].trim().parse() .map_err(|_| McpError::Validation("Invalid number".to_string()))?; let b: f64 = parts[1].trim().parse() .map_err(|_| McpError::Validation("Invalid number".to_string()))?; a + b } else { return Err(McpError::Validation("Invalid expression format".to_string())); } } expr if expr.contains('-') => { let parts: Vec<&str> = expr.split('-').collect(); if parts.len() == 2 { let a: f64 = parts[0].trim().parse() .map_err(|_| McpError::Validation("Invalid number".to_string()))?; let b: f64 = parts[1].trim().parse() .map_err(|_| McpError::Validation("Invalid number".to_string()))?; a - b } else { return Err(McpError::Validation("Invalid expression format".to_string())); } } _ => return Err(McpError::Validation("Unsupported operation".to_string())), }; Ok(ToolResult { content: vec![Content::text(result.to_string())], is_error: None, structured_content: Some(json!({ "expression": expression, "result": result })), meta: None, }) } } #[tokio::main] async fn main() -> Result<(), Box> { // Create a new MCP server (note: requires String parameters) let mut server = McpServer::new("calculator-server".to_string(), "1.0.0".to_string()); // Add a calculator tool using the actual API server.add_tool( "calculate".to_string(), Some("Perform basic arithmetic calculations".to_string()), json!({ "type": "object", "properties": { "expression": { "type": "string", "description": "Mathematical expression to evaluate (e.g., '5+3', '10-2')" }, "precision": { "type": "integer", "description": "Number of decimal places (optional)", "default": 2 } }, "required": ["expression"] }), CalculatorHandler, ).await?; // Start the server with STDIO transport (compatible with Claude Desktop) use mcp_protocol_sdk::transport::stdio::StdioServerTransport; let transport = StdioServerTransport::new(); server.start(transport).await?; Ok(()) } ``` -------------------------------- ### Docker Multi-Architecture Build Setup Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/platform-support.md Sets up a multi-stage Docker build using a Rust base image, specifying build arguments for target and platform. This is a starting point for building multi-architecture Docker images. ```dockerfile # Multi-stage build for multiple architectures FROM --platform=$BUILDPLATFORM rust:1.85 AS builder ARG TARGETPLATFORM ARG BUILDPLATFORM WORKDIR /app COPY . . ``` -------------------------------- ### Run HTTP Client Example Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/examples/README.md Connects to an HTTP server using the MCP protocol. This client example requires the 'http' feature and a running HTTP server. ```bash cargo run --example http_client --features http ``` -------------------------------- ### HTTP Client Example Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/README.md Example of an HTTP client for making external service calls. ```rust use mcp_protocol_sdk::client::run_http_client; #[tokio::main] async fn main() { run_http_client().await; } ``` -------------------------------- ### Install GitHub CLI Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/scripts/README.md Instructions for installing the GitHub CLI on Ubuntu/Debian systems. This is a prerequisite for full badge manager functionality. ```bash curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null sudo apt update sudo apt install gh ``` -------------------------------- ### Clone Repository and Build Project Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/CONTRIBUTING.md Steps to clone the repository, install dependencies, and build the project locally. ```bash git clone https://github.com/mcp-rust/mcp-protocol-sdk.git cd mcp-protocol-sdk cargo build --all-features cargo test --all-features cargo run --example echo_server --features stdio,tracing-subscriber ``` -------------------------------- ### Start WebSocket Server Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/transports.md Initializes and starts a WebSocket server using the MCP Protocol SDK. Ensure necessary imports are included. ```rust use mcp_protocol_sdk:: server::McpServer, transport::websocket::WebSocketServerTransport, }; #[tokio::main] async fn main() -> Result<(), Box> { let mut server = McpServer::new("ws-server".to_string(), "1.0.0".to_string()); // Add your tools, resources, and prompts let transport = WebSocketServerTransport::new("0.0.0.0:8080"); server.start(transport).await?; println!("WebSocket server running on ws://localhost:8080"); // Keep running until interrupted tokio::signal::ctrl_c().await?; server.stop().await?; Ok(()) } ``` -------------------------------- ### HTTP Server Example Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/README.md Example of an HTTP server, useful for web integration and REST API services. ```rust use mcp_protocol_sdk::server::run_http_server; #[tokio::main] async fn main() { run_http_server().await; } ``` -------------------------------- ### Server Setup with Custom Configuration Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/configuration.md Initialize an MCP server with a custom ServerConfig object. ```rust use mcp_protocol_sdk::prelude::*; use mcp_protocol_sdk::server::mcp_server::ServerConfig; // Or with custom configuration let config = ServerConfig { max_concurrent_requests: 10, request_timeout_ms: 30000, validate_requests: true, enable_logging: true, }; let mut server = McpServer::with_config( "my-server".to_string(), "1.0.0".to_string(), config, ); ``` -------------------------------- ### Start Database Integration Server Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/examples.md Initiates a server with database integration. Ensure the Database::new() constructor is correctly implemented and accessible. ```rust ).await?, DatabaseResource { db: Database::new() }, ).await?; let transport = StdioServerTransport::new(); server.start(transport).await?; Ok(()) } ``` -------------------------------- ### Database Server Example (STDIO) Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/README.md Example of a server using STDIO transport for database operations, such as SQL query execution. ```rust use mcp_protocol_sdk::server::run_database_server; #[tokio::main] async fn main() { run_database_server().await; } ``` -------------------------------- ### Add New Utility Example to Cargo.toml Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/examples/utilities/README.md Configuration for adding a new utility example to the project's Cargo.toml file. ```toml [[example]] name = "my_utility" path = "examples/utilities/my_utility.rs" required-features = ["http", "tracing-subscriber"] ``` -------------------------------- ### Rust Complete Client Example Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/api/README.md An example of an MCP client connecting to a server using STDIO transport. It shows how to initialize the client, establish a connection, and retrieve server information and capabilities. ```rust use mcp_protocol_sdk::prelude::*; use mcp_protocol_sdk::client::McpClient; use serde_json::json; #[tokio::main] async fn main() -> McpResult<()> { // Create client let mut client = McpClient::new("my-client".to_string(), "1.0.0".to_string()); // Connect with STDIO transport use mcp_protocol_sdk::transport::stdio::StdioClientTransport; let transport = StdioClientTransport::new("./calculator-server".to_string()).await?; // Connect and initialize let init_result = client.connect(transport).await?; println!("Connected to: {} vˉ{}", init_result.server_info.name, init_result.server_info.version ); // Check capabilities if let Some(capabilities) = client.server_capabilities().await { if capabilities.tools.is_some() { println!("✅ Server supports tools"); } } Ok(()) } ``` -------------------------------- ### HTTP MCP Client Example Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/examples/client/README.md Shows how to create an MCP client using the HTTP transport. This example connects to a local server and lists available tools. ```rust use mcp_protocol_sdk:: client::{McpClient, ClientSession}, transport::http::HttpClientTransport, ; #[tokio::main] async fn main() -> Result<(), Box> { let client = McpClient::new("http-client".to_string(), "1.0.0".to_string()); let session = ClientSession::new(client); let transport = HttpClientTransport::new("http://localhost:3000/mcp".to_string()).await?; let init_result = session.connect(transport).await?; let client = session.client(); let client_guard = client.lock().await; // List available tools let tools = client_guard.list_tools().await?; println!("Available tools: {:?}", tools.tools.len()); Ok(()) } ``` -------------------------------- ### Rust Complete Server Example Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/api/README.md A full example of an MCP server implementing a calculator tool. It demonstrates how to define a `ToolHandler`, handle incoming requests, perform calculations, and return results or errors. The server is set up with a specific tool, schema, and uses STDIO for transport. ```rust use mcp_protocol_sdk::prelude::*; use async_trait::async_trait; use std::collections::HashMap; use serde_json::{json, Value}; // Tool handler implementation struct CalculatorHandler; #[async_trait] impl ToolHandler for CalculatorHandler { async fn call(&self, arguments: HashMap) -> McpResult { let a = arguments.get_number("a")?; let b = arguments.get_number("b")?; let operation = arguments.get_string("operation")?; let result = match operation { "add" => a + b, "subtract" => a - b, "multiply" => a * b, "divide" => { if b == 0.0 { return Ok(ToolResult { content: vec![Content::text("Error: Division by zero")], is_error: Some(true), structured_content: None, meta: None, }); } a / b } _ => return Err(McpError::validation("Invalid operation")), }; Ok(ToolResult { content: vec![Content::text(result.to_string())], is_error: None, structured_content: Some(json!({ "operation": operation, "operands": [a, b], "result": result })), meta: None, }) } } #[tokio::main] async fn main() -> McpResult<()> { // Create server let mut server = McpServer::new("calculator".to_string(), "1.0.0".to_string()); // Add calculator tool server.add_tool( "calculate".to_string(), Some("Perform arithmetic calculations".to_string()), json!({ "type": "object", "properties": { "operation": { "type": "string", "enum": ["add", "subtract", "multiply", "divide"] }, "a": {"type": "number"}, "b": {"type": "number"} }, "required": ["operation", "a", "b"] }), CalculatorHandler, ).await?; // Start with STDIO transport use mcp_protocol_sdk::transport::stdio::StdioServerTransport; let transport = StdioServerTransport::new(); server.start(transport).await?; Ok(()) } ``` -------------------------------- ### Verify Server Examples with Cargo Check Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/examples/README.md This command checks all server examples with the necessary features enabled. It ensures server-side components are correctly configured. ```bash # Test all server examples for example in simple_server echo_server database_server http_server websocket_server; do echo "Testing $example..." cargo check --example $example --features "stdio,http,websocket,tracing-subscriber" --quiet done ``` -------------------------------- ### McpServer::start Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/api-reference.md Starts the `McpServer` with the specified transport. ```APIDOC ## McpServer::start ### Description Starts the `McpServer` with the specified transport. ### Signature ```rust pub async fn start(&mut self, transport: T) -> Result<(), McpError>; ``` ### Parameters * `transport` (T) - The server transport implementation. ``` -------------------------------- ### Cross-Platform Server Example with Platform Detection Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/platform-support.md A Rust example demonstrating a cross-platform MCP server that detects the operating system to determine configuration directories and add platform-specific tools. ```rust use mcp_protocol_sdk::prelude::*; use std::path::PathBuf; #[tokio::main] async fn main() -> Result<(), Box> { // Platform-specific configuration let config_dir = get_platform_config_dir(); let config_path = config_dir.join("server.json"); // Create server with platform detection let mut server = McpServer::new("multi-platform-server", "1.0.0"); // Add platform-specific tools add_platform_tools(&mut server).await?; // Start with appropriate transport let transport = StdioServerTransport::new(); server.run(transport).await?; Ok(()) } fn get_platform_config_dir() -> PathBuf { #[cfg(target_os = "windows")] return dirs::config_dir() .unwrap_or_else(|| PathBuf::from(r"C:\\ProgramData")) .join("MCP Server"); #[cfg(target_os = "macos")] return dirs::config_dir() .unwrap_or_else(|| PathBuf::from("/Library/Application Support")) .join("MCP Server"); #[cfg(target_os = "linux")] return dirs::config_dir() .unwrap_or_else(|| PathBuf::from("/etc")) .join("mcp-server"); } async fn add_platform_tools(server: &mut McpServer) -> Result<(), Box> { // Cross-platform file operations server.add_tool( Tool::new("get_platform_info", "Get current platform information") ); // Platform-specific tools #[cfg(target_os = "linux")] server.add_tool( Tool::new("systemd_status", "Check systemd service status") ); #[cfg(target_os = "macos")] server.add_tool( Tool::new("launchctl_status", "Check launchd service status") ); #[cfg(target_os = "windows")] server.add_tool( Tool::new("service_status", "Check Windows service status") ); Ok(()) } ``` -------------------------------- ### Install Rust on Windows (x86_64) Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/platform-support.md Provides instructions for installing Rust on Windows 10/11 (x86_64) using rustup, Chocolatey, or Scoop. Includes adding the SDK to Cargo.toml. ```powershell # Install Rust via rustup # Download and run: https://rustup.rs/ # Or via Chocolatey choco install rust # Or via Scoop scoop install rust # Add to Cargo.toml [dependencies] mcp-protocol-sdk = "0.5.0" ``` -------------------------------- ### Run Transport Performance Benchmarks Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/implementation-guide.md Execute the transport benchmark example with all features enabled to measure performance. ```bash cargo run --example transport_benchmark --all-features ``` -------------------------------- ### Cursor Development Tools Installation Script Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/integrations/cursor.md A bash script to install the Cursor development server binary. It copies the binary to `/usr/local/bin` and sets execute permissions. Configure Cursor to use this path. ```bash #!/bin/bash set -e INSTALL_DIR="/usr/local/bin" BINARY_NAME="cursor-dev-server" echo "Installing Cursor Development Tools..." # Copy binary sudo cp "$BINARY_NAME" "$INSTALL_DIR/" sudo chmod +x "$INSTALL_DIR/$BINARY_NAME" echo "Installation complete!" echo "Configure in Cursor: Set myMcp.serverPath to $INSTALL_DIR/$BINARY_NAME" ``` -------------------------------- ### Fragmented Dependencies Example Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/README.md Illustrates the previous approach of using separate crates for client, server, and types. ```toml [dependencies] mcp-protocol-client = "0.1.0" # Separate client crate mcp-protocol-server = "0.1.0" # Separate server crate mcp-protocol-types = "0.1.0" # Separate types crate ``` -------------------------------- ### Basic MCP Server and Client Setup Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/nav.md Demonstrates setting up a basic MCP server with an echo tool and connecting a client via WebSocket. Ensure necessary imports and tool implementations are available. ```rust // Simple server let mut server = McpServer::new("my-server".to_string(), "1.0.0".to_string()); server.add_tool("echo".to_string(), None, json!({}), EchoTool).await?; server.start(StdioServerTransport::new()).await?; // Client connection let session = ClientSession::new(McpClient::new("client".to_string(), "1.0.0".to_string())); let transport = WebSocketClientTransport::new("ws://localhost:8080").await?; session.connect(transport).await?; ``` -------------------------------- ### HTTP Transport - Client Setup Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/transports.md Example of connecting an MCP client using the HTTP transport. This allows clients to interact with an HTTP-based MCP server. ```APIDOC ## HTTP Transport - Client ### Description Initializes an MCP client and connects to an HTTP-based MCP server. The client interacts with the server via its API endpoint. ### Language Rust ### Code Example ```rust use mcp_protocol_sdk::\n client::mcp_client::McpClient,\n transport::http::HttpClientTransport,\n; #[tokio::main] async fn main() -> Result<(), Box> { let mut client = McpClient::new("http-client".to_string(), "1.0.0".to_string()); let transport = HttpClientTransport::new("http://localhost:3000/mcp", None).await?; let init_result = client.connect(transport).await?; println!("Connected to: {}", init_result.server_info.name); // Use the client... Ok(()) } ``` ``` -------------------------------- ### STDIO Transport - Client Setup Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/transports.md Example of connecting an MCP client using the STDIO transport. This allows a client to communicate with a server process via stdio. ```APIDOC ## STDIO Transport - Client ### Description Initializes an MCP client and establishes a connection to a server process using the STDIO transport. The client connects to a specified server executable. ### Language Rust ### Code Example ```rust use mcp_protocol_sdk::\n client::mcp_client::McpClient,\n transport::stdio::StdioClientTransport,\n; #[tokio::main] async fn main() -> Result<(), Box> { let mut client = McpClient::new("stdio-client".to_string(), "1.0.0".to_string()); // Connect to server executable let transport = StdioClientTransport::new("./my-server".to_string(), vec![]).await?; let init_result = client.connect(transport).await?; println!("Connected to: {}", init_result.server_info.name); // Use the client... Ok(()) } ``` ``` -------------------------------- ### Mock Server for Testing Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/CONTRIBUTING.md Example of setting up a mock server and defining expected tool calls with parameters and return results for testing. ```rust @cfg(test) mod tests { use super::*; use mcp_protocol_sdk::testing::*; #[tokio::test] async fn test_tool_execution() { let mut server = MockServer::new(); server.expect_tool_call("test_tool") .with_params(json!({"param": "value"})) .return_result(json!({"result": "success"})); // Test your code here } } ``` -------------------------------- ### Rust MCP Server with STDIO Transport Source: https://github.com/prismworks-ai/mcp-protocol-sdk/blob/main/docs/integrations/claude-desktop.md Example of an MCP server built in Rust that uses STDIO transport, making it compatible with Claude Desktop. Includes a basic tool handler and server setup. ```rust use mcp_protocol_sdk::prelude::*; use async_trait::async_trait; use serde_json::{json, Value}; use std::collections::HashMap; // Tool handler example struct MyToolHandler; #[async_trait] impl ToolHandler for MyToolHandler { async fn call(&self, arguments: HashMap) -> McpResult { // Your tool implementation Ok(ToolResult { content: vec![Content::text("Tool executed successfully".to_string())], is_error: None, structured_content: None, meta: None, }) } } #[tokio::main] async fn main() -> Result<(), Box> { // Create server (note: requires String parameters) let mut server = McpServer::new("my-server".to_string(), "1.0.0".to_string()); // Add your tools using the actual API setup_capabilities(&mut server).await?; // Use STDIO transport for Claude Desktop use mcp_protocol_sdk::transport::stdio::StdioServerTransport; let transport = StdioServerTransport::new(); server.start(transport).await?; Ok(()) } async fn setup_capabilities(server: &mut McpServer) -> McpResult<()> { // Add tools using the correct API server.add_tool( "example_tool".to_string(), Some("Example tool description".to_string()), json!({ "type": "object", "properties": { "input": {"type": "string", "description": "Tool input"} }, "required": ["input"] }), MyToolHandler, ).await?; Ok(()) } ```