Skip to main content

Module server

Module server 

Source
Expand description

MCP server implementation

This module provides the complete server-side implementation of the Model Context Protocol.

§Architecture

The server module is organized as follows:

  • McpServer - Main server struct handling protocol lifecycle
  • ServerBuilder - Fluent API for server configuration
  • handlers - Request/response handlers for each protocol method
  • lifecycle - Server startup, shutdown, and state management
  • discovery_handler - Protocol discovery and capability exchange

§Usage Patterns

§Simple Server

use prism_mcp_rs::server::McpServer;

let server = McpServer::new("server".to_string(), "1.0.0".to_string());
// Register handlers, then call:
// server.run_with_transport(StdioServerTransport::new()).await?;

§Using ServerBuilder

use prism_mcp_rs::server::{ServerBuilder, ServerConfig};
use prism_mcp_rs::core::{Tool, Resource, Prompt};

let server = ServerBuilder::new()
    .name("complex-server")
    .version("2.0.0")
    .with_tools()  // Enable tools capability
    .with_resources()  // Enable resources capability
    .with_prompts()  // Enable prompts capability
    .config(ServerConfig {
        validate_requests: true,
        enable_logging: false,
        max_concurrent_requests: 100,
        request_timeout_ms: 30000,
    })
    .build();

§Custom Request Handling

use prism_mcp_rs::server::McpServer;
use prism_mcp_rs::protocol::{JsonRpcRequest, JsonRpcResponse};

let server = McpServer::new("server".to_string(), "1.0.0".to_string());

// Handle requests programmatically
let request = JsonRpcRequest::new(
    "1".into(),
    "initialize".to_string(),
    None::<()>,
)?;

// Process the request
// let response = server.handle_request(request).await?;

§Features

  • Protocol Types: MCP 2025-11-25 messages and capabilities
  • Capability Management: Dynamic capability negotiation
  • Lifecycle Handling: Proper initialization and shutdown
  • Error Handling: Comprehensive error responses
  • Transport Agnostic: Works with stdio, HTTP, WebSocket

Re-exports§

pub use builder::ServerBuilder;
pub use builder::ServerBuilderError;
pub use mcp_server::McpServer;
pub use mcp_server::ServerConfig;
pub use mcp_server::ServerState;
pub use tasks::ComposedTaskToolHandler;
pub use tasks::TaskContext;
pub use tasks::TaskToolHandler;
pub use http_server::HttpMcpServer;

Modules§

async_methods
Async request handling methods for MCP server
builder
Server builder implementation for fluent API construction
discovery_handler
Discovery handler for the RPC discovery mechanism
handlers
MCP server request handlers
http_server
HTTP-specific MCP server implementation
mcp_server
MCP server implementation
tasks
Production runtime for the MCP Tasks extension.