Skip to main content

prism_mcp_rs/server/
mod.rs

1//! MCP server implementation
2//!
3//! This module provides the complete server-side implementation of the Model Context Protocol.
4//!
5//! # Architecture
6//!
7//! The server module is organized as follows:
8//! - [`McpServer`] - Main server struct handling protocol lifecycle
9//! - [`ServerBuilder`] - Fluent API for server configuration
10//! - `handlers` - Request/response handlers for each protocol method
11//! - `lifecycle` - Server startup, shutdown, and state management
12//! - `discovery_handler` - Protocol discovery and capability exchange
13//!
14//! # Usage Patterns
15//!
16//! ## Simple Server
17
18//! ```no_run
19//! use prism_mcp_rs::server::McpServer;
20//!
21//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
22//! let server = McpServer::new("server".to_string(), "1.0.0".to_string());
23//! // Register handlers, then call:
24//! // server.run_with_transport(StdioServerTransport::new()).await?;
25//! # Ok(())
26//! # }
27//! ```
28//!
29//! ## Using ServerBuilder
30
31//! ```
32//! use prism_mcp_rs::server::{ServerBuilder, ServerConfig};
33//! use prism_mcp_rs::core::{Tool, Resource, Prompt};
34//!
35//! let server = ServerBuilder::new()
36//!     .name("complex-server")
37//!     .version("2.0.0")
38//!     .with_tools()  // Enable tools capability
39//!     .with_resources()  // Enable resources capability
40//!     .with_prompts()  // Enable prompts capability
41//!     .config(ServerConfig {
42//!         validate_requests: true,
43//!         enable_logging: false,
44//!         max_concurrent_requests: 100,
45//!         request_timeout_ms: 30000,
46//!     })
47//!     .build();
48//! ```
49//!
50//! ## Custom Request Handling
51//! ```no_run
52//! use prism_mcp_rs::server::McpServer;
53//! use prism_mcp_rs::protocol::{JsonRpcRequest, JsonRpcResponse};
54//!
55//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
56//! let server = McpServer::new("server".to_string(), "1.0.0".to_string());
57//!
58//! // Handle requests programmatically
59//! let request = JsonRpcRequest::new(
60//!     "1".into(),
61//!     "initialize".to_string(),
62//!     None::<()>,
63//! )?;
64//!
65//! // Process the request
66//! // let response = server.handle_request(request).await?;
67//! # Ok(())
68//! # }
69//! ```
70//!
71//! # Features
72//!
73//! - **Protocol Types**: MCP 2025-11-25 messages and capabilities
74//! - **Capability Management**: Dynamic capability negotiation
75//! - **Lifecycle Handling**: Proper initialization and shutdown
76//! - **Error Handling**: Comprehensive error responses
77//! - **Transport Agnostic**: Works with stdio, HTTP, WebSocket
78
79pub mod async_methods;
80pub mod builder;
81pub mod discovery_handler;
82pub mod handlers;
83pub mod mcp_server;
84pub mod tasks;
85
86// Test types for complete testing
87#[cfg(test)]
88pub mod test_types;
89
90// HTTP-specific server implementation (when HTTP feature is enabled)
91#[cfg(feature = "http")]
92pub mod http_server;
93
94// Re-export the main server type and builder
95pub use builder::{ServerBuilder, ServerBuilderError};
96pub use mcp_server::{McpServer, ServerConfig, ServerState};
97pub use tasks::{ComposedTaskToolHandler, TaskContext, TaskToolHandler};
98
99// Re-export HTTP server when feature is enabled
100#[cfg(feature = "http")]
101pub use http_server::HttpMcpServer;